ImageGear for C and C++ on Windows v19.2 - Updated
IG_PDF_doc_print
API Reference Guide > PDF Component API Reference > PDF Component Objects Reference > General Objects > HIG_PDF_DOC > IG_PDF_doc_print

Prints PDF pages from a PDF document, allowing the user to specify options such as page size, rotation, and fit mode.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_PDF_doc_print(
        HIG_PDF_DOC hDoc,
        LPAT_PDF_PRINTOPTIONS lpPrintOptions
);

Arguments:

Name Type Description
hDoc HIG_PDF_DOC Handle to the document to print.
lpPrintOptions LPAT_PDF_PRINTOPTIONS Parameters to control printing.

Return Value:

Error count.

Supported Raster Image Formats:

This function does not process image pixels.

Example

The following code fragment shows how to set up basic print options and print to file using the Microsoft XPS Document Writer printer driver. For a more elaborate example, see the legacy MFC PDF Sample.

C and C++
Copy Code
    HMIGEAR document;
    HIG_PDF_DOC pdfDocument;
    UINT pdfPageCount;
    HDC deviceContext;
    DOCINFO docInfo;
    int jobId;
    AT_PDF_PRINTPARAMS printParams;
    AT_PDF_PRINTOPTIONS printOptions;

    // Load the PDF document.
    IG_mpi_create(&document, 0);
    IG_mpi_file_open("sample.pdf", document, IG_FORMAT_PDF, IG_MP_OPENMODE_READONLY);
    IG_mpi_info_get(document, IG_MP_DOCUMENT, &pdfDocument, sizeof(HIG_PDF_DOC));
    IG_PDF_doc_get_page_count(pdfDocument, &pdfPageCount);
    IG_mpf_page_load(document, 0, pdfPageCount);

    // Set up the DC used for printing.
    deviceContext = CreateDC("WINSPOOL", "Microsoft XPS Document Writer", NULL, NULL);

    // Set the Windows related document printing parameters.
    memset(&docInfo, 0, sizeof(DOCINFO));
    docInfo.cbSize = sizeof(DOCINFO);
    docInfo.lpszDocName = "Sample Document";
    docInfo.lpszOutput = "sample.xps";

    // Start the print job.
    jobId = StartDoc(deviceContext, &docInfo);

    // Initialize PDF print parameters.
    memset(&printParams, 0, sizeof(AT_PDF_PRINTPARAMS));
    printParams.size = sizeof(AT_PDF_PRINTPARAMS);
    printParams.shrinkToFit = 1;
    printParams.emitPS = TRUE;
    printParams.psLevel = IG_PS_LEVEL_2;
    printParams.incBaseFonts = IG_PDF_INCLUDE_NEVER;
    printParams.incType3Fonts = IG_PDF_INCLUDE_ON_EVERY_PAGE;
    printParams.emitShowpage = TRUE;
    printParams.emitDSC = TRUE;
    printParams.setupProcsets = TRUE;
    printParams.binaryOK = TRUE;
    printParams.TTasT42 = TRUE;
    printParams.scale = 100.0;
    printParams.printWhat = IG_PDF_PRINT_DOCUMENT_AND_COMMENTS;
    printParams.printWhatAnnot = IG_PDF_PRINT_NO_EXTRAS;

    // Initialize PDF print options.
    memset(&printOptions, 0, sizeof(printOptions));
    printOptions.size = sizeof(printOptions);
    printOptions.emitToFile = FALSE;
    printOptions.printParams = &printParams;
    printOptions.paperWidth = IG_PDF_PRINT_USE_MEDIA_BOX;
    printOptions.paperHeight = IG_PDF_PRINT_USE_MEDIA_BOX;
    printOptions.emitToPrinter = TRUE;
    printOptions.inFileName = "sample.pdf";
    printOptions.endPage = pdfPageCount - 1;
    printOptions.shrinkToFit = 1;
    printOptions.printAnnots = 1;
    printOptions.nCopies = 1;
    printOptions.transQuality = 3;
    printOptions.startResult = jobId;
    printOptions.hDC = deviceContext;

    // Print the PDF document.
    IG_PDF_doc_print(pdfDocument, &printOptions);

    // Clean up.
    EndDoc(deviceContext);
    DeleteDC(deviceContext);    

Remarks:

For an overview on printing, see the section Printing Images.