Dim caption As String = "Example: AddFreeTextAnnotation"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
'Please always select the required page before adding an annotation.
If gdpicturePDF.SelectPage(1) = GdPictureStatus.OK Then
Dim textSize As Single = 20
Dim text As String = "GdPicture freetext annot."
Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim textW As Single = gdpicturePDF.GetTextWidth(fontResName, textSize, text)
Dim status1 As GdPictureStatus = gdpicturePDF.GetStat()
Dim textH As Single = gdpicturePDF.GetTextHeight(fontResName, textSize, False)
Dim status2 As GdPictureStatus = gdpicturePDF.GetStat()
If (status1 = GdPictureStatus.OK) AndAlso (status2 = GdPictureStatus.OK) Then
Dim annotID As Integer = gdpicturePDF.AddFreeTextAnnotation(5, 5, textW, textH, False, "GdPicture", "Review", text,
fontResName, textSize, 90, 213, 213, 90, 0, 90, 255, 0, 0.75F)
'Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim annotType As String = gdpicturePDF.GetAnnotationType(annotID)
status1 = gdpicturePDF.GetStat()
Dim annotSubtype As String = gdpicturePDF.GetAnnotationSubType(annotID)
status2 = gdpicturePDF.GetStat()
Dim message As String = "The annotation has been created with the ID = " + annotID.ToString() + "." + vbCrLf + "type: "
If status1 = GdPictureStatus.OK Then message = message + annotType Else message = message + status1.ToString()
message = message + " subtype: "
If status2 = GdPictureStatus.OK Then message = message + annotSubtype Else message = message + status2.ToString()
If gdpicturePDF.SaveToFile("freetext.pdf") = GdPictureStatus.OK Then
message = message + vbCrLf + "The file has been saved."
Else
message = message + vbCrLf + "The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString()
End If
MessageBox.Show(message, caption)
Else
MessageBox.Show("The AddFreeTextAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The GetTextWidth()/GetTextHeight() method has failed with the status: " + status1.ToString() + "/" + status2.ToString(), caption)
End If
Else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The SelectPage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The file can't be created.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: AddFreeTextAnnotation";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
//Please always select the required page before adding an annotation.
if (gdpicturePDF.SelectPage(1) == GdPictureStatus.OK)
{
float textSize = 20;
string text = "GdPicture freetext annot.";
string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
float textW = gdpicturePDF.GetTextWidth(fontResName, textSize, text);
GdPictureStatus status1 = gdpicturePDF.GetStat();
float textH = gdpicturePDF.GetTextHeight(fontResName, textSize, false);
GdPictureStatus status2 = gdpicturePDF.GetStat();
if ((status1 == GdPictureStatus.OK) && (status2 == GdPictureStatus.OK))
{
int annotID = gdpicturePDF.AddFreeTextAnnotation(5, 5, textW, textH, false, "GdPicture", "Review", text,
fontResName, textSize, 90, 213, 213, 90, 0, 90, 255, 0, 0.75f);
//Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
string annotType = gdpicturePDF.GetAnnotationType(annotID);
status1 = gdpicturePDF.GetStat();
string annotSubtype = gdpicturePDF.GetAnnotationSubType(annotID);
status2 = gdpicturePDF.GetStat();
string message = "The annotation has been created with the ID = " + annotID.ToString() + ".\ntype: ";
if (status1 == GdPictureStatus.OK) message = message + annotType; else message = message + status1.ToString();
message = message + " subtype: ";
if (status2 == GdPictureStatus.OK) message = message + annotSubtype; else message = message + status2.ToString();
if (gdpicturePDF.SaveToFile("freetext.pdf") == GdPictureStatus.OK)
message = message + "\nThe file has been saved.";
else
message = message + "\nThe file can't be saved. Status: " + gdpicturePDF.GetStat().ToString();
MessageBox.Show(message, caption);
}
else
MessageBox.Show("The AddFreeTextAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The GetTextWidth()/GetTextHeight() method has failed with the status: " + status1.ToString() + "/" + status2.ToString(), caption);
}
else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The SelectPage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The file can't be created.", caption);
gdpicturePDF.Dispose();