Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Create preview thumbnail for each page in a PDF using Visual C++

Question

I'm using Quick PDF with Visual C++ 6.0. I'd like to create a preview bitmap for each page in an opened PDF. I'm using RenderPageToDC, but I can't calculate right size for the bitmap, which I select do dc before calling the function. How can I get the right size? Or is there a better way to create the bitmap?

Answer

I've included some sample code for you below in Visual C++ that demonstrates how to create a thumbnail for each page in a PDF file using the RenderPageToDC function. The only enhancement you'll need to make to the code below is to loop through each page in your PDF to create the thumbnail and save it with a unique filename.

QuickPDFAX0718::PDFLibrary ^pdf = gcnew QuickPDFAX0718::PDFLibrary();
pdf->UnlockKey("...license key goes here...");

// Open PDF File
int Handle = pdf->DAOpenFile("C:\\temp\sample.pdf","");

// Get Total Number of Pages in a PDF File
int PageCount = pdf->DAGetPageCount(Handle);

int PageNo = 1;

// It will get Reference of page 1 from PDF file
int PageRefNo = pdf->DAFindPage(Handle, PageNo);

// You can change this parameter for Zoom In/Zoom Out purpose
// Try setting Zoom to 25,50,75,100,125 or with any suitable value
int Zoom = 20;
double pageWidth = pdf->DAGetPageWidth(Handle, PageRefNo) / Zoom;
double pageHeight = pdf->DAGetPageHeight(Handle, PageRefNo) / Zoom;

// DPI use for rendering the page. Increase DPI will increate quality of image
int dpi = 96;

// Calculate Dimension of final output image
System::Drawing::Bitmap ^b = gcnew System::Drawing::Bitmap (System::Convert::ToInt32(pageWidth * dpi), System::Convert::ToInt32(pageHeight * dpi));

// This will Draw render image on GDI
Graphics ^ g = Graphics::FromImage(b);
System::IntPtr dc = g->GetHdc();
pdf->DARenderPageToDC(Handle, PageRefNo, dpi,(int) dc);
g->ReleaseHdc();

// Assigne rendered image to PictureBox Control which will display PDF on Windows Form.
pictureBox1->Image = b;
}

© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum