Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9094265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:18:39+00:00 2026-06-16T23:18:39+00:00

I’m working on a Java program that programmatically converts .doc- and .docx-files to pdf.

  • 0

I’m working on a Java program that programmatically converts .doc- and .docx-files to pdf. I’ve tested several different ways to convert .doc- and .docx-files to pdf such as using several open source Java libraries, sadly these libraries would often mess up the layout in the documents.

I’ve stumbled upon a javascript script to use the underlying Microsoft Word instance to open the file and save it as a PDF (found at: https://superuser.com/questions/17612/batch-convert-word-documents-to-pdfs-free/28303#28303):

var fso = new ActiveXObject("Scripting.FileSystemObject");
var docPath = WScript.Arguments(0);
var pdfPath = WScript.Arguments(1);
docPath = fso.GetAbsolutePathName(docPath);
var objWord = null;
try{
    WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'...");
    objWord = new ActiveXObject("Word.Application");
    objWord.Visible = false;
    var objDoc = objWord.Documents.Open(docPath);
    var wdFormatPdf = 17;
    objDoc.SaveAs(pdfPath, wdFormatPdf);
    objDoc.Close();
    WScript.Echo("The CV was succesfully converted.");
} catch(err){
    WScript.Echo("An error occured: " + err.message);
}finally{
    if (objWord != null){
        objWord.Quit();
    }
}

This javascript-script is called from my Java program synchronously for each document.

On a small scale this seems to work great, but when dealing with a lot of documents like several thousands, I encountered a couple of problems:

  • Sometimes one Word process would hang at the ‘Save as’-prompt, if this happened user intervention was needed to continue. Until any user interaction the process would just block.
  • Sometimes the Word process would hang at a ‘Bookmark’-prompt. The process is also blocked until any user intervention to pass the prompt.

I’m looking for the best/cleanest way to somehow control these Word processes better by giving them a deadline or something. Like giving them 5 seconds to open the Word document and save it as a PDF, after 5 seconds the process would be killed if still active.

I’ve dealt with something similiar in the past and the solution for that included a ‘kill word processes batch script’ to kill any WORD processes that were stuck after the program ended. Not very clean but it did its job.

Any experiences or ideas would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:18:40+00:00Added an answer on June 16, 2026 at 11:18 pm

    I managed to get around the issue related to the process being stuck at a prompt in Microsoft Word. In my final solution I altered my Java code to make it start the Javascript script in a separate Thread. My main Thread would then sleep for a few seconds and would then check the other Thread.

    The other Thread keeps a reference to the Process instance it uses to run the Javascript-script. The main Thread would then check the exitValue of that process, if the script would be stuck at a Microsoft Word prompt a IllegalThreadStateException would be thrown. I would then handle the Exception by killing the process and cleaning up any temporary files left by Microsoft Word.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.