
|
Black Ice is developing the new PDF library that will support the PDF 1.4 file format (not just the Image PDF). This article contains a little sample that shows the usage of the new library. The following code snippet creates a CPDF object and than it loads information from the file. It shows how you can get the number of pages, get images from a page, get the size of a page and rendersa page to a DC or to a BITMAP.
// create the PDF object CPDF pdf; // load the PDF file if( !pdf.LoadPDFFile("test.pdf") ){ AfxMessageBox("PDF loading error!"); }
// get the number of pages int numberOfPages = pdf.GetNumberOfPages(); // get the number of images on page 1 int numberOfImages = pdf.GetNumberOfImages(1); // if there are any images in the first page then get the 1st image if( numberOfImages ){ HANDLE hDIB = pdf.GetImage(1,1); }
// get the size of the 1st page float width, height; pdf.GetPageSize(1, width, height);
// draw the 1st page to the client DC CClientDC dc(this); pdf.DrawPage(dc, 1);
// draw the 1st page to a BITMAP HBITMAP hBMP = pdf.DrawPageToBMP(1);
To get all information from the PDF file or from a page of a PDF, you can just call the get functions. To draw a page to a DC (Client DC, Metafile DC, Window DC), you can call the DrawPage function. This is a flexible solution to display the pages of the PDF file. By calling DrawPageToBMP, the pages of the PDF file can be displayed and saved as several image formats. |
