We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Fixed Width Html Image in PDF - Fit to PDF Width

Thread ID:





104932 Aug 29,2012 11:47 AM UTC Sep 3,2012 09:44 AM UTC WinForms 5
Tags: PDF
Asked On August 29, 2012 11:47 AM UTC


I'm evaluating your HTML to PDF converter to see if it can give us the same or similar output as a component we currently use but would like to replace.

I've succeeded in converting a simple test page and the results are promising, however in order to get the same output I had to set the width of the image to a fixed value (688). This causes a problem as when the image is added to the PDF it does not take up the full width of the page as the other component does.

What I really need to do is resize the image to use the full width of the PDF, but I haven't yet found a way of doing this.

I've attached an example of the output I'm currently getting, and the output our current component gives us. Please let me know if there's any way of achieving the same result.


PDF Examples_ae6b668b.rar

Geetha M [Syncfusion]
Replied On August 30, 2012 10:56 AM UTC

Hi Joshua,

Thank you for evaluating Syncfusion products.

While converting a webpage, the width can be maintained at PdfPage size using the following code snippet:

PdfUnitConvertor convertor = new PdfUnitConvertor();

float width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);


using (HtmlToPdfResult result = html.Convert(@"http://www.google.com", ImageType.Metafile, (int)width, -1, AspectRatio.KeepWidth))


    result.Render(page, metafileFormat);


This makes the webpages with larger width to be drawn to the full page without any cut. Pages with smaller width will be drawn as it is in PDF. Could you please try the above code snippet and let me know?



Replied On August 30, 2012 03:41 PM UTC

Thanks for getting back to me.

The code snippet you provided does get me closer to the result I need, however as you mentioned because the page width is smaller than the width of the PDF it is rendered in the middle of the page.

Because I'm trying to match the output of our existing component I need it to stretch the full width of the PDF (minus margins) regardless of the size of the page. If you compare the output I now get (attached) with the output from our current component attached to my previous post, you can see the difference in the margins.

I realise this is an unusual requirement but unfortunately it's what we need to replicate.


Geetha M [Syncfusion]
Replied On August 31, 2012 06:08 AM UTC

Hi Joshua,

Thank you for the details.

You can easily adjust the margins using the following code snippet:

PdfDocument document = new PdfDocument();

document.PageSettings.Margins.All = 18;


PdfPage page = document.Pages.Add();

I could see that margin set to “18” yields output similar to you current component. Please try this and let me know if you have any other questions.



Replied On August 31, 2012 09:59 AM UTC


That does get me a lot closer, certainly enough to continue comparing on live documents.

Thank you for your help.

Geetha M [Syncfusion]
Replied On September 3, 2012 09:44 AM UTC

Hi Joshua,

Thank you for the update.




This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon