'We assume that GdPicture has been correctly installed and unlocked.
'Firstly, we create a new PDF document.
Dim oGdPicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = oGdPicturePDF.NewPDF()
If status <> GdPictureStatus.OK Then
MessageBox.Show("Error occurred whe creating a new PDF document. Error: " + status.ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
GoTo [end]
End If
'For convenience reasons, set the measurement units and the origin.
oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
'Creating and inserting a new A4 sized page to the document.
status = oGdPicturePDF.NewPage(210, 297)
If status <> GdPictureStatus.OK Then
MessageBox.Show("Error occurred when creating a new page. Error: " + status.ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
GoTo [end]
End If
'Adding fonts that will be used in this PDF document.
Dim fontHelv As String = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
If oGdPicturePDF.GetStat() <> GdPictureStatus.OK Then
MessageBox.Show("Error occurred when adding fonts. Error: " + oGdPicturePDF.GetStat().ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
GoTo [end]
End If
Dim fontHelvBold As String = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelveticaBold)
If oGdPicturePDF.GetStat() <> GdPictureStatus.OK Then
MessageBox.Show("Error occurred when adding fonts. Error: " + oGdPicturePDF.GetStat().ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
GoTo [end]
End If
'Drawing the title in a blue rectangle and then drawing the page body.
If (oGdPicturePDF.SetLineColor(Color.Blue) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.SetLineWidth(2) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.DrawRoundedRectangle(10, 5, 190, 20, 3, False, True) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.SetTextSize(30) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.DrawTextBox(fontHelvBold, 10, 5, 200, 25, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Form Filling") = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.SetLineColor(Color.Black) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.SetLineWidth(0.1F) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.SetTextSize(10) = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.DrawText(fontHelv, 10, 40, "Name") = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.DrawText(fontHelv, 10, 50, "Nick Name") = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.DrawText(fontHelv, 10, 70, "Centre of interest") = GdPictureStatus.OK) AndAlso
(oGdPicturePDF.DrawRectangle(5, 30, 200, 80, False, True) = GdPictureStatus.OK) Then
'Adding some form fields.
Dim FieldNameId As Integer = oGdPicturePDF.AddTextFormField(40, 35, 90, 8, "Name", "Enter your name", False, fontHelv, 8, Color.Black)
If oGdPicturePDF.GetStat() <> GdPictureStatus.OK Then
oGdPicturePDF.SetFormFieldMaxLen(FieldNameId, 50)
Else
MessageBox.Show("Error occurred when adding form Name. Error: " + oGdPicturePDF.GetStat().ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Dim FieldNickNameId As Integer = oGdPicturePDF.AddTextFormField(40, 45, 90, 8, "Nickname", "Enter your nickname", False, fontHelv, 8, Color.Black)
If oGdPicturePDF.GetStat() <> GdPictureStatus.OK Then
oGdPicturePDF.SetFormFieldMaxLen(FieldNickNameId, 50)
Else
MessageBox.Show("Error occurred when adding form Nickname. Error: " + oGdPicturePDF.GetStat().ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Dim FieldCOIId As Integer = oGdPicturePDF.AddTextFormField(40, 55, 90, 30, "COI", "Enter your centre of interest", True, fontHelv, 8, Color.Black)
If oGdPicturePDF.GetStat() <> GdPictureStatus.OK Then
oGdPicturePDF.SetFormFieldMaxLen(FieldCOIId, 500)
Else
MessageBox.Show("Error occurred when adding form COI. Error: " + oGdPicturePDF.GetStat().ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'And finally, saving the PDF document.
status = oGdPicturePDF.SaveToFile("form.pdf")
MessageBox.Show("Finished! Status: " + status.ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Error occurred when drawing. Error: " + oGdPicturePDF.GetStat().ToString(), "Creating PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
[end]:
oGdPicturePDF.Dispose() |