Creating PDF
C++ Code Snippet
EasyPDFPrinter::IPrinterPtr oPrinter;
oPrinter.CreateInstance("easyPDF.Printer.7");
EasyPDFPrinter::IPrintJobPtr oPrintJob = oPrinter->GetPrintJob();
oPrintJob->PrintOut("C:\\input.doc", "C:\\output.pdf");
C++ Sample Projects
Processing PDF (Merging PDFs, Splitting PDF, Extracting Text from PDF, etc)
- Read the PDFProcessor Object Specification
This object lets you do post-processing of existing PDF files (such as merging multiple PDF files into one, splitting one PDF file into two, and encrypting/decrypting a PDF file)
C++ Sample Projects
C++ Code Snippet for Merging PDF Files
EasyPDFProcessor::IPDFProcessorPtr oProcessor;
oProcessor.CreateInstance("easyPDF.PDFProcessor.7");
// merge two files using Merge
oProcessor->Merge("C:\\input1.pdf", "C:\\input2.pdf", "C:\\merged.pdf");
// merge more than two files using MergeBatch
SAFEARRAYBOUND bound;
bound.lLbound = 0;
bound.cElements = 3;
SAFEARRAY *inputFiles = SafeArrayCreate(VT_VARIANT, 1, &bound);
std::string filesToMerge[] = { "C:\\input1.pdf", "C:\\input2.pdf", "C:\\input3.pdf" };
int numFiles = sizeof(filesToMerge) / sizeof(std::string);
_variant_t var;
_variant_t inputArray;
char *file;
_bstr_t str;
long ix;
var.vt = VT_BSTR;
for (int i = 0; i < numFiles; i++)
{
ix = i;
file = const_cast<char *>(filesToMerge[i].c_str());
str = file;
var.bstrVal = str;
SafeArrayPutElement(inputFiles, &ix, &var);
}
inputArray.vt = VT_ARRAY|VT_VARIANT;
inputArray.parray = inputFiles;
oProcessor->MergeBatch(inputArray, "C:\\merged.pdf");
Code Snippet for Splitting PDF
EasyPDFProcessor::IPDFProcessorPtr oProcessor;
oProcessor.CreateInstance("easyPDF.PDFProcessor.7");
// split the document at page 3
oProcessor->Split("C:\\input.pdf", "C:\\part1.pdf", "C:\\part2.pdf", 3);
Code Snippet for Extracting Text from PDF
EasyPDFProcessor::IPDFProcessorPtr oProcessor;
oProcessor.CreateInstance("easyPDF.PDFProcessor.7");
// extract text from pages 1 through 4 to a physical file using ExtractText
oProcessor->ExtractText("C:\\input.pdf", "C:\\extracted.txt", NULL, 0, 3, NULL, NULL);
// extract text from a bounding box on page 1 to a string variable using ExtractText2
std::string text = oProcessor->ExtractText2("C:\\input.pdf", 0, 0, 0, 300, 300, NULL);
Rasterizing PDF
C++ Code Snippet
EasyPDFConverter::IPDFConverterPtr oConverter;
oConverter.CreateInstance("easyPDF.PDFConverter.7");
EasyPDFConverter::IPDF2ImagePtr oPDF2Image = oConverter->GetPDF2Image();
oPDF2Image->Convert("C:\\input.pdf", "C:\\output.jpg", NULL, NULL, NULL);
C++ Sample Projects
Processing PDF Form Fields
C++ Code Snippet
Download the input.pdf form (highlighted below)
// this example takes the first two fields in a PDF template
// which are Name and Address
// and populates them with values of "BCL Technologies" and "Santa Clara, CA"
EasyPDFDocument::IPDFDocumentPtr oDocument;
oDocument.CreateInstance("easyPDF.PDFDocument.7");
oDocument->Open("C:\\input.pdf");
// get all form fields from the PDF
EasyPDFDocument::IFormFieldsPtr oFormFields = oDocument->FormFields;
// get the first form field
EasyPDFDocument::IFormFieldPtr oFormField = oFormFields->Item[0];
EasyPDFDocument::ITextFieldPtr oTextField;
if (oFormField->Type == EasyPDFDocument::DOC_FRMTYPE_TEXT && oFormField->Name == _bstr_t("Name"))
{
// set Name to "BCL Technologies"
oTextField = oFormField;
oTextField->Value = "BCL Technologies";
}
// get the second form field
oFormField = oFormFields->Item[1];
if (oFormField->Type == EasyPDFDocument::DOC_FRMTYPE_TEXT && oFormField->Name == _bstr_t("Address"))
{
// set Address to "Santa Clara, CA"
oTextField = oFormField;
oTextField->Value = "Santa Clara, CA";
}
oDocument->SaveAs("C:\\output.pdf");
C++ Sample Projects