This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Need to Fit an HTML file to an A4 pdf paper size.

guilherme.stenio wrote on 2012-07-30:
I need to fit an HTML file to an A4 paper size. As in the attachments I'm currently using the "test.html" to generate PDF files.
My current output is indicated by the "NOT_OK.pdf". I used the following web site do generate the "IS_OK.pdf" pdf file:

I tried to set PageHeight, PageWidth, PdfScalingFactor, PageLayout, PageMode, InitialPdfExactZoom and others properties to distinct values, but nothing seems to work for me, maybe I'm missing something.

Does anyone have any code sample that does the same thing as the sample in web site above ?

I'm using the code below

                FileStream fileStream;
                fileStream = new FileStream(@"C:\test.pdf", FileMode.CreateNew);

                c.convertFile(@"C:\test.html", fileStream);


Thanks in advance.
support wrote on 2012-07-31:
The table width is 960 pixels. Since there are 96 CSS pixels per inch the table width is 254mm (=10 inches). That means it is scaled down from 254 mm to 210 mm when it is printed to PDF.

To fit A4 you need the following
1. Change the table width from 960 pixels to 755. The default margins are 0.2in so the calculation goes like this:

2. Change your code:
 c.convertFile(@"C:\test.html", fileStream);

The modified html document and the resulting PDF are attached.
guilherme.stenio wrote on 2012-07-31:
Indeed. It was my mistake, setting the properties after the file generation.
Its working perfect.
Thank you for your quick support.