Dim caption As String = "Example: GetWrappedTextLineCount"
Dim message As String = "The example has not been followed successfully." + vbCrLf + "The last known status is "
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
Dim fontName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesBold)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
If gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK Then
Dim text As String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " +
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " +
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Dim xp As Integer = 3, yp As Integer = 4 'This is the point where we start drawing.
Dim textsize As Integer = 20 'This is the size of the drawn text.
Dim rectwidth As Integer = 14 'This is the width of the rectangle, in which we want to write the whole text.
Dim textheight As Single = gdpicturePDF.GetTextHeight(fontName, textsize) 'This is the height of the text = the height of one text line.
If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetTextSize(textsize) = GdPictureStatus.OK) Then
'It is important to set the size of the text before all drawing operations.
'Computing the number of text lines for the whole text.
Dim textlines As Integer = gdpicturePDF.GetWrappedTextLineCount(fontName, rectwidth, TextAlignment.TextAlignmentCenter, text, False)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim startPos As Integer = 0
Dim rectheight As Integer = CInt(Math.Abs(textheight * textlines)) + 1 'This is the whole height of the rectangle for writing the text.
If (gdpicturePDF.SetFillColor(0, 0, 255) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineWidth(0.04F) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawRectangle(xp, yp, rectwidth, rectheight, False, True) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawWrappedText(fontName, xp, yp, xp + rectwidth, yp + rectheight, TextAlignment.TextAlignmentCenter, text, False, startPos) = GdPictureStatus.OK) Then
'You can find out, if the whole text is drawn, by using the startPos parameter.
status = gdpicturePDF.SaveToFile("test_GetWrappedTextLineCount.pdf")
If status = GdPictureStatus.OK Then
message = "The example has been followed successfully and the file has been saved."
Else
message = "The example has been followed successfully, but the file can't be saved. Status: " + status.ToString()
End If
Else
message = message + gdpicturePDF.GetStat().ToString()
End If
Else
message = message + gdpicturePDF.GetStat().ToString()
End If
Else
message = message + gdpicturePDF.GetStat().ToString()
End If
Else
message = message + gdpicturePDF.GetStat().ToString()
End If
Else
message = "The AddStandardFont() method has failed with the status: " + status.ToString()
End If
Else
message = "The NewPDF() method has failed with the status: " + status.ToString()
End If
MessageBox.Show(message, caption)
gdpicturePDF.Dispose()
string caption = "Example: GetWrappedTextLineCount";
string message = "The example has not been followed successfully.\nThe last known status is ";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
string fontName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesBold);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
if (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK)
{
string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " +
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " +
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
int xp = 3, yp = 4; //This is the point where we start drawing.
int textsize = 20; //This is the size of the drawn text.
int rectwidth = 14; //This is the width of the rectangle, in which we want to write the whole text.
float textheight = gdpicturePDF.GetTextHeight(fontName, textsize); //This is the height of the text = the height of one text line.
if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
(gdpicturePDF.SetTextSize(textsize) == GdPictureStatus.OK))
//It is important to set the size of the text before all drawing operations.
{
//Computing the number of text lines for the whole text.
int textlines = gdpicturePDF.GetWrappedTextLineCount(fontName, rectwidth, TextAlignment.TextAlignmentCenter, text, false);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
int startPos = 0;
int rectheight = (int)Math.Abs(textheight * textlines) + 1; //This is the whole height of the rectangle for writing the text.
if ((gdpicturePDF.SetFillColor(0, 0, 255) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineWidth(0.04f) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawRectangle(xp, yp, rectwidth, rectheight, false, true) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawWrappedText(fontName, xp, yp, xp + rectwidth, yp + rectheight, TextAlignment.TextAlignmentCenter, text, false, ref startPos) == GdPictureStatus.OK))
{
//You can find out, if the whole text is drawn, by using the startPos parameter.
status = gdpicturePDF.SaveToFile("test_GetWrappedTextLineCount.pdf");
if (status == GdPictureStatus.OK)
message = "The example has been followed successfully and the file has been saved.";
else
message = "The example has been followed successfully, but the file can't be saved. Status: " + status.ToString();
}
else
message = message + gdpicturePDF.GetStat().ToString();
}
else
message = message + gdpicturePDF.GetStat().ToString();
}
else
message = message + gdpicturePDF.GetStat().ToString();
}
else
message = message + gdpicturePDF.GetStat().ToString();
}
else
message = "The AddStandardFont() method has failed with the status: " + status.ToString();
}
else
message = "The NewPDF() method has failed with the status: " + status.ToString();
MessageBox.Show(message, caption);
gdpicturePDF.Dispose();