|
PDFsharp - moved to http://forum.pdfsharp.net/ Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
|
View previous topic :: View next topic |
Author |
Message |
mdreyer
Joined: 24 Jul 2007 Posts: 2
|
Posted: Tue Jul 24, 2007 3:09 pm Post subject: Bug with Adding text to split pages |
|
|
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 |
|
Back to top |
|
|
mdreyer
Joined: 24 Jul 2007 Posts: 2
|
Posted: Tue Jul 24, 2007 4:08 pm Post subject: This does not work either... |
|
|
Does not give me an error...just does not write anything to the pdf file
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)
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()
Dim pagetmp As PdfPage = outputdoc.Pages.Add(page)
Dim gfx As PdfSharp.Drawing.XGraphics = _
PdfSharp.Drawing.XGraphics.FromPdfPage(pagetmp, XGraphicsPdfPageOptions.Append)
Dim font As New PdfSharp.Drawing.XFont("Verdana", 18, XFontStyle.Regular)
gfx.DrawString(TextBox1.Text.ToString(), font, XBrushes.Black, 30, 50, XStringFormat.Default)
outputdoc.Save(filename)
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 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|