I tried to render a PDF (letter size pages ~930px wide) as PNG. The PNG files produced were 1275px. How can I make sure the images are the same dimension as the original document?
Yes. v2.xxx was the .Net dll version.
using (Viewer viewer = new Viewer(workFileName))
{
PngViewOptions pngViewOptions = new PngViewOptions(@"D:\Temp\PCGD\work\" + filePrefix + "-{0}.png");
pngViewOptions.RenderComments = true;
viewer.View(pngViewOptions);
}
We are investigating this scenario. Your investigation ticket ID is VIEWERNET-2343. As there is any update, you’ll be notified.
Currently, the output image size is calculated. We’re looking at how we can solve this. As a workaround please try scaling the image down as shown in the code snippet below:
using (Viewer viewer = new Viewer("sample.pdf"))
{
PngViewOptions pngViewOptions = new PngViewOptions();
ViewInfo viewInfo = viewer.GetViewInfo(
ViewInfoOptions.FromPngViewOptions(pngViewOptions));
pngViewOptions.Width = viewInfo.Pages[0].Width;
pngViewOptions.Height = viewInfo.Pages[0].Height;
viewer.View(pngViewOptions);
}
This workaround will not work, if the pages within a document are not the same size. Its possible to have the first page in legal, second in letter size, and third in portrait, fourth in landscape, etc… Is there a way to make sure all pages are resize to the original and not just the size of the first page?
Currently, we’re looking into this issue and checking if we can make output image size to be the same as PDF document page size by default. We’ll keep you updated. Meanwhile, you can try the code below:
using (Viewer viewer = new Viewer("sample.pdf"))
{
PngViewOptions pngViewOptions = new PngViewOptions();
ViewInfo viewInfo = viewer.GetViewInfo(
ViewInfoOptions.FromPngViewOptions(pngViewOptions));
foreach (Page page in viewInfo.Pages)
{
pngViewOptions.Width = page.Width;
pngViewOptions.Height = page.Height;
viewer.View(pngViewOptions, page.Number);
}
}
The good thing is you will be able to render images with the same size as a size of pages in the source document. We’ve added a new option to PdfOptions
class. This feature will be available in version 20.2 that will be released soon. Once new version is on-board, we’ll notify you.