|
Rank: Member Groups: Member
Joined: 2/21/2013 Posts: 12
|
I have 14 html divs that each represent a page. Each div has the same height and width (14.5 in X 8in). I am using page-break-after: always on divs.
I am having issues.
Requirements 1. PDF should generate exactly 14 pages (same as number of divs in html page). 2. Should be a 0.25 margin around each pdf page 3. **** Most importantly - when i print the pdf, 0.25 margin should persist and the page needs to be printed on the entire sheet of paper (see large bit of top and bottom margin)
After exhaustive testing, this is the only way I can get each div to be converted to a single pdf page: float width = 14.5f; float height = 8.3f; // need to add more height than actual div size
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ScaleToFit; HtmlToPdf.Options.PageSize = new SizeF(width, height);
//Set page layout arguments HtmlToPdf.Options.OutputArea = new RectangleF(marginLeft, marginTop,(EO.Pdf.HtmlToPdf.Options.PageSize.Width - marginLeft - marginRight), (EO.Pdf.HtmlToPdf.Options.PageSize.Height - marginTop - marginBottom));
This makes no sense to me. Shouldn't I just be able to set height and width to the same as the actual div size. I need to add an additional 0.3 inches to height inorder to get it working and it is not very consistent because sometimes a page will be rendered as 2 pages in the converted pdf.
The biggest issue I am having is when I go to print the pdf there is all kinds of white space on top and bottom. I need the pdf to be printed with the same dimensions (0.25in margin around).
Can you please help.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
Your code makes sense. The reason is the HTML to PDF converter will ALWAYS try to automatically find out a "good" page width. For example, if the page is designed to have a width of 800 pixel, then the HTML to PDF converter will try to find that value so that when it renders the page, the whole 800 pixel wide content will fit exactly on the whole paper with no extra margins (excluding the margins set in OutputArea) either on the left or on the right. Likewise if the page is designed to have a width of 1600 pixel, then the HTML to PDF converter will try to make all that 1600 pixels of content to fit exactly on the page. This is achieved by automatically scaling the output. This behavior is controled by HtmlToPdf.Options.AutoFitX and HtmlToPdf.Options.AutoFitY property.
Using ScaleToFit is the correct way to achieve what you wanted to do. However on the same time you will want to use a fixed width on your DIV so that the converter will be able to pick up the right width. If all the DIVs has the same fixed width value, then all DIVs will be scaled by the same factor, that way they will have the same margins.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/16/2013 Posts: 7
|
hi, i'm in the same situation, the big problem is in t the first and last page; in the first page i have a greyed area on the top of the page, there is a way to post my resulting pdf to clarify the problem? thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi Marco,
You may want to try to change your HTML to see what's causing the gray area. Usually it's caused by your HTML body's background image.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/16/2013 Posts: 7
|
hi, i changed the background color that was gray but i see the margin of the contentplaceholder of the masterpages, what i mean is that a got printed the content of the div (that is what i want) but i see the margin of their controls. i cand send the resulting pdf if can help thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi Marco, We don't need your PDF because we do not troubleshoot or debug for our users. Our previous reply has already clearly explained how scaling works. If you still have questions, you can take a look of this: http://www.essentialobjects.com/doc/4/htmltopdf/page_size.aspxhttp://www.essentialobjects.com/doc/4/htmltopdf/auto_fit.aspxHope this helps. Thanks!
|
|