PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 6:21 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Mar 24, 2007 4:04 pm 
Offline

Joined: Tue Feb 20, 2007 1:36 pm
Posts: 8
I want to excerpt information from PDF pages and use it in the pages of a new document, without the need to drag any information about the original page and the offsets of the excerpt along. This is what I came up with so far:

' load XPdfForm from file
Dim filename As String = "testpage.pdf"
Dim form As XPdfForm = XPdfForm.FromFile(filename)
form.PageNumber = 1
Dim OrigWidth As Double = form.Width
Dim OrigHeight As Double = form.Height

' set parameters for excerpt
Dim OffsetX As Double = 100
Dim OffsetY As Double = 600
Dim ExcerptWidth As Double = 400
Dim ExcerptHeight As Double = 600

' create new PdfDocument that has page dimensions
' just equal to the dimensions of the excerpt
Dim tmpPDFdoc As New PdfDocument
tmpPDFdoc.PageLayout = PdfPageLayout.SinglePage
Dim tmppage As PdfPage = tmpPDFdoc.AddPage
tmppage.Orientation = PageOrientation.Portrait
tmppage.Width = XUnit.FromPoint(ExcerptWidth)
tmppage.Height = XUnit.FromPoint(ExcerptHeight)

Dim box As XRect
box = New XRect(-OffsetX, OffsetY - OrigHeight, OrigWidth, OrigHeight)

' paint the excerpt into the new page
Dim gfx As XGraphics
gfx = XGraphics.FromPdfPage(tmppage)
gfx.DrawImage(form, box)

tmpPDFdoc.Save("tmp.pdf")
tmpPDFdoc.Close()

' now the excerpted content can be used in another
' document...
Dim myPDFdoc As New PdfDocument
myPDFdoc.PageLayout = PdfPageLayout.SinglePage
Dim page As PdfPage = myPDFdoc.AddPage
page.Orientation = PageOrientation.Portrait
page.Width = XUnit.FromPoint(1000)
page.Height = XUnit.FromPoint(2000)
gfx = XGraphics.FromPdfPage(page)
form = XPdfForm.FromFile("tmp.pdf")
form.PageNumber = 1
box = New XRect(100, 100, ExcerptWidth, ExcerptHeight)
gfx.DrawRectangle(New XPen(XColor.FromKnownColor(XKnownColor.Black)), box)
gfx.DrawImage(form, box)
myPDFdoc.Save("result.pdf")
myPDFdoc.Close()

What I am looking for is a more intelligent method that can avoid temporary storage of the excerpt in a file!

I have unfortunately no deep understanding of the PDF innards, so any help is highly welcome.

Peter


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 143 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