Page 1 of 1

Updating PDF Producer throws an exception

Posted: Thu May 18, 2017 9:11 pm
by mmasood
Hi,

I am having an issue while updating the Producer of a PDF file. I am using Core Api and VB6 and this is happening for a particular set of files.

Following is the code that I am using for this:

Code: Select all

Public Function updateProducer(ByRef oCoreApi As clsCoreApi, ByRef pInst As PXC_Inst, sFileName As String, sProducer As String) As Boolean
    Dim pDoc As IPXC_Document
    
    On Error GoTo errorOccured
    
    ' load pdf file
    If Not oCoreApi.loadPdfFile(sFileName, pDoc, pInst) Then
        GoTo errorOccured
    End If
    
    ' update the pdf producer
    pDoc.Info.InfoStr(DocInfo_Producer) = sProducer
    
    ' save the pdf file
    oCoreApi.savePdfFile sFileName, pDoc
    
    Set pDoc = Nothing
    
    updateProducer = True
    Exit Function
    
errorOccured:
    If Not pDoc Is Nothing Then
        pDoc.Close
        Set pDoc = Nothing
    End If
    
    updateProducer = False
End Function
The line

Code: Select all

pDoc.Info.InfoStr(DocInfo_Producer) = sProducer
fails and goes to the error handler. The Err object shows the error description to be "Automation Error" and the error number is "-2112221168". I close out the document in the error handler block as you can see above.

The issue is that when that happens, my application throws a StackHeap exception after some time randomly. My questions are:

1. Is there a better way to do what I am trying to do here? If yes, can you share some VB6 code that I can use?
2. Is there a way the Core Api can tell me without throwing an exception that I cannot update the producer for a particular file? Any particular property/method that I can call before actually updating the producer?
3. Is there a way that I can cleanup after the exception so that my application does not throw run time heap exceptions after this exception is thrown?

Looking forward to your response.

Regards,
M

Re: Updating PDF Producer throws an exception

Posted: Fri May 19, 2017 7:53 am
by Sasha - Tracker Dev Team
Hello mmasood,

I've updated the Forum Rules window for the Editor SDK and Core API forums - there is a link that might help you there.

Cheers,
Alex

Re: Updating PDF Producer throws an exception

Posted: Fri May 19, 2017 2:10 pm
by mmasood
Hi Alex,

I tried to implement the FormatHRESULT method that you suggested but I am getting the an error when i try to compile the code. I have attached a snapshot of the code and error.

1. Is there any other way to get the information that you asked for?
2. Can you look into the issue without the error code?

and the questions from the first post still remain:

1. Is there a better way to do what I am trying to do here? If yes, can you share some VB6 code that I can use?
2. Is there a way the Core Api can tell me without throwing an exception that I cannot update the producer for a particular file? Any particular property/method that I can call before actually updating the producer?
3. Is there a way that I can cleanup after the exception so that my application does not throw run time heap exceptions after this exception is thrown?

Regards,
M

Re: Updating PDF Producer throws an exception

Posted: Fri May 19, 2017 2:25 pm
by Sasha - Tracker Dev Team
Hello mmasood,

Well it works here in our VB6 sample. The error itself means "Operation not permitted for the document.", that's why I asked you to look it up in the first place. This means that the document is protected and you cannot modify it unless you specify it's owner's password (or a valid certificate if it's the certificate security type).

Cheers,
Alex

Re: Updating PDF Producer throws an exception

Posted: Fri May 19, 2017 3:46 pm
by mmasood
Hi Alex,

This brings me back to my original question that I asked in the first post:

Is there a way the Core Api can tell me without throwing an exception that I cannot update the producer for a particular file? Any particular property/method that I can call before actually updating the producer?

What steps should i perform before changing the producer in order to know if the document is:

1. Password Protected
2. Invalid Certificate

Regards,
M

Re: Updating PDF Producer throws an exception

Posted: Mon May 22, 2017 1:42 pm
by Sasha - Tracker Dev Team
Hello mmasood,

Having an opened IPXC_Document you can use http://sdkhelp.tracker-software.com/vie ... Permission method to see whether the needed operation is permitted. In your case, you should check Perm_ObjDoc for Perm_OperModify.

Cheers,
Alex

Re: Updating PDF Producer throws an exception

Posted: Thu Aug 10, 2017 1:48 pm
by mmasood
Hi Alex,

I am trying to move the updating producer code to C# now. Following is a snippet of my code:

Code: Select all

    IPXS_Inst loPxsInst = pInst.GetExtension("PXS");
    IPXS_PDFVariant loVariant = loPxsInst.NewVar_String("Temp");
    // update the pdf producer
    loDoc.Info.SetInfoVar("DocInfo_Producer", loVariant);
The code above compiles correctly and even runs without any exception but does not update the Producer of the document. Can you take a look and let me know if there is anything wrong with the code?

Regards,
M

Re: Updating PDF Producer throws an exception

Posted: Thu Aug 10, 2017 3:03 pm
by Sasha - Tracker Dev Team
Hello mmasood,

Try changing the DocInfo_Producer to Producer and see whether it helps.

Cheers,
Alex

Re: Updating PDF Producer throws an exception

Posted: Thu Aug 10, 2017 3:35 pm
by mmasood
Hi Alex,

That did it. Thanks a lot. :)

Regards,
M

Re: Updating PDF Producer throws an exception

Posted: Thu Aug 10, 2017 3:45 pm
by Will - Tracker Supp
:D