PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Any tips on how to layout a PDF Document before coding ?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1727
Page 1 of 1

Author:  Shabalaka [ Thu Jul 28, 2011 11:32 pm ]
Post subject:  Any tips on how to layout a PDF Document before coding ?

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 ;)

Author:  mikesowerbutts [ Mon Aug 01, 2011 11:19 am ]
Post subject:  Re: Any tips on how to layout a PDF Document before coding ?

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/