Skip to main content
Participant
July 1, 2021
Question

AcroExch crash after populating too many fields

  • July 1, 2021
  • 2 replies
  • 1145 views

I'm trying to populate a few thousands of PDF forms with around 100 fields per file. In Python it looks like this:

 
def createPDF(data) :

    import winerror
    from win32com.client.dynamic import DispatchERRORS_BAD_CONTEXT
    ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)

    template  = 'C:\\template.pdf'
 
    for row in data:
        app = Dispatch('AcroExch.App')
        pdfDoc = Dispatch('AcroExch.PDDoc')
        pdfDoc.Open(template)

        jso = pdfDoc.GetJSObject()
        jso.getField('field1').Value = row[0]
        #...
        jso.getField('field100').Value = row[99]
 
        pdfDoc.Save (33,  row[0] +  '.pdf')

        pdfDoc.close()
        app.CloseAllDocs
        app.exit
 
This is some very simplified version of the code. I know it can be faster with opening and closing 'AcroExch.App' outside the loop, safer with using try... but for this example it really does not matter.
 
It works quite good for small batches as it populates around 200 files per minute. Unfortunately with every additional file it starts to slowing down until crash with error like this:
AttributeError: Property '<unknown>.Value' can not be set
so in some moment it cannot populate anymore fields.
 
When it is running I see in task manager that Acrobat is using more and more memory, but those are some small values: it starts from 50MB, goes to arund 900MB and crashes when there is still a few GB of free memory. It really looks like Acrobat is leaving some trash that is slowing and crashing it down. 
 
In "Interapplication Communication withthe Acrobat SDK" I see that AcroExch.AVDoc.close function after closing file is allowing to reuse it ("To reuse an AVDoc object, close it with AVDoc.Close, then use the AVDoc object’s LPDISPATCH for AVDoc.OpenInWindow"), but in the descrition of other functions that I am using: AcroExch.PDDoc.close and AcroExch.App.CloseAllDocs there is noting about leaving something to reuse. 
 
 
I have this problem in Windows 10 Enerprise with using current Acrobat DC Pro (32-bit) version. I was testing also some other acrobat versions and even running AcroExch.App from VBA, but results were the same.
 
At the moment I have one workaround for this. On error and after some N created files(based on number of fields in a form) it is:
  • closing Acrobat with AcroExch.App.exit
  • wait around 15 or 20 seconds before opening it once again

This additional time allows system to close Acrobat app and clear all garbages from memory, but waiting 20 second every few minutes is not too efficient.

Do you maybe know some other way how it can be resolved? Something like forcing Actobat to clear cache without closing it or maybe just using some different functions to populate forms?

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
July 6, 2021

You are using Acrobat as an automation server. Not only is this against the license agreement, it's not suitable for the task (as you've already discovered).  You should be using a PDF Library or form filling tool. Both Appligent and Active PDF make tools specifically for this purpose. And there are many others.

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 6, 2021

Right... if I'm using one thread in a laptop to convert small excel file to PDFs during cofee break(less than 10 minutes) this is "automation server". xD Just please don't go with such idea to the microsoft as then they can move "mail merge" option from word to windows server. Are you really thinking that using some SDK for more than 5 minutes requires moving it to the server? Or maybe not leaving trash in a memory should require additional license? 

Legend
July 1, 2021

Acrobat is an interactive tool with tools for very low volume automation. Never mind 200 per minute, 200 is too many. Restart Acrobat at least every 100 files and check results carefully. 

BarlaeDC
Community Expert
Community Expert
July 6, 2021

HI ,

 

Everything said above, and you probably want to put something in place to make sure that Acrobat has actually exited fully before you start again.

Participant
July 6, 2021

Hi,

 

Sorry, but for me it is just a set of bugs in SDK and not something to deal with it.

 

First of all: any software should not leave trash in a memory after closing files. If from some reasons you have to leave references to closed files, then you should give user at least option to force some garbage collector or clear cache.

 

Second: if user is asking to close application it should be closed without keeping it hidden in a background to "open" it once again with all garbages from previous run.

 

SDK does not have any problems with populating files to fast, it is just crashing after populating too many fields. To be clear this "too many" fields is something that average laptp is able to populate literally in a less thatn 5 minutes. It really looks like software bug and not something that user shoud be worry about. We are talking here about paid comercial software that should not be crashing by defaulf after 5 minutes of using it.