Samples Overview
Basic Conversion | Features and Configuration | In Memory
Basic Conversion
Convert PDF to JPEG
Convert each page of a PDF document to a single JPEG image. Optionally set the quality for JPEG compression.
// Create the converter
using (Converter converter = new Converter())
{
// Open input file
if (!converter.Open(inputPath, ""))
throw new Exception(String.Format("Input file {0} cannot be opened. " +
"{1} (ErrorCode: 0x{2:x}).", inputPath, converter.ErrorMessage, converter.ErrorCode));
// Set image quality
converter.ImageQuality = quality;
// Loop over all pages of input file and create each time a new JPEG.
for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
{
string imagePath = Path.ChangeExtension(outputPath, null) + pageNo.ToString() + ".jpg";
// Create output JPEG
if (!converter.CreateImage(imagePath))
throw new Exception(String.Format("Output image {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x}).", imagePath, converter.ErrorMessage,
converter.ErrorCode));
// Render page from PDF to output JPEG
if (!converter.RenderPage(pageNo))
throw new Exception(String.Format("Page {0} of PDF {1} could not be rendered to " +
"JPEG {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath, imagePath,
converter.ErrorMessage, converter.ErrorCode));
// Close output image
if (!converter.CloseImage())
throw new Exception(String.Format("Output image {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x}).", imagePath, converter.ErrorMessage, converter.ErrorCode));
}
}
// Create the converter
converter = new Pdf2Img();
// Open input file
if (!converter.open(inputPath, ""))
throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
inputPath, converter.getErrorMessage(), converter.getErrorCode()));
converter.setImageQuality(quality);
// Loop over all pages of input file and create each time a new JPEG
for (int pageNo = 1; pageNo <= converter.getPageCount(); pageNo++)
{
// Construct path of output image in case of a multi-page input PDF
String imagePath = outputPath.substring(0, outputPath.lastIndexOf(".")) + pageNo + ".jpg";
// Create output JPEG
if (!converter.createImage(imagePath))
throw new IOException(String.format("Output image %s cannot be created. " +
"%s (ErrorCode: 0x%08x).", imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
// Render page from PDF to output JPEG
if (!converter.renderPage(pageNo))
throw new IOException(String.format("Page %d of PDF %d could not be rendered to JPEG %s. " +
"%s (ErrorCode: 0x%08x).", pageNo, inputPath, imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
// Close output image
if (!converter.closeImage())
throw new IOException(String.format("Output image %s cannot be closed. %s " +
"(ErrorCode: 0x%08x).", imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
}
// Create the converter
pConverter = Pdf2ImgCreateObject();
// Open input file
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szOutputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Set image quality
Pdf2ImgSetImageQuality(pConverter, iQuality);
// Loop over all pages of input file and create each time a new JPEG
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
// Change file name and extension
_tcstok(szOutputPath, _T("."));
_stprintf(szImagePath, _T("%s%d.jpg"), szOutputPath, iPage);
// Create output JPEG
if (!Pdf2ImgCreateImage(pConverter, szImagePath))
{
_tprintf(_T("Output image %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szInputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Render page from PDF to output JPEG
if (!Pdf2ImgRenderPage(pConverter, iPage))
{
_tprintf(_T("Page %d of PDF %s could not be rendered to JPEG %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output image
if (!Pdf2ImgCloseImage(pConverter))
{
_tprintf(_T("Output image %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
}
Convert PDF to PNG
Render each page of a PDF document to a single PNG image.
// Create the converter
using (Converter converter = new Converter())
{
// Open input file
if (!converter.Open(inputPath, ""))
throw new Exception(String.Format("Input file {0} cannot be opened. " +
"{1} (ErrorCode: 0x{2:x}).", inputPath, converter.ErrorMessage, converter.ErrorCode));
// Loop over all pages of input file and create each time a new PNG.
for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
{
string imagePath = Path.ChangeExtension(outputPath, null) + pageNo.ToString() + ".png";
// Create output PNG
if (!converter.CreateImage(imagePath))
throw new Exception(String.Format("Output image {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x}).", imagePath, converter.ErrorMessage, converter.ErrorCode));
// Render page from PDF to output PNG
if (!converter.RenderPage(pageNo))
throw new Exception(String.Format("Page {0} of PDF {1} could not be rendered to " +
"PNG {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath, imagePath,
converter.ErrorMessage, converter.ErrorCode));
// Close output image
if (!converter.CloseImage())
throw new Exception(String.Format("Output image {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x}).", imagePath, converter.ErrorMessage, converter.ErrorCode));
}
}
// Create the converter
converter = new Pdf2Img();
// Open input file
if (!converter.open(inputPath, ""))
throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
inputPath, converter.getErrorMessage(), converter.getErrorCode()));
// Loop over all pages of input file and create each time a new PNG
for (int pageNo = 1; pageNo <= converter.getPageCount(); pageNo++)
{
// Construct path of output image in case of a multi-page input PDF
String imagePath = outputPath.substring(0, outputPath.lastIndexOf(".")) + pageNo + ".png";
// Create output PNG
if (!converter.createImage(imagePath))
throw new IOException(String.format("Output image %s cannot be created. " +
"%s (ErrorCode: 0x%08x).",imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
// Render page from PDF to output PNG
if (!converter.renderPage(pageNo))
throw new IOException(String.format("Page %d of PDF %d could not be rendered to PNG %s. " +
"%s (ErrorCode: 0x%08x).", pageNo, inputPath, imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
// Close output image
if (!converter.closeImage())
throw new IOException(String.format("Output image %s cannot be closed. " +
"%s (ErrorCode: 0x%08x).", imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
}
// Create the converter
pConverter = Pdf2ImgCreateObject();
// Open input file
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szOutputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Loop over all pages of input file and create each time a new PNG
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
// Change file name and extension
_tcstok(szOutputPath, _T("."));
_stprintf(szImagePath, _T("%s%d.png"), szOutputPath, iPage);
// Create output PNG
if (!Pdf2ImgCreateImage(pConverter, szImagePath))
{
_tprintf(_T("Output image %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Render page from PDF to output PNG
if (!Pdf2ImgRenderPage(pConverter, iPage))
{
_tprintf(_T("Page %d of PDF %s could not be rendered to PNG %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output image
if (!Pdf2ImgCloseImage(pConverter))
{
_tprintf(_T("Output image %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
}
Convert PDF to TIFF and set specific compression
Render all pages of a PDF file to a multi-page TIFF file. Optionally set the algorithm for data compression and the compression quality when the TIFF is a container for JPEG images.
// Create the converter
using (Converter converter = new Converter())
{
// Open input file
if (!converter.Open(inputPath, ""))
throw new Exception(String.Format("Input file {0} cannot be opened. {1} (ErrorCode: {2}).",
inputPath, converter.ErrorMessage, converter.ErrorCode));
// Set compression and quality
converter.Compression = compression;
converter.ImageQuality = quality;
// Create output TIFF
if (!converter.CreateImage(outputPath))
throw new Exception(String.Format("Output image {0} cannot be created. " +
"{1} (ErrorCode: {2}).", outputPath, converter.ErrorMessage, converter.ErrorCode));
// Loop over all pages of input file and create a multi-page TIFF file
for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
{
// Render pages from PDF to output TIFF
if (!converter.RenderPage(pageNo))
throw new Exception(String.Format("Page {0} of PDF {1} could not be rendered to " +
"TIFF {2}. {3} (ErrorCode: {4}).", pageNo, inputPath, outputPath,
converter.ErrorMessage, converter.ErrorCode));
}
// Close output image
if (!converter.CloseImage())
throw new Exception(String.Format("Output image {0} cannot be closed. " +
"{1} (ErrorCode: {2}).", outputPath, converter.ErrorMessage, converter.ErrorCode));
}
// Create the converter
converter = new Pdf2Img();
// Open input file
if (!converter.open(inputPath, ""))
throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
inputPath, converter.getErrorMessage(), converter.getErrorCode()));
// Set compression and quality
converter.setCompression(compression);
converter.setImageQuality(quality);
// Create output TIFF
if (!converter.createImage(outputPath))
throw new IOException(String.format("Output image %s cannot be created. " +
"%s (ErrorCode: 0x%08x).", outputPath, converter.getErrorMessage(),
converter.getErrorCode()));
// Loop over all pages of input file and create multi-page TIFF file
for (int pageNo = 1; pageNo <= converter.getPageCount(); pageNo++)
{
// Render pages from PDF to output TIFF
if (!converter.renderPage(pageNo))
throw new IOException(String.format("Page %d of PDF %d could not be rendered to TIFF %s." +
" %s (ErrorCode: 0x%08x).", pageNo, inputPath, outputPath, converter.getErrorMessage(),
converter.getErrorCode()));
}
// Close output image
if (!converter.closeImage())
throw new IOException(String.format("Output image %s cannot be closed. " +
"%s (ErrorCode: 0x%08x).", outputPath, converter.getErrorMessage(),
converter.getErrorCode()));
// Create the converter
pConverter = Pdf2ImgCreateObject();
// Open input file
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Change file name and extension
_tcstok(szOutputPath, _T("."));
_stprintf(szImagePath, _T("%s.tif"), szOutputPath);
// Set compression and quality
Pdf2ImgSetCompression(pConverter, eCompression);
Pdf2ImgSetQuality(pConverter, iQuality);
// Create output TIFF
if (!Pdf2ImgCreateImage(pConverter, szImagePath))
{
_tprintf(_T("Output image %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Loop over all pages of input file and create each time a new TIFF
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
// Render pages from PDF to output TIFF
if (!Pdf2ImgRenderPage(pConverter, iPage))
{
_tprintf(_T("Page %d of PDF %s could not be rendered to TIFF %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
}
// Close output image
if (!Pdf2ImgCloseImage(pConverter))
{
_tprintf(_T("Output image %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
Features and Configuration
Convert PDF to image and set fax settings
Render pages of a PDF document to a bitonal multi-page TIFF. Apply Floyd-Steinberg dithering in order to create a visual effect of different grays in a 1-bit black-and-white image. Set the TIFF Class F settings.
// Create the converter
using (Converter converter = new Converter())
{
// Open input file
if (!converter.Open(inputPath, ""))
throw new Exception(String.Format("Input file {0} cannot be opened. " +
"{1} (ErrorCode: 0x{2:x}).", inputPath, converter.ErrorMessage, converter.ErrorCode));
// Set dithering
converter.Dithering = dithering;
converter.BitsPerPixel = 1;
converter.FitPage = true;
converter.Center = true;
PDFRendererOption2 rendererOptions = converter.Options2;
rendererOptions |= PDFRendererOption2.eOptionNoAntialiasing |
PDFRendererOption2.eOptionUseBoxFilter | PDFRendererOption2.eOptionFitPaths;
converter.Options2 = rendererOptions;
converter.RotateMode = PDFRotateMode.eRotatePortrait;
// Set the TIFF type fax settings
converter.FaxHSetting();
// Create output image
if (!converter.CreateImage(outputPath))
throw new Exception(String.Format("Output image {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x}).", outputPath, converter.ErrorMessage, converter.ErrorCode));
// Loop over all pages of input file and create each time a new image.
for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
{
// Render page from PDF to output image
if (!converter.RenderPage(pageNo))
throw new Exception(String.Format("Page {0} of PDF {1} could not be rendered to " +
"image {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath, outputPath,
converter.ErrorMessage, converter.ErrorCode));
}
// Close output image
if (!converter.CloseImage())
throw new Exception(String.Format("Output image {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x}).", outputPath, converter.ErrorMessage, converter.ErrorCode));
}
// Create the converter
converter = new Pdf2Img();
// Open input file
if (!converter.open(inputPath, ""))
throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
inputPath, converter.getErrorMessage(), converter.getErrorCode()));
// Set dithering
converter.setDithering(dithering);
converter.setBitsPerPixel(1);
converter.setFitPage(1);
converter.setCenter(true);
int renderOptions = converter.getOptions2();
renderOptions |= NativeLibrary.RENDEREROPTION2.eOptionNoAntialiasing |
NativeLibrary.RENDEREROPTION2.eOptionUseBoxFilter |
NativeLibrary.RENDEREROPTION2.eOptionFitPaths;
converter.setOptions2(renderOptions);
converter.setRotateMode(NativeLibrary.ROTATEMODE.eRotatePortrait);
// Set the TIFF type fax settings
converter.faxHSetting();
// Create output image
if (!converter.createImage(outputPath))
throw new IOException(String.format("Output image %s cannot be created. %s " +
"(ErrorCode: 0x%08x).", outputPath, converter.getErrorMessage(),
converter.getErrorCode()));
// Loop over all pages of input file and create a multi-page TIFF file
for (int pageNo = 1; pageNo <= converter.getPageCount(); pageNo++)
{
// Render page from PDF to output image
if (!converter.renderPage(pageNo))
throw new IOException(String.format("Page %d of PDF %d could not be rendered to image %s." +
" %s (ErrorCode: 0x%08x).", pageNo, inputPath, outputPath, converter.getErrorMessage(),
converter.getErrorCode()));
}
// Close output image
if (!converter.closeImage())
throw new IOException(String.format("Output image %s cannot be closed. " +
"%s (ErrorCode: 0x%08x).", outputPath, converter.getErrorMessage(),
converter.getErrorCode()));
// Create the converter
pConverter = Pdf2ImgCreateObject();
// Open input file
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Set dithering
Pdf2ImgSetDithering(pConverter, eDithering);
Pdf2ImgSetBitsPerPixel(pConverter, 1);
Pdf2ImgSetFitPage(pConverter, 1);
Pdf2ImgSetCenter(pConverter, 1);
TPDFRendererOption2 renderOptions = Pdf2ImgGetOptions2(pConverter);
renderOptions |= eOptionNoAntialiasing | eOptionUseBoxFilter | eOptionFitPaths;
Pdf2ImgSetOptions2(pConverter, renderOptions);
Pdf2ImgSetRotateMode(pConverter, eRotatePortrait);
// Set the TIFF type fax settings
Pdf2ImgFaxHSetting(pConverter);
// Create output image
if (!Pdf2ImgCreateImage(pConverter, szOutputPath))
{
_tprintf(_T("Output image %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Loop over all pages of input file and create a multi-page TIFF file
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
// Render pages from PDF to output image
if (!Pdf2ImgRenderPage(pConverter, iPage))
{
_tprintf(_T("Page %d of PDF %s could not be rendered to image %s. %s (ErrorCode: 0x%08x).\n"),
iPage, szInputPath, szOutputPath, Pdf2ImgGetErrorMessage(pConverter),
Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
}
// Close output image
if (!Pdf2ImgCloseImage(pConverter))
{
_tprintf(_T("Output image %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
In Memory
Create image in memory from PDF
Read a PDF from a byte stream and convert it to an image as byte stream. For demonstration purpose, the PDF byte stream is created from file and the image byte stream is written back to a file.
// Create the converter
using (Converter converter = new Converter())
{
// Open input file
if (!converter.OpenMem(inputBuffer, ""))
throw new Exception(String.Format("Input buffer cannot be opened. " +
"{0} (ErrorCode: 0x{1:x}).", converter.ErrorMessage, converter.ErrorCode));
// Loop over all pages of input buffer and create each time a new image.
for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
{
// Construct path of output image in case of a multi-page input PDF
string imagePath = converter.PageCount == 1 ? outputPath : Path.ChangeExtension(outputPath, null) + pageNo.ToString() + extension;
// Create output buffer
if (!converter.CreateImageInMemory(extension))
throw new Exception(String.Format("Output buffer cannot be created. " +
"{0} (ErrorCode: 0x{1:x}).", converter.ErrorMessage, converter.ErrorCode));
// Render page from input PDF to output image
if (!converter.RenderPage(pageNo))
throw new Exception(String.Format("Page {0} of PDF {1} could not be rendered to " +
"image {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath,
imagePath, converter.ErrorMessage, converter.ErrorCode));
byte[] outputBuffer = converter.GetImage();
if (outputBuffer == null)
throw new Exception(String.Format("Getting buffer of output image failed." +
"{0} (ErrorCode: 0x{1:x}).", converter.ErrorMessage, converter.ErrorCode));
// Write bytes to output file.
File.WriteAllBytes(imagePath, outputBuffer);
}
}
// Create the converter
converter = new Pdf2Img();
// Open input file
if (!converter.openMem(inputBuffer, ""))
throw new IOException(String.format("Input buffer cannot be opened. %s (ErrorCode: 0x%08x).",
converter.getErrorMessage(), converter.getErrorCode()));
// Loop over all pages of input file and create each time a new image
for (int pageNo = 1; pageNo <= converter.getPageCount(); pageNo++)
{
// Construct path of output image in case of a multi-page input PDF
String imagePath = outputPath.substring(0, outputPath.lastIndexOf(".")) + pageNo + extension;
// Create output buffer
if (!converter.createImageInMemory(extension))
throw new IOException(String.format("Output buffer cannot be created. " +
"%s (ErrorCode: 0x%08x).", converter.getErrorMessage(), converter.getErrorCode()));
// Render page from input PDF to output image
if (!converter.renderPage(pageNo))
throw new IOException(String.format("Page %d of PDF %s could not be rendered to image %s." +
" %s (ErrorCode: 0x%08x).", pageNo, inputPath, imagePath, converter.getErrorMessage(),
converter.getErrorCode()));
// Get image as buffer
byte[] outputBuffer = converter.getImage();
if (outputBuffer == null)
throw new IOException(String.format("Getting buffer of output image failed. " +
"%s (ErrorCode: 0x%08x).", converter.getErrorMessage(), converter.getErrorCode()));
// Write bytes to output file
Files.write(Paths.get(imagePath), outputBuffer, StandardOpenOption.CREATE_NEW);
}
// Close file of input buffer
if (!converter.close())
throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
inputPath, converter.getErrorMessage(), converter.getErrorCode()));
// Create the converter
pConverter = Pdf2ImgCreateObject();
// Open input file
if (!Pdf2ImgOpenMem(pConverter, pInputBuffer, nLength, _T("")))
{
_tprintf(_T("Input buffer cannot be opened. %s (ErrorCode: 0x%08x).\n"), Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Loop over all pages of input buffer and create each time a new image
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
// Change file name and extension
_tcstok(szOutputPath, _T("."));
_stprintf(szImagePath, _T("%s%d%s"), szOutputPath, iPage, szExtension);
// Create output buffer
if (!Pdf2ImgCreateImageInMemory(pConverter, szExtension))
{
_tprintf(_T("Output buffer cannot be created. %s (ErrorCode: 0x%08x).\n"), Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Render pages from PDF to output image
if (!Pdf2ImgRenderPage(pConverter, iPage))
{
_tprintf(_T("Page %d of PDF %s could not be rendered to image %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Get PDF as buffer
TPDFByteArray* pOutputBuffer = Pdf2ImgGetImage(pConverter);
if (!(pData = _tfopen(szOutputPath, _T("wb"))))
{
_tprintf(_T("Failed to create output file %s.\n"), szOutputPath);
iReturnValue = 1;
goto cleanup;
}
// Write bytes to output file
fwrite(pOutputBuffer->m_pData, pOutputBuffer->m_nLength, 1, pData);
fclose(pData);
}