Hello,
I have a multi-page PDF document that I need to split, add some text and then save the pdf page to a BLOB SQL Server field. I created a simple Proof of concept to test if this tool will work for me.
I open the source document in import mode, split into an individual page in a new document, close the new document, reopen the new document in Modify mode, draw some text, save the new document and close it.
I get no errors, however no text is added to the new document page.
What am I doing wrong?
Here is the source code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim inputdoc As PdfDocument = PdfReader.Open(txtPDFFile.Text, PdfDocumentOpenMode.Import)
For index As Integer = 0 To inputdoc.PageCount - 1
Dim page As PdfPage = inputdoc.Pages(index)
''inputdoc.Save(txtPDFFile.Text)
Dim filename As String = inputdoc.FullPath.Substring(0, inputdoc.FullPath.LastIndexOf(".pdf")) + _
"(Page " + String.Format("{0:000}", index + 1) + ").pdf"
Dim outputdoc As New PdfDocument(filename)
outputdoc.Pages.Add(page)
outputdoc.Close()
' reopen the new doc to modify and add the unique number
Dim newdoc As PdfDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Modify)
For i As Integer = 0 To newdoc.PageCount - 1
Dim NewPage As PdfPage = newdoc.Pages(i)
Dim gfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(NewPage)
Dim font As New PdfSharp.Drawing.XFont("Verdana", 10, XFontStyle.Regular)
gfx.DrawString(TextBox1.Text.ToString(), font, XBrushes.Black, 20, 20, XStringFormat.Default)
newdoc.Save(filename)
newdoc.Close()
Next
Next
inputdoc.Close()
MessageBox.Show("Done...")
Me.Close()
End Sub
|