Welcome Guest Search | Active Topics | Sign In | Register

ScaleToFit not working in ConvertHTML Options
CHIEN
Posted: Friday, February 7, 2014 2:05:14 AM
Rank: Member
Groups: Member

Joined: 9/4/2013
Posts: 18
Dear Support Team,

We found the option HtmlToPdfAutoFitMode.ScaleToFit not working in ConvertHTML,
but it's fine in ConvertUrl.

this is our code
HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(16.09F, 13.52F);
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(
0F,
0F,
16.09F,
13.52F
);

HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.MinLoadWaitTime = 1000;
string htmlFile = "scale.html";

//using ConvertUrl to get PDF
HtmlToPdf.ConvertUrl(htmlFile, "scale_url.pdf");


//using ConvertHtml to get PDF
PdfDocument pdfDoc = new PdfDocument();
string text = System.IO.File.ReadAllText(htmlFile);
HtmlToPdf.ConvertHtml(text, pdfDoc);
pdfDoc.Save("scale_html.pdf");

in theory ,scale_html.pdf and scale_url should be the same,
but we found scale_url.pdf is correct and scale_html.pdf is not.

Sample Files

Please see the screen.jpg in above link.

Best Regards,
Chien Chih


eo_support
Posted: Friday, February 7, 2014 9:11:03 AM
Rank: Administration
Groups: Administration

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

You have to set it again before calling ConvertHtml. AtuoFitX/AutoFitY are automatically reset to default value after every conversion.

Thanks!
CHIEN
Posted: Friday, February 7, 2014 6:25:45 PM
Rank: Member
Groups: Member

Joined: 9/4/2013
Posts: 18
ScaleToFit Still not working even when we set the option every time !!!
Please try our code and sample, ScaleToFit is not work when using HtmlToPdf.ConvertHtml()

HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(16.09F, 13.52F);
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(
0F,
0F,
16.09F,
13.52F
);

HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.MinLoadWaitTime = 1000;

//using ConvertHtml to get PDF
PdfDocument pdfDoc = new PdfDocument();
string text = System.IO.File.ReadAllText(htmlFile);
HtmlToPdf.ConvertHtml(text, pdfDoc);
pdfDoc.Save("scale_html.pdf");

Best Regards,
Chien Chih
eo_support
Posted: Friday, February 14, 2014 9:43:28 PM
Rank: Administration
Groups: Administration

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

AutoFitX/AutoFitY does work with ConvertHtml but they do not work the way you might have expected. Specifically, the converter does NOT scale the contents X/Y independently. So for example, if you have a single line of text that is 1000 pixels wide and 20 pixels tall and the page is 2000 pixels by 2000 pixels, then it won't scale 2 times on X direction and 100 times on Y direction. Instead it would scale min(x_scale_factor, y_scale_factor), in this case it would be 2. This is necessary so that the contents will always maintain their original X/Y ratio.

The converter uses a minimum window width of about 650 pixels. So if your HTML body element will be measured at least to be 650 pixels. That means the X scale ratio won't be too high. For example, for 16.09 inch, the X scale factor will only be 16.09 * 72 / 650 = 1.78. And that value will limit the Y scale factor since the actual scale factor is the lesser of the the two.

Thanks!
CHIEN
Posted: Saturday, February 15, 2014 5:37:22 PM
Rank: Member
Groups: Member

Joined: 9/4/2013
Posts: 18
Thanks for your explanation, really help a lot , now we understand scale much better.
But there still one thing really bothered us , the scale in HtmlToPdf.ConvertHtml is not the same
as HtmlToPdf.ConvertUrl.

if you can try our sample code, you will find the ConvertUrl() using much bigger scale ratio(X and Y) than
ConvertHtml(). in our test, the result PDF difference between ConvertUrl() and ConvertHTML is very obvious,
even when we use same html file ,same parameters.

the PDF generated by ConvertUrl() is actually what we want, but sad thing is ConvertUrl() can only load HTML from file,
since our HTML is store in the MemoryStream. it seem ConvertHtml() is our only option. so scale ratio became real problem,
if you can find us a way to let ConvertHtml() work same as ConvertUrl() , that will really solve our problem.

Thanks in advance,
Chien Chih





eo_support
Posted: Saturday, February 15, 2014 5:58:26 PM
Rank: Administration
Groups: Administration

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

That does not make much sense. The only real difference beween ConvertUrl and ConvertHtml is you usually need to set HtmlToPdf.Options.BaseUrl in order for ConvertHtml to correctly resolve external resources (script, image, CSS, etc), where as with ConvertUrl the BaseUrl is automatically derived from the full Url.

If the problem continues, please upload a test HTML file and we will try to run it both through ConvertUrl and ConvertHtml to see what we can find.

Thanks!
CHIEN
Posted: Sunday, February 16, 2014 10:23:20 PM
Rank: Member
Groups: Member

Joined: 9/4/2013
Posts: 18
Thanks for quick response and Yes , the difference between ConvertUrl() and ConvertHtml() doesn't make sense to us either.
we already upload sample file to dropbox.com(because we don't know how to upload to forum). can you take a look?

https://www.dropbox.com/sh/a779qcmyay4zt1c/ILsjmbxFVD#/

in this link,

scale_html.pdf - the PDF generate by ConvertHtml()
scale_url.pdf - the PDF generate by ConvertUrl()
scale.html - the source html file.
screen.jpg - the screen shot show the difference between ConvertHtml() and ConvertUrl()

our sample code

static void TestConvertUrl()
{
HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(16.01F, 13.86F);
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0F,0F,16.01F,13.86F);
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.MinLoadWaitTime = 1000;
string htmlFile = "scale.html";

//using ConvertUrl to get PDF
HtmlToPdf.ConvertUrl(htmlFile, "scale_url.pdf");
}

static void TestConvertHtml()
{
HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(16.01F, 13.86F);
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0F,0F,16.01F,13.86F);
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.MinLoadWaitTime = 1000;
string htmlFile = "scale.html";

//using ConvertHtml to get PDF
PdfDocument pdfDoc = new PdfDocument();
string text = System.IO.File.ReadAllText(htmlFile);
HtmlToPdf.ConvertHtml(text, pdfDoc);
pdfDoc.Save("scale_html.pdf");
}


eo_support
Posted: Saturday, February 22, 2014 10:16:07 PM
Rank: Administration
Groups: Administration

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

We have posted a new build that should fix this problem. You can download the new build from our download page.

Thanks!
CHIEN
Posted: Monday, February 24, 2014 11:46:32 PM
Rank: Member
Groups: Member

Joined: 9/4/2013
Posts: 18
Thank you very much! problem solved!
eo_support
Posted: Tuesday, February 25, 2014 8:16:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Great. Thanks for confirming the fix!


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.