DynaPDF Manual - Page 134

Previous Page 133   Index   Next Page 135

Function Reference
Page 134 of 839
return retval;
}
SI32 TestDPart(const PPDF* PDF, const wchar_t* InFileName, wchar_t* OutFileName, bool Compress)
{
SI32 retval = 0, bufSize, last, node;
pdfCreateNewPDF(PDF, NULL);
pdfSetDocInfo(PDF, diProducer, NULL); // No need to override the producer
pdfSetImportFlags(PDF, ifImportAll | ifImportAsPage);
pdfSetImportFlags2(PDF, if2UseProxy);
if (InFileName)
{
if ((retval = pdfOpenImportFileW(PDF, InFileName, ptOpen, NULL)) < 0)
{
if (IsWrongPwd(retval))
{
// A password dialog should normally be displayed here
printf("File is encrypted!\n");
}
goto err;
}
if ((retval = pdfImportPDFFile(PDF, 1, 1.0, 1.0)) < 0) goto err;
}
// Create the required root node
const char* nameList[] = {"Root", "Pages"};
pdfCreateDPartRoot(PDF, nameList, 2, 3);
// GetFileBuf() is a helper function that returns the contents of an arbitrary file. See
// definition above.
char* dpmbase = GetFileBuf("f:/test.json", bufSize);
if (!dpmbase)
{
printf("Cannot open JSON file!\n");
goto err;
}
// This node holds some DPM for two child DPart nodes.
node = pdfAddDPartNode(PDF, -1, -1, -1, dpmbase);
free(dpmbase);
// We create two ranges for test purposes.
last = pdfGetPageCount(PDF) / 2;
const char json2[] = "\"CIP4_Production\":{\"CIP4_CopyCount\" : 1\"CIP4_User\":\"Stefan\"}";
const char json3[] = "\"CIP4_Production\":{\"CIP4_CopyCount\" : 1\"CIP4_User\":\"Jens\"}";
pdfAddDPartNode(PDF, node, 1, last, json2);
pdfAddDPartNode(PDF, node, last +1, pdfGetPageCount(PDF), json3);
// If you want to have a look into the resulting PDF file then deactivate object compression.
if (!Compress)
pdfSetGStateFlags(PDF, gfNoObjCompression | gfDoNotComprMetadata, false);
else
pdfSetGStateFlags(PDF, gfDoNotComprMetadata, false);
if (pdfHaveOpenDoc(PDF))
{
if ((retval = pdfOpenOutputFileW(PDF, OutFileName)) == TRUE)
retval = pdfCloseFile(PDF);
}
return retval;
err:
pdfFreePDF(PDF);
return retval;
}
 

Previous topic: How to create DPM?

Next topic: AddFieldToFormAction, AddFieldToHideAction