I create a PDF document using iTextSharp and this code:
Document pdfDoc = new Document(PageSize.A4.Rotate(), 10f, 10f, 100f, 0f);
I googled but I couldn't find the Envelope size. How do I set the page size as Envelope with Landscape orientation?
You are creating an A4 document in landscape format in iText 7 with this code:
PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdf, PageSize.A4); doc.setMargins(10f, 10f, 100f, 0f);
If you want to create a document in envelope format, you shouldn't create an A4 page, instead you should do this:
Document doc = new Document(pdf, new PageSize(envelope));
In this line,
envelope is an object of type
There is no such thing as the envelope size. There are different envelope sizes to choose from. Take a look at the envelope size chart.
For instance, if you want to create a page with the size of a 6-1/4 Commercial Envelope, then you need to create a rectangle that measures 6 by 3.5 inch. The measurement system in PDF doesn't use inches, but user units. By default, 1 user unit = 1 point, and 1 inch = 72 points.
Hence you'd define the
envelope variable like this:
Rectangle envelope = new Rectangle(432, 252);
6 inch x 72 points = 432 points (the width) 3.5 inch x 72 points = 252 points (the height)
If you want a different envelope type, you have to do the Math with the dimensions of that envelope format.
Click this link if you want to see how to answer this question in iText 5.