ByteScout PDF Suite - C++ - Merge PDF Documents with PDF Extractor SDK - ByteScout

ByteScout PDF Suite – C++ – Merge PDF Documents with PDF Extractor SDK

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – C++ – Merge PDF Documents with PDF Extractor SDK

How to merge PDF documents with PDF extractor SDK in C++ with ByteScout PDF Suite

Step-by-step tutorial on how to merge PDF documents with PDF extractor SDK in C++

An easy to understand sample source code to learn how to merge PDF documents with PDF extractor SDK in C++ ByteScout PDF Suite: the bundle that provides six different SDK libraries to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript. It can merge PDF documents with PDF extractor SDK in C++.

Want to quickly learn? This fast application programming interfaces of ByteScout PDF Suite for C++ plus the guidelines and the code below will help you quickly learn how to merge PDF documents with PDF extractor SDK. This C++ sample code is all you need for your app. Just copy and paste the code, add references (if needs to) and you are all set! Further improvement of the code will make it more robust.

The trial version of ByteScout PDF Suite can be downloaded for free from our website. It also includes source code samples for C++ and other programming languages.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

CPPExample.cpp
      
#include "stdafx.h" #include "comip.h" // you may also refer to the tlb from \net4.00\ folder // you may also want to include the tlb file into the project so you could compile it and use intellisense for it #import "c:\\Program Files\\Bytescout PDF Extractor SDK\\net2.00\\Bytescout.PDFExtractor.tlb" raw_interfaces_only using namespace Bytescout_PDFExtractor; int _tmain(int argc, _TCHAR* argv[]) { // Initialize COM. HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // Create the interface pointer. _DocumentSplitterPtr pIDocumentSplitter(__uuidof(DocumentSplitter)); // Set the registration name and key // Note: You should use _bstr_t or BSTR to pass string to the library because of COM requirements _bstr_t bstrRegName(L"DEMO"); pIDocumentSplitter->put_RegistrationName(bstrRegName); _bstr_t bstrRegKey(L"DEMO"); pIDocumentSplitter->put_RegistrationKey(bstrRegKey); // you may enable optimization for extracted pages from documents // pIDocumentSplitter->put_OptimizeSplittedDocuments = true; // Load sample PDF document HRESULT sRes = S_OK; //1. extract selected pages (!note: page numbers are 1-based) _bstr_t bstrPath(L"..\\..\\sample2.pdf"); _bstr_t bstrParam(L"page2.pdf"); sRes = pIDocumentSplitter->ExtractPage(bstrPath, bstrParam, 2); // 2. split the doc into 2 parts at page #2 // (!) Note: page numbers are 1-based _bstr_t bstrPathInput(L"..\\..\\sample2.pdf"); _bstr_t bstrParam1(L"part1.pdf"); _bstr_t bstrParam2(L"part2.pdf"); sRes = pIDocumentSplitter->Split(bstrPathInput, bstrParam1, bstrParam2, 2); // 3. merge page 2 extracted on step 1 along with base pdf // Create the interface pointer. _DocumentMergerPtr pIDocumentMerger(__uuidof(DocumentMerger)); //_bstr_t bstrRegName(L"DEMO"); pIDocumentMerger->put_RegistrationName(bstrRegName); //_bstr_t bstrRegKey(L"DEMO"); pIDocumentMerger->put_RegistrationKey(bstrRegKey); // merge 2 files into the 3rd one _bstr_t bstrParamMerge1(L"page2.pdf"); _bstr_t bstrParamMerge2(L"..\\..\\sample2.pdf"); _bstr_t bstrParamMergeOutput(L"merged.pdf"); sRes = pIDocumentMerger->Merge2(bstrParamMerge1, bstrParamMerge2,bstrParamMergeOutput); // finally release both instances pIDocumentSplitter->Release(); pIDocumentMerger->Release(); // uninitialize ActiveX COM support CoUninitialize(); return 0; }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

stdafx.cpp
      
// stdafx.cpp : source file that includes just the standard includes // CPPExample.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

stdafx.h
      
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> // TODO: reference additional headers your program requires here

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

targetver.h
      
#pragma once // Including SDKDDKVer.h defines the highest available Windows platform. // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. #include <SDKDDKVer.h>

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next