0

Original idea: use a PDF template to create multiple pages after reading a CSV file

I've found that PDF isn't as friendly as I thought
(Especially when I want to code using PHP)

What I want: a pre-formated document with place holders for a few fields of data The look and design of the template document are really important - so I don't want to consider using code libraries and constructing the PDF document from scratch

Now... I've had a lightning bolt of an idea: use a Word format document that is in XML format. If in XML format, surely I just can't go wrong?? If its XML, I can use any scripting language?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118

1 Answers1

0

Good idea for using MS-Word template and then exporting it to pdf. Rather than xml format, you can go about it like this:

  • Create a word template with text,heading,tables etc. and bookmark each with unique name eg. paragraph 1 is bookmarked as 'para1'

  • Create a new .net C# project & include Microsoft.Office.Interop.Word (Google for more)

  • Now in your C# project access those text fields in word file using bookmark names & populate it with Data from database. (See this) It's as simple as:

    Document wordDoc = wordApp.Documents.Open(@"C:\test.docx");
    Bookmark bkm = wordDoc.Bookmarks["para1"];
    Microsoft.Office.Interop.Word.Range rng = bkm.Range;
    rng.Text = "It was never a tough job to automate....";
    
  • Save & close the document(See this) or you can export/print it to pdf (Google it)

pxm
  • 1,611
  • 2
  • 18
  • 34
  • Sounds awesome. Thanks for the reply. I was thinking of using Python. This would allow me to develop web versions + a stand alone that I could turn into an executable and run on Windows and Mac. (I know I can make standalone on Windows, not sure about Mac). – Jonathan Johnson Jun 09 '14 at 19:59
  • Also... I don't want to be reliant on .net, so would want to discount for that reason. I'll look into creating bookmarks though. I'm sure that will help. If I have chosen XML format to be the default format of my documents, then do I still have to create a XML file from Word? Doesn't actually make a difference though - happy to have an XML. – Jonathan Johnson Jun 09 '14 at 20:06
  • Ya no worry you can use xml format and automating with C# was easy for me but you can search for python word automation & see this http://stackoverflow.com/questions/1035183/how-can-i-create-a-word-document-using-python – pxm Jun 11 '14 at 08:21