PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 12, 2024 4:14 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: Thu Jul 28, 2011 11:32 pm 
Offline

Joined: Thu Jul 28, 2011 11:19 pm
Posts: 1
Hi guys

Ive recently started using PDFSharp and it looks to do exactly what i need but what im wondering is there any way of laying out a PDF Document before attempting to code it ?

Just like when you lay out a mock webpage in Photoshop, From what i can gather is the XRect class acts very similar to a DIV tag in CSS with the X and Y locations indicating the location on the PDF of this Div(I,ll use the term DIV coz its easier atm lol) and the last 2 arguments are the sizes of the Div to place at a guess..

Also is there anyway to add Padding to a PDFPage something similar to

myPage.Padding = 10 (Create a page which has 10 points from all sides)


Any help is greatly appreciated.

Many Thanks Shab ;)


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 01, 2011 11:19 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I wouldnt recommend doing mock-ups in PdfSharp as using something like MS Word or even Excel will be much much quicker - like you use Photoshop becuase its all GUI based, rather than code based for webpages, but yes you're right about XRect's, though you will basically need to follow this process to add an xrect:
- create a PdfDocument object
- add a PdfPage pbject to the PdfDocument
- get an XGraphics object from the pdfPage (XGraphics.FromPdfPage(yourPageInstance);) - i figured it would be yourPageInstance.GetGraphics() at first....
- create new XRect and pass in the x/y/width/height
- call yourXGraphicsInstance.DrawRect(yourXRectInstance);
note that XGraphics objects are page specific - i tend to keep a List<XGraphics> somewhere global so i can get access at any point in my code to draw on any page (and i believe you can only call XGraphics.FromPdfPage(yourPageInstance); on a page once, hence why its useful to keep the reference somewhere global...

Re: the page padding, look at the samples provided with PdfSharp for MigraDoc, i use this:
Code:
Document.DefaultPageSetup.TopMargin = TopMargin = Unit.FromCentimeter(3);

which can be applied to all margins like this:
Code:
Document.DefaultPageSetup.TopMargin = Document.DefaultPageSetup.BottomMargin = = Document.DefaultPageSetup.LeftMargin = Document.DefaultPageSetup.RightMargin = Unit.FromCentimeter(3);

Where Document is an instance of a MigraDoc.DocumentObjectModel.Document Object...

PdfSharp tends to be much lower level, kind of like formatting a <p> tag within the tag instead of using CSS:
Code:
<p font="arial">sometext</p> as opposed to <p style="yourArialStyleWhichCanAccomplishMuchMore">sometext</p>

I tend to use PdfSharp for drawing graphics (and labels on those graphics) and MigraDoc for the higher level things like tables/parahgraphs etc.

Hope this helps,

Mike


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: Google [Bot] and 43 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