Before working with a PDF document, make sure to initialize the PDF component (see Getting Started with PDF).
This section illustrates how to merge two PDF documents into one document. This example assumes you have two loaded HMIGEAR PDF documents in memory, i.e., document1 and document2 (refer to Load and Save a PDF to learn how to load a PDF).
C and C++ |
Copy Code
|
---|---|
HIG_PDF_DOC pdf1 = 0; HIG_PDF_DOC pdf2 = 0; IG_mpi_info_get(document1, IG_MP_DOCUMENT, &pdf1, sizeof(HIG_PDF_DOC)); IG_mpi_info_get(document2, IG_MP_DOCUMENT, &pdf2, sizeof(HIG_PDF_DOC)); |
C and C++ |
Copy Code
|
---|---|
HMIGEAR targetDocument = 0;
HIG_PDF_DOC targetPdf = 0;
IG_mpi_create(&targetDocument, 0);
IG_PDF_doc_create(targetDocument);
IG_mpi_info_get(targetDocument, IG_MP_DOCUMENT, &targetPdf, sizeof(HIG_PDF_DOC));
|
At this point, the target PDF document has zero pages.
C and C++ |
Copy Code
|
---|---|
UINT firstPage = 0; IG_PDF_doc_insert_pages(targetPdf, IG_PDF_LAST_PAGE, pdf1, firstPage, IG_PDF_ALL_PAGES, IG_PDF_INSERT_ALL); IG_PDF_doc_insert_pages(targetPdf, IG_PDF_LAST_PAGE, pdf2, firstPage, IG_PDF_ALL_PAGES, IG_PDF_INSERT_ALL); |
C and C++ |
Copy Code
|
---|---|
UINT pageCount = 0;
IG_PDF_doc_get_page_count(targetPdf, &pageCount);
IG_mpi_file_save("merged.pdf", targetDocument, firstPage, firstPage, pageCount, IG_FORMAT_PDF,
IG_MPI_SAVE_OVERWRITE);
|