Xojo Conferences
MBSOct2019CologneDE

DynaPDF Manual - Page 525

Previous Page 524   Index   Next Page 526

Function Reference
Page 525 of 767
Use the function IsWrongPwd() to determine whether the function failed due to a wrong password.
The function requires the return value of this function to determine whether the password was
wrong. The function can be executed in a loop so that the user is able to enter another password.
Damaged PDF files
The function reads the file header, the cross-reference tables and the required global objects when
opening a PDF file. It checks also if the first page object is available. When it is possible to load these
objects without errors then the file is loaded in normal mode by using the cross-reference table to
fetch objects. If an error occurs during loading the global objects then the function tries to repair the
file by scanning the all the objects in the file to rebuild the cross-reference table.
However, PDF files can contain damages in the cross-reference table which cause not necessarily an
error when opening the file, e.g. when the damages affect only specific pages in the file. In such cases
it is possible to load a file explicitely in repair mode. This can be achieved with the flag
ptForceRepair. The flag must be combined with a binary or operator with the parameter PwdType,
e.g. (TPwdType)(ptOpen | ptForceRepair).
The ptForceRepair flag should only be set if it was not possible to load specific pages due to errors in
the file. Check first whether the file was not already loaded in repair mode with GetInRepairMode().
If the function returns false then load the file in repair mode and try to import it again. If the file
contains no fatal errors then it is often possible to repair the damages.
The repair mode is supported for PDF files with an uncompressed file structure only because PDF
files with a compressed object structure are organized in a manner that does not allow further repair
actions.
Remarks:
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;
 

Previous topic: Damaged PDF files

Next topic: OpenOutputFileEncrypted