DynaPDF Manual - Page 564

Previous Page 563   Index   Next Page 565

Function Reference
Page 564 of 821
This function is implemented in an Ansi and Unicode compatible version. Unicode paths are
converted to UTF-8 on non-Windows operating systems.
Return values:
If the function succeeds the return value is zero or the file handle if the flag if2UseProxy is set (a
value greater or equal zero). If the function fails the return value is a negative error code. This code
can be used to check with IsWrongPwd() whether the supplied password was wrong.
Example (C):
This example loads a PDF file and encrypts it. After a PDF file was loaded it is also possible to edit
specific pages of it. Existing pages can be opened with EditPage()
// First, we declare an error callback function so that we can see all
// errors or warnings.
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode, const char*
ErrMessage, SI32 ErrType)
printf("%s\n", ErrMessage);
return 0;
int main(int argc, char* argv[])
char outFile[] = "cout.pdf";
void* pdf = pdfNewPDF(); // Create a new PDF instance
if (!pdf) return -2; // Out of memory?
pdfSetOnErrorProc(pdf, NULL, PDFError);
// The output file is opened later...
pdfCreateNewPDF(pdf, NULL);
// No need to convert pages to templates. See SetImportFlags() for
// further information.
pdfSetImportFlags(pdf, ifImportAll | ifImportAsPage);
pdfSetImportFlags2(pdf, if2UseProxy); // Reduce the memory usage
pdfOpenImportFile(pdf, "test.pdf", ptOwner, NULL);
pdfImportPDFFile(pdf, 1, 1.0, 1.0);
// No fatal error occurred?
if (pdfHaveOpenDoc(pdf))
// OK, now we can open the output file. The function can be called
// in a while statement, e.g. to display a file open dialog.
if (!pdfOpenOutputFile(pdf, outFile))
return -1;
// We encrypt the file, low-resolution printing should be allowed

Previous topic: Editing encrypted PDF files, Damaged PDF files

Next topic: OpenOutputFile

Start Chat