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