TLDR: How can I convert a DOC(X) to a PDF and keep CustomDocumentProperties and Fields - so that I can programmatically update the Custom Properties and print the PDF via a Windows Service?


We have a custom in-house application that pairs DOCX creation - followed with field updates and printing. The application as it is - a Windows Form based program - works but requires it to be run from user shell. I want to upgrade this program to be run from a Windows Service.

THE issue with DOCX in a Windows Service is printing. Must have Word Installed on the Server. Word doesn't play well outside of a user shell - Modal Dialogs, user prompts (do you want to restore one of these? Do you want to enable editing of this document? etc), required registry entries, etc.

I'm exploring adjusting our workflow to PDFs on the server.


DOC(X) Prep/Creation (Manual, not in-program):

  • Import/Run VBScript:
    • Get table/view columns out of a database.
    • Each column goes into a Custom DocumentProperty.
  • Place Fields into document for desired Custom Properties.

So CustomerName, AddressLine1, City, etc get added as CustomDocumentProperties... then the fields get placed in the right spots on a form to print automatically in the automated program.

DOCX Usage (Automatic, in program):

  • Pull row from same table
  • Put correct data into each CustomDocumentPropertyField
  • Update fields (replaces CustomerName with Doe, John, City with Whoville, etc)
  • Print document to correct printer

Desired Changes

I'm looking to either

a. Convert the DOC(X) to a PDF in such a way that the custom properties transfer - as well as the ability to replace the fields - remains intact. Would be 1) Create DOCX (lots of these currently exist and is current workflow), 2) Convert to PDF, 3) Update/print PDF. PRO: Continued use of word products that customers are happy with/trained in. CONS: Possibly complex docx/pdf conversion in the middle in exchange for the easier PDF printing inside a windows service.

b. Replace DOC(X) completely and instead use PDF creation tools. PRO: Same two step process. CON: Users are used to DOC(X) creation. Additional software/training may be needed. Lots of documents would need to be converted.

c. Work around DOCX as a service and get it to print inside a service.

This question is exploring a - DOC(X) conversion to PDF. Given a Word Document with Custom Document Properties and Fields placed on the document... I seem to lose those properties AND the fields are replaced with the current values when I convert to PDF via Save As PDF in Word. What other viable options are there to convert to PDF - keeping that information for step 2) DOCX Usage/Printing.

  • I think you would be better off exploring how to make/update .docx files without Word, e.g. Using the Office Open XML SDK. But you'll really need to switch from vbscript or write some vbscript-callable libraries. Have a look for Eric White's Document Builder material for some pointers.
    – user181946
    Feb 5, 2014 at 7:37
  • @bibadia the main issue with sticking with DOCX isn't document editing/updating (I've actually explored updating the current process with OOXML and don't think THAT part would be onerous.). THE issue is printing from inside of a Windows Service (Desired change: GUI to Windows Service). Everything I read says it requires word to be installed on the server and that word doesn't play well as a service (modal dialog errors, requests for user interaction on errors, required user registry entries, etc).
    – WernerCD
    Feb 5, 2014 at 13:56
  • @Werner, You can look into Aspose.Words for .NET which can retain custom document properties when converting DOCX to PDF without using word automation. It is also fully supported in a server scenario.
    – Adam
    Feb 6, 2014 at 12:48

1 Answer 1


Use pdfsharp, it is an open source library. You can set the custom properties of pdf like this:

PdfDocument document = PdfReader.Open("c:\\Test.pdf"); 
     new KeyValuePair<String, PdfItem>("/MyKey", new PdfString("MyValue")));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .