Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdf not center the content Options
FcoCarrasco
Posted: Tuesday, March 26, 2013 4:56:16 PM
Rank: Newbie
Groups: Member

Joined: 3/22/2013
Posts: 4
People, i need help.
when i convert a page to pdf with HtmlToPdf.ConvertUrl(url), and i be using HtmlToPdf.AutoFitY = ScaleFit (or ShrinkFit), the content of the page is not center in the PDF, unless that in the html is center.

the code is:
Code: Visual Basic.NET
HtmlToPdf.Options.PageSize = PdfPageSizes.A4
HtmlToPdf.Options.OutputArea = New RectangleF(0.800000012F, 0.0F, PdfPageSizes.A4.Width - 1.5F, PdfPageSizes.A4.Height - 0.100000001F)
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.ShrinkToFit

Dim pdfdocTemp As New PdfDocument
HtmlToPdf.ConvertUrl(strUrl, pdfdocTemp)


plis any help Brick wall
eo_support
Posted: Tuesday, March 26, 2013 9:47:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

This is normal. When you use ScaleFit on the Y direction, X direction is scaled as well (otherwise the contents x/y ratio will be off, for example, text will appear as super thin or super short). That means on X direction the full document width is no longer the full page width. That will cause X direction content to be off center.

Thanks!
FcoCarrasco
Posted: Wednesday, March 27, 2013 7:42:47 AM
Rank: Newbie
Groups: Member

Joined: 3/22/2013
Posts: 4
then, What can i do?
a idea is increment the margins of the page (reducing the outputarea), but, if change the content's page, maybe can be the width longest that the output area.

any idea?
eo_support
Posted: Wednesday, March 27, 2013 10:28:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Yes. You can increase the margin of the page. But in order to find out the property value, you must know the exactly content width. In order to content width, you must know the scale factor. You can find out the scale factor by setting HtmlToPdf.PageSize to a "very long" page (so that output will fit in one page without scaling), then check HtmlToPdfResult.LastPosition. For example, if the final page output size is 9 inch high but HtmlToPdfResult.LastPosition is 18, then your scale factor will be 0.5.

After you find out the scale factor, you will know the margin to set. For example, the full page width is 6.5, and your scale factor is 0.5, then then actual output area will be 3.25. You can then set the margin so that this 3.25 inch area is in the middle of your page.

Hope this makes sense to you.

Thanks!
FcoCarrasco
Posted: Wednesday, March 27, 2013 11:35:15 AM
Rank: Newbie
Groups: Member

Joined: 3/22/2013
Posts: 4
Thanks for the idea, with this i can set the width's margins (in the example, 3.25, 1.625 in the left and rigth) for center the output area.

I can use this topic to do other cuestion?
(if necesary open other topic, i have not problem)
when i use the htmltopdf, when convert a URL to pdf, any css class aren't draw in the pdf.
for example, i have a asp label, that set the border, drawing the text inner a rectangle.
if i view the page in browser, that work fine, but in pdf, this border disappear.
also occurs with other controls (for example, in a gridview, i set the tittle gridview with white background, and a specific font, font size, font color, and in the pdf, take the default style).

when convert the page, this page inherit the css from the page that is using the htmltopdf?
or htmltopdf not take the styles properties from the asp controls? (because when a control reference a css class from style tag in header, or a css file, work fine)
eo_support
Posted: Wednesday, March 27, 2013 11:53:58 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

If you call ConvertUrl, then everything should work. If you call ConvertHtml, then you must set HtmlToPdf.Options.BaseUrl correctly. The HTML to PDF converter doesn't care about how the HTML is generated. As long as it can correctly for the Urls for all external resources (this is where it needs BaseUrl), it should render everything as you browser.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.