• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AcroPDPage.GetSize Fails at Random places in Large Volume Processes

New Here ,
Mar 10, 2023 Mar 10, 2023

Copy link to clipboard

Copied

Hello - I'm developing an application in VBA to return a page level report including the X and Y values from the MediaBox struct on large volumes of PDFs for organizing by page size for printing. 

 

My program functions perfectly on smaller data sets. 

 

The issue I am having is that after ~4000 - 5000 pages I receive an runtime error stating that I have not SET an object correctly, which I find odd as the program worked perfectly for the large bit it got through.  This feels like a memory issue, which I have tried to solve using AcroApp.Exit.  However, I cannot seem to get AcroApp.Exit to return true.  

 

My File Listing and AcroPDDoc.GetNumPages sub has retrieved 

 

As an example, when I run this code in a module by itself, ExitAcroVar begins as false and remains false while CloseAllDocsVar changes from False to True. 

Sub TestAcro()

Dim pdfApp As AcroApp
Dim pdfDoc As AcroPDDoc
Dim ExitAcroVar As Boolean
Dim CloseAllDocsVar As Boolean

Set pdfApp = CreateObject("AcroExch.app")
Set pdfDoc = CreateObject("AcroExch.PDDoc")

CloseAllDocsVar = pdfApp.CloseAllDocs()
ExitAcroVar = pdfApp.Exit()

End Sub

 

To take a few steps back, in the immediate usecase for the larger program, I am first creating a sheet of ~7,000 files (QCSheet = Folder, Filename, PageCount) using the Dir function in a DoWhile loop and the below Acrobat functions: 

Do While xFileName <> ""
Cells(RowDocs, 1) = xFdItem
Cells(RowDocs, 2) = xFileName
pdfDoc.Open (xFdItem & xFileName)

//I am opening the PDF here because I want the pages during this initial process to create a progress bar of //sorts in the second process, but I could relegate this to the second sub. 
NumPages = pdfDoc.GetNumPages
Cells(RowDocs, 3) = NumPages
PDDocCloseVar = pdfDoc.Close
RowDocs = RowDocs + 1
xFileName = Dir

 

Then, using those pathfilenames, I am opening the PDFs again to loop through the pages in each doc and use the AcroPDPage.GetSize function. 

 

For i = 2 To RowDocs
pdfDoc.Open (Sheets("QCSheet").Cells(i, 1) & Sheets("QCSheet").Cells(i, 2))

 

For j = 0 To Sheets("QCSheet").Cells(i, 3) - 1
Cells(RowPages, 1) = Sheets("QCSheet").Cells(i, 1)
Cells(RowPages, 2) = Sheets("QCSheet").Cells(i, 2)
Cells(RowPages, 3) = Sheets("QCSheet").Cells(i, 3)
Set PDPage = pdfDoc.AcquirePage(j)
Set XYZ = PDPage.GetSize
Cells(RowPages, 4) = j + 1
Cells(RowPages, 5) = XYZ.x / 72 <- the documentation really buries the lead on how to use this stucture...
Cells(RowPages, 6) = XYZ.y / 72
RowPages = RowPages + 1
Next j

 

//Here is where I would like to add an If i Mod 1000 Then AcroApp.Exit...

PDDocCloseVar = pdfDoc.Close

 

Next i

 

Any help would be greatly appreciated! 

 

Thank you, 

Dean

TOPICS
Acrobat SDK and JavaScript , Windows

Views

521

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 10, 2023 Mar 10, 2023

Copy link to clipboard

Copied

Acrobat is an interactive tool with VERY LOW VOLUME automation. On no account try to use it on such huge datasets. My suspicion is that appexit.quit doesn't work any more, you might have to kill the process at worst.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2023 Mar 11, 2023

Copy link to clipboard

Copied

LATEST

I would recommend doing it using a stand-alone tool, instead of VBA via Acrobat. As mentioned, Acrobat is not suited for large-volume automation tasks and what you're tying to do can easily be done using a robust, command-line based tool, written in Java (for example).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines