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

Extract first page of PDF, resize, then save to disk

Question

Is there a way using QuickPDF to extract the first page of the pdf, resize it down to say 100x150, then save it to disk?

I found this FAQ: Create preview thumbnail for each page in a pdf using visual C++

That talks about rendering out the thumbnails but its written in C and I'm not sure if I can apply the same technique using ASP.NET (C#) within a .aspx page.

Answer
// Open PDF File
int Handle = QPdf.DAOpenFile(pdfFilePath, "");

// It will get Reference of page 1 from PDF file
int PageRefNo = QPdf.DAFindPage(Handle, 1);

// Get width and height values from first pdf page
double pageWidth = QPdf.DAGetPageWidth(Handle, PageRefNo);
double pageHeight = QPdf.DAGetPageHeight(Handle, PageRefNo);

// DPI use for rendering the page. Increase DPI will increate quality of image
// but will generate an odd offset when the first page happens to be a graphic
int dpi = 72;

// Calculate Dimension of final output image
System.Drawing.Bitmap b = new System.Drawing.Bitmap(System.Convert.ToInt32(pageWidth), 
System.Convert.ToInt32(pageHeight));

// This will Draw render image on GDI
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
System.IntPtr dc = g.GetHdc();
QPdf.DARenderPageToDC(Handle, PageRefNo, dpi, (int)dc);
g.ReleaseHdc();

// Generate and save thumbnail image
System.Drawing.Image thumbNailImg;
thumbNailImg = b.GetThumbnailImage(125, 175, 
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
thumbNailImg.Save(pdfThumnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
thumbNailImg.Dispose();

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