PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Apr 01, 2026 1:35 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Sep 17, 2013 8:23 pm 
Offline

Joined: Tue Sep 17, 2013 8:16 pm
Posts: 3
I am having some trouble and can't seem to find out a way to do this... Is there a way to add borders with crop marks to an existing PDF? I am trying to take an existing PDF 8.5x11 and add .25 inch border around the whole document with crop marks for printing.


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 18, 2013 9:24 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3144
Location: Cologne, Germany
Not my area of expertise.

You can create a new, larger page with PDFsharp, draw the crop marks as lines and draw the page from the existing PDF also.

There may be better ways, but this way it will work.

See samples like Combine Documents, Concatenate Documents, or Two Pages on One:
http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 18, 2013 12:45 pm 
Offline

Joined: Tue Sep 17, 2013 8:16 pm
Posts: 3
Code:
Dim filename As String = txtUploadPath.Text
        ' Create the output document
        Dim outputDocument As New PdfDocument()

        outputDocument.PageLayout = PdfPageLayout.SinglePage

        Dim gfx As XGraphics

        ' Open the external document as XPdfForm object
        Dim form As XPdfForm = XPdfForm.FromFile(filename)
        ' Determine width and height
        Dim extWidth As Double = form.PixelWidth
        Dim extHeight As Double = form.PixelHeight

        Dim page As PdfPage = outputDocument.AddPage()
        'page.Orientation = PageOrientation.Landscape
        page.Width = (XUnit.FromInch(0.5).Point + extWidth)
        page.Height = (XUnit.FromInch(0.5).Point + extHeight)
        Dim width As Double = page.Width
        Dim height As Double = page.Height

        gfx = XGraphics.FromPdfPage(page)

        ' Skip if left side has to remain blank
        Dim box As XRect

        box = New XRect(0, 0, extWidth, extHeight)
        ' Draw the page identified by the page number like an image
        gfx.DrawImage(form, box)

        ' Save the document...
        filename = "Border.pdf"
        outputDocument.Save(filename)
        ' ...and start a viewer.
        Process.Start(filename)
        txtUploadPath.Text = "File uploaded"


Here is what I have... now the issue that I am running into is that the PDF image that is drawn in is left/top justified. Is there a way to center the image? I tried
Code:
gfx.DrawImage(form, box.center)
However this will start the image at the center. Do you know if there is a way to to manually adjust the starting point? I want to start the image top/left - 0.25 inch


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 18, 2013 1:10 pm 
Offline

Joined: Tue Sep 17, 2013 8:16 pm
Posts: 3
I was able to figure it out.

Code:
box = New XRect(XUnit.FromInch(0.25).Point, XUnit.FromInch(0.25).Point, extWidth, extHeight)
        gfx.DrawImage(form, box)


I didn't realize that you could set a starting point when you define the box size.


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

All times are UTC


Who is online

Users browsing this forum: AhrefsBot and 738 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