|
Rank: Newbie Groups: Member
Joined: 3/22/2013 Posts: 3
|
Hi, We are attempting to generate a 2-page landscape-oriented pdf with high-resolution images from a webpage. I am trying to do something similar to the instructions at the following page: http://www.essentialobjects.com/doc/4/htmltopdf/image_size.aspx. The html page actually has a filler image in the correct size in the desired location for the eventual image, and I am attempting to later render the high resolution image in its place. For some reason the images are rendered in the incorrect location (they overlap each other) on the first page, and no images are rendered at all on the second. Sample code:
Code: C#
HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(PdfPageSizes.A4.Height, PdfPageSizes.A4.Width);
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.2f, 0.2f, PdfPageSizes.A4.Height, PdfPageSizes.A4.Width);
PdfDocument doc = new PdfDocument();
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(strFileText, doc);
AcmRender render = new AcmRender(doc, new AcmPageLayout(new AcmPadding(0)));
render.SetDefPageSize(new System.Drawing.SizeF(PdfPageSizes.A4.Height, PdfPageSizes.A4.Width));
foreach (HtmlElement image in result.HtmlDocument.GetElementsByTagName("img"))
{
if (image.ClassName != null)
{
AcmImage acmImage = new AcmImage(LoadImage(image.ClassName));
acmImage.Style.Width = image.Size.Width;
acmImage.Style.Height = image.Size.Height;
AcmBlock acmBlock = new AcmBlock(acmImage);
acmBlock.Style.Left = image.Location.X;
acmBlock.Style.Top = image.Location.Y;
render.Render(acmBlock);
}
}
doc.Save(path);
LoadImage(image.ClassName) is loading the high resolution image (using the css class on the html image) from a directory, strFileText is the contents of the 2-page html document, and path is just the output file name. I've attempted to change the orientation, changed the padding on the page layout, etc, but the way the images are misplaced indicates to me that the location is being calculated incorrectly. And I'm uncertain how to render things at all on the second page; I assumed that the X and Y values would just carry over to page two but that is obviously not the case. Any insight would be appreciated, thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi
You don't have to do that at all. The HTML to PDF converter automatically retain your high resolution image. So for example, if the image used in your HTML has a DPI of 1200, then the image in the PDF will be at that resolution.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/22/2013 Posts: 3
|
We are noticing a visible downgrade in display quality of the images when doing so. I have tried the following settings:
Code: C#
HtmlToPdf.Options.PreserveHighResImages = true;
HtmlToPdf.Options.SaveImageAsJpeg = false;
If there are other settings I can try I'd love to have at it, this is a terrible workaround for us.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
With the latest build you can set SaveImageAsJpeg as true but make sure you you do NOT set HtmlToPdf.Options.JpegQualityLevel (keep the default value -1). That way the converter will keep all Jpeg image as is and compress other type of images as Jpeg.
I am not sure what you meant by "this is a terrible workaround" though.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/22/2013 Posts: 3
|
Having to manually render the images is the terrible workaround :) These files have small text in them that becomes significantly more difficult to read in the PDF even though it is readable in the base image.
I updated so that we're putting a 1200 dpi jpeg into the file with PreserveHighResImage and SaveImageAsJpeg both to true, and there is no discernible improvement from the other settings.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Shanna Terry wrote:I updated so that we're putting a 1200 dpi jpeg into the file with PreserveHighResImage and SaveImageAsJpeg both to true, and there is no discernible improvement from the other settings. That would look like a bug. The whole purpose of PreserveHighResImage is to keep your original high resolution image data. If you are not running the latest build, make sure you update to the latest build first ---- if problem still occurs with the latest build, we will need you to isolate the problem into a test project and send the test project to us. Let us know if you wish to do that so that we can send you further instructions.
|
|