PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Sep 24, 2018 5:17 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Jul 24, 2007 3:09 pm 
Offline

Joined: Tue Jul 24, 2007 3:01 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 24, 2007 4:08 pm 
Offline

Joined: Tue Jul 24, 2007 3:01 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group