Free Support Forum - groupdocs.com

Document Viewer size discrepancy in .NET

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?

@alwinmartin,

Can you please share the PDF, sample code and API version that you are evaluating?

GroupDocs.Viewer for .Net

v2.0.50727

1-Page.pdf (2.8 KB)

@alwinmartin,

Please share sample code as well.

Do you mean 20.1?

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);
        }

@alwinmartin,

We are investigating this scenario. Your investigation ticket ID is VIEWERNET-2343. As there is any update, you’ll be notified.

@alwinmartin,

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?

@alwinmartin,

We are further investigating this. You’ll be notified about the outcomes.

@alwinmartin,

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.

@alwinmartin,

Your reported issue VIEWERNET-2343 is now resolved in version 20.2.