cognidox / OfficeToPDF

A command line tool to convert Microsoft Office documents to PDFs
https://www.cognidox.com/
Other
610 stars 137 forks source link

Error when trying to use this tool on a large number of PDF files and BAT script #2

Closed mspicer closed 6 years ago

mspicer commented 6 years ago

The issue comes when I'm trying to iterate through a group of files and convert them all to PDF. Here is the BAT script I am trying to use:

for %%f in (*.docx) do ( echo %%~nf OfficeToPDF.exe "%%~nf.docx" "%%~nf.pdf" )

The first file generates and then subsequent files do not and the command line give the following error: _Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALLREJECTED)) Did not convert

Other times when I run the script it creates a few files then hangs. And sometimes when I run the script MS Word opens with a message that document1 has been modified, would you like to save it.

Let me know your thoughts.

vittala commented 6 years ago

Hi

When working with Office, there's always the possibility of it triggering dialogs because it's not designed to be used un-attended.

Some things that may help:

Unfortunately, there's no magic bullet that can guarantee documents convert without intervention - Word documents are just too variable.

mspicer commented 6 years ago

Thank you for feedback!! I will try to add a delay to the code, that's a great idea. I wil ltry the /word_field_quick_update option as well. I've tried the /readonly option without any success, but maybe combine with the other it will work. I will report back.

Side question, are there compiling instructions or a dependency list? I've opened the .sln file in Visual Studio 2012 Express and am trying to build a debugging binary so that I can step through execution to see what the state is when it fails. Also another thing I'd like to consider adding is to add a timer and after X seconds close the program because its likely not going to convert. I've seen some issues with some of my docx files where the program simply hangs. If I can figure this out, I'd be glad to contribute my code back.

lalo-mx commented 6 years ago

In the project are missing some dependencies, i added the Office Primary Interop Assemblies with a NuGet Package and it worked.

Packages List

Interop.Microsoft.Office.Interop.OneNote Interop.Microsoft.Office.Interop.Publisher Microsoft.Office.Interop.Excel Microsoft.Office.Interop.Outlook Microsoft.Office.Interop.PowerPoint Microsoft.Office.Interop.Word Visio2010.PrimaryInteropAssembly Visio2013.PrimaryInteropAssembly

mspicer commented 6 years ago

Awesome, I'll give that a try.

Thanks!!