Knowledgebase

Back to Articles List

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]
 
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.
Was this article helpful?
Yes No Somewhat