I have a problem with splitting a PDF document after adding a watermark to it.
Problem:
I am having a problem with splitting a PDF document after adding a watermark to it.
Within the application, the line below will fail after adding a watermark to the document:
nRet = PXCpVB_WriteDocumentW(n1stPageDocID, txt1stPage.Text, PXCp_CreationDisposition_Overwrite, PXCp_Write_NoRelease)
Resolution:
The application contained the following:
Code:
If IS_DS_FAILED(nRet) Then
GetErrorString nRet, True
Else
DeleteFile txtWatermark.Text
'Create watermark document from 1stPage document
PXCpVB_WriteDocumentW nOriginalDocID, txtWatermark.Text, PXCp_CreationDisposition_Overwrite, [color=#FF0000]PXCp_Write_Release[/color]
'MsgBox "Watermark created." & txtWatermark.Text
End If
'Release the lock
[color=#FF0000]PXCp_Delete nOriginalDocID[/color]
GetErrorString nRet, True
Else
DeleteFile txtWatermark.Text
'Create watermark document from 1stPage document
PXCpVB_WriteDocumentW nOriginalDocID, txtWatermark.Text, PXCp_CreationDisposition_Overwrite, [color=#FF0000]PXCp_Write_Release[/color]
'MsgBox "Watermark created." & txtWatermark.Text
End If
'Release the lock
[color=#FF0000]PXCp_Delete nOriginalDocID[/color]
The problem exists because an attempt to delete nOriginalDocID occured twice, which may cause highly unpredictable results. Also please note that if the function PXCpVB_WriteDocumentW fails (for example destination file is locked) the document will not be deleted, so you will likely get a memory leak.
Best solution for this case - always use PXCp_Write_NoRelease flag, and then call PXCp_Delete.
More Like This
-
KB#72: How do Icopy an image from an existing PDF file to a new PDF file and retain the original dimensions?
-
KB#227: I have an issue using the PDF-XChange SDK sample code with Microsoft Visual Basic in 'Interactive Mode' for debugging.
-
KB#50: Error when running application scheduled task
-
KB#51: I have a problem with my web application making calls to PXCLIB40.dll when running in 64 bit development environment
-
KB#63: Are there any examples of the low-level API functions?