In my MVC application when it comes to printing of reports i have few options
RazorPDF - advanatage of handling design from cshtml itself & can pass values from controller as model
iTextSharp - advanatage of handling design from cshtml itself & can pass values from controller as model
pdfSharp - No advantage of handling design from cshtml page. Have to do all coding from .cs file & modifications is very difficult. BUt have a great control over the layout of generated report
So Can any one suggest a method with both options
- Can do the PDF design from cshtml itself.
- Can specify width and height of the PDF page
Since the report is not always to print on laser printers. Need to giv support for dotmatrix print as well and in that case i have to mention width & height of page .Also there is a possibility toprint on letter heads so i have to mention widtha nd height of empty area again
Or any one can suggest a way to mention to width and height of PDF page with RazorPDF and iTextSharp approach
Your question is about many different tools, but this is the answer in case you are using iTextSharp.
When you create a PDF from scratch using iTextSharp, you always need a
Documentand aPdfWriterclass. TheDocumentclass is to be used for the high-level functionality; thePdfWriterclass for the low-level operations.The page size is defined at the
Documentlevel. You can create a newDocumentobject like this:As we didn't pass any parameters to the constructor, iTextSharp will create a PDF using the default page size (A4) and margins of half an inch.
This is the equivalent of:
As you can see: I use 36 as value for half an inch, because 1 inch = 72 user units in PDF.
If you want to define another page size, you can do so by using one of the other values available in the
PageSizeclass, for instance:PageSize.A4andPageSize.LETTERare instances of theRectangleclass, so if you need a page size that isn't defined inPageSize, then you can create your own rectangle. For instance:Where do these values come from? Let's do the Math:
This is how you define pages with a custom size.