views:

106

answers:

2

Hello,

I’d like in an ASP.NET MVC application generate document (invoice for example) based on a word document than I use as template. I create a word document with :

Some fix data :

  • Company info
  • Logo
  • general layout

Some data to add in a specific place :

  • Invoice number
  • A section with a table, with some column (price, quantity, description, vat, …)
  • In the bottom the total with and without VAT
  • A date

In this document, I can create a kind of tag, example <PDF:InvoiceNumber> and replace it by the value by code, same for all the other "TAG"

Do you have an idea how I can do this? Did you experiment another way (suggestions are welcome)? I accept to use 3rd control free or commercial. The only restriction is … I don’t want install Microsoft Word on the server.

Thanks,

+1  A: 

Use the OSS .net port of iText, iTextSharp (google or bing for it).

General process: 1) Create a PDF file of your existing Word Doc

2) Using Acrobat (or similar tool) add PDF form fields to the file as placeholders for the data you will insert into the form at run-time

3) Using iTextSharp 's PDF form-filling API, insert the data into the form-fields in the PDF

4) Save, print, return-as-stream-to-client's-browser-with-PDF-mime-type, etc. the resulting PDF

sbohlen
That mean, the customer must have Acrobat Pro right ?
Kris-I
To do exactly as I suggest, yes, but as an alt. approach you could also create the *entire* PDF from scratch using iTextSharp (but its just a lot more work to do it that way)
sbohlen
A: 

I realise you don't want to install MS-Word on the server, but you could consider installing it on a separate machine and then consider the approach in this article. It uses Web Services and is clean and efficient.

I wrote this article so the usual disclaimers apply.

Muhimbi