Fixed Width Html Image in PDF - Fit to PDF Width
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.
Thanks
PDF Examples_ae6b668b.rar
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?
Regards
Geetha
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.
Result_9d81e7a9.rar
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.
Regards
Geetha
That does get me a lot closer, certainly enough to continue comparing on live documents.
Thank you for your help.
Hi Joshua,
Thank you for the update.
Regards
Geetha
- 5 Replies
- 2 Participants
-
JO Joshua
- Aug 29, 2012 11:47 AM UTC
- Sep 3, 2012 09:44 AM UTC