Beispiele-Übersicht

Basis Konversion | Funktionen und Konfiguration | In Memory

Basis Konversion

PDF nach JPEG konvertieren

Konvertiere jede Seite eines PDF Dokumentes in ein einzelnes JPEG Bild. Setze optional die Qualität der JPEG Kompression.

C# Beispiel:
// 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));
    }
}
Java Beispiel:
// 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()));
}
C Beispiel:
// 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;
    }
}

PDF in PNG konvertieren

Rendere jede Seite eines PDF Dokuments zu einer einzigen PNG Bilddatei.

C# Beispiel:
// 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));
    }
}
Java Beispiel:
// 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()));
}
C Beispiel:
// 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;
    }
}

PDF in TIFF konvertieren und spezifische Kompression einstellen

Rendere alle Seiten einer PDF Datei in eine mehrseitige TIFF Datei. Optional kann der Algorithmus für die Datenkompression und die Kompressionsqualität eingestellt werden, wenn das TIFF ein Container für JPEG Bilder ist.

C# Beispiel:
// 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));
}
Java Beispiel:
// 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()));
C Beispiel:
// 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;
}

Funktionen und Konfiguration

PDF in Bild konvertieren und Faxeinstellungen festlegen

Rendere Seiten eines PDF Dokuments zu einem bitonalen mehrseitigen TIFF. Wende dabei die Floyd-Steinberg-Dithering-Funktion an, um einen visuellen Effekt verschiedener Grautöne in einem 1-Bit-Schwarz-Weiss-Bild zu erzeugen. Lege die TIFF Class F-Einstellungen fest.

C# Beispiel:
// 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));
}
Java Beispiel:
// 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()));
C Beispiel:
// 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

Erstellen von Bildern im Speicher aus PDF-Dateien

Lese ein PDF aus einem Byte-Stream und konvertiere es in ein Bild als Byte-Stream. Zu Demonstrationszwecken wird der PDF-Byte-Stream aus einer Datei erzeugt und der Image-Byte-Stream wird in eine Datei zurückgeschrieben.

C# Beispiel:
// 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);
    }
}
Java Beispiel:
// 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()));
C Beispiel:
// 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);
}