C#: How do you create a Document object of custom size using iText 7?

Viewed 283

I am trying to create a Document object with a custom page size in C# using iText 7.

So far I have tried passing a rectangle using the documentation's definition for resolution of 72 user units per inch:

Rectangle pageSize = new Rectangle(288, 306);

string fullFilePath = "some string";
 PdfWriter pdfwriter = new PdfWriter(fullFileNamePDF);
            PdfDocument pdf = new PdfDocument(pdfwriter);
            pdf.AddNewPage();
            Document Doc = new Document(pdf, rect);

However, the code fails compilation with 'cannot convert from iText.Kernel.Geom.Rectangle to iText.Kernel.Geom.PageSize.'

1 Answers

You need to update your code so that you pass in a PageSize to the document constructor instead of the Rectangle directly.

e.g.

// This:
Document Doc = new Document(pdf, rect);

// Should be this:
Document Doc = new Document(pdf, new PageSize(rect));
Related