Before working with a PDF document, make sure to initialize the PDF component (see Getting Started with PDF).
This section illustrates how to convert a PDF to a raster image.
Refer to the PDF to Image Sample for complete sample code that illustrates how to use this capability.
C and C++ |
Copy Code
|
---|---|
LPSTR inputPath = "MyFilePath.pdf";
HMIGEAR document = 0;
IG_mpi_create(&document, 0);
IG_mpi_file_open(inputPath, document, IG_FORMAT_PDF, IG_MP_OPENMODE_READONLY);
|
C and C++ |
Copy Code
|
---|---|
const UINT firstPage = 0; HIGEAR page = 0; HIGEAR rasterPage = 0; // Get a handle to the first page. IG_mpi_page_get(document, firstPage, &page); // Rasterize the loaded page. IG_vector_data_to_dib(page, &rasterPage); |
C and C++ |
Copy Code
|
---|---|
const UINT firstPage = 0; HIGEAR page = 0; HIGEAR rasterPage = 0; AT_UINT resolution = 100; // Get a handle to the first page. IG_mpi_page_get(document, firstPage, &page); // Set the resolution of the PDF filter to 100 dots per inch. // This specifies the resolution used in the conversion to a raster image. IG_fltr_ctrl_set(IG_FORMAT_PDF, "RESOLUTION_X", (LPVOID)resolution, sizeof(resolution)); IG_fltr_ctrl_set(IG_FORMAT_PDF, "RESOLUTION_Y", (LPVOID)resolution, sizeof(resolution)); // Rasterize the loaded page. IG_vector_data_to_dib(page, &rasterPage); |
There are additional filters that you can use to control the rasterization process, such as the bit depth and smoothing. (Refer to PDF in the File Formats Reference for more details).
C and C++ |
Copy Code
|
---|---|
// Save the loaded page as a raster image. IG_fltr_save_file(rasterPage, "PdfToRaster.bmp", IG_SAVE_BMP_UNCOMP, firstPage, TRUE); // If the FormatType is set to IG_SAVE_UNKNOWN, ImageGear will check the file's // extension and save the image accordingly. IG_fltr_save_file(rasterPage, "PdfToRaster.png", IG_SAVE_UNKNOWN, firstPage, TRUE); IG_fltr_save_file(rasterPage, "PdfToRaster.jpg", IG_SAVE_UNKNOWN, firstPage, TRUE); |