RenderPageToGdPictureImage produces poor quality image

Discussions about PDF management.
Post Reply
ryancole12
Posts: 4
Joined: Tue Aug 09, 2011 5:52 pm

RenderPageToGdPictureImage produces poor quality image

Post by ryancole12 » Wed Aug 10, 2011 6:16 pm

Hello,

I'm looping over pages in a PDF and using the RenderPageToGdPictureImage function to convert that page into an image. I am then saving that image into a second PDF. The image quality of the rendered page is terrible, though. It's nowhere near readable, so the OCR process that I do afterwards can't even process the text. Here's my code. Is there anything that I am not doing that might help raise the image quality?

Code: Select all

using System;
using GdPicture;

namespace NewGdPictureTest
{
    class Program
    {
        static void Main(string[] args)
        {
            String path_input = args[0];
            String path_temp = String.Format("{0}.tmp.pdf", path_input);

            // instanciate all the required objects
            GdPicturePDF the_pdf = new GdPicturePDF();
            GdPicturePDF the_pdf_flat = new GdPicturePDF();

            // unlock them
            if (!the_pdf.SetLicenseNumber("xxx"))
                Environment.Exit(0);

            // open the input pdf and the tmp pdf
            if (the_pdf.LoadFromFile(path_input, true) == GdPictureStatus.OK)
            {
                // create the new flat pdf
                the_pdf_flat.NewPDF(false);
                the_pdf_flat.SetJpegQuality(100);

                int page_count = the_pdf.GetPageCount();
                for (int x = 1; x <= page_count; x++)
                {
                    Console.WriteLine("Flattening page {0} of {1}.", x, page_count);

                    // activate the current page
                    the_pdf.SelectPage(x);

                    // rasterize the active page
                    int image_id = the_pdf.RenderPageToGdPictureImage(72, true);

                    // add the image to the temp pdf
                    if (the_pdf_flat.AddImageFromGdPictureImage(image_id, false, true).Length == 0)
                        Console.WriteLine("Failed to flatten page {0}.", x);
                }

                // save the flattened pdf
                the_pdf_flat.SaveToFile(path_temp);
                the_pdf_flat.CloseDocument();

                // close the original pdf
                the_pdf.CloseDocument();
            }
        }
    }
}

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: RenderPageToGdPictureImage produces poor quality image

Post by Loïc » Wed Aug 10, 2011 6:46 pm

Hi,

You are using too low DPI for rendering: 72.
I suggest to try at least 200 to get a good output quality.

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests