PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

excerpt information from PDF pages

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
peteratoce



Joined: 20 Feb 2007
Posts: 5

PostPosted: Sat Mar 24, 2007 4:04 pm    Post subject: excerpt information from PDF pages Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com