DynaPDF Manual - Page 219

Previous Page 218   Index   Next Page 220

Function Reference
Page 219 of 860
SI32 PDFToPDFA(const void* PDF, const char* InFileName, const char* OutFileName)
{
pdfCreateNewPDF(PDF, NULL);
// Don't override the producer with "DynaPDF 4.0..."
pdfSetDocInfo(PDF, diProducer, NULL);
// The flag ifPrepareForPDFA is required!
pdfSetImportFlags(PDF,ifImportAll | ifImportAsPage | ifPrepareForPDFA);
// Optional but recommended to reduce the memory usage
pdfSetImportFlags2(PDF, if2UseProxy);
if (pdfOpenImportFile(PDF, InFileName, ptOpen, NULL) < 0)
{
pdfFreePDF(PDF);
return -1;
}
pdfImportPDFFile(PDF, 1, 1.0, 1.0);
switch(pdfCheckConformance(PDF, ctPDFA_1b_2005, coDefault_PDFA_1,
PDF, // We need the instance pointer in the callback functions
pdf_OnFontNotFount,
pdf_OnReplaceICCProfile))
{
case 1: pdfAddRenderingIntent(PDF, m_RGBProfile); break;
case 2: pdfAddRenderingIntent(PDF, m_CMYKProfile); break;
case 3: pdfAddRenderingIntent(PDF, m_GrayProfile); break;
default: break;
}
// Still a PDF file in memory?
if (pdfHaveOpenDoc(PDF))
{
if (!pdfOpenOutputFile(PDF, OutFileName))
{
pdfFreePDF(PDF);
return -2;
}
pdfCloseFile(PDF);
}
TPDFError msg;
msg.StructSize = sizeof(msg);
SI32 e, errMsgCount = pdfGetErrLogMessageCount(PDF);
for (e = 0; e < errMsgCount; e++)
{
pdfGetErrLogMessage(PDF, e, &msg);
printf("Error: %s\n", msg.Message);
}
return 0;
}
int main(int argc, char* argv[])
{
// Process as many files as possible with one instance
void* pdf = pdfNewPDF();
if (!pdf) return -3; // Out of memory?
pdfSetOnErrorProc(pdf, NULL, PDFError);
pdfSetLicenseKey(pdf, "...");
// Not required but strongly recommended. External CMaps should be available when converting
// imported PDF files. The files are only loaded if necessary.
// Use an absolute path if possible! Otherwise the CMaps cannot be loaded if the working
// directory was changed.
pdfSetCMapDir("c:/MyAppPath/Resource/CMap/", TLoadCMapFlags(lcmDelayed | lcmRecursive));
SI32 retval = PDFToPDFA(pdf, "c:/test.pdf", "c:/cppout.pdf");
pdfDeletePDF(pdf);
return retval;
}
 

Previous topic: Return values

Next topic: CheckFieldNames, CircleAnnot