Create PDF from Merge document via ASP C# - c#

Okay, here is what i want to do..
A user will run a query and return 3 pieces of data (really more but for this example lets say 3.. such as name, city, state).
The user will then be prompted with a list of 1 or more documents that are basically word merge documents. Does not have to be word but needs to be something standard.
Once they pic the document, we need to merge the data with the document and would then like to have a PDF displayed back to the user so they can print or save.
So, looking for ideas on what would be a suggested format to store the merge documents in as well as how to do the merge and create the PDF via ASP C#.
Thanks!

firstly ... stop thinking "doc" as standard cause .. it is not.
PDF is much more standard than doc and using any online viewer it is easy to provide access to it's content
now...
for manipulating PDF files fore free u have a very nice C# Library called iTextSharp

Related

Create a Word document from a template file c#

I am trying to make a word document in an asp.Net MVC application using OpenXML template document .
The main challenges for me are
How can i create a word document as an OpenXML template? In my word
document i have some paragraphs of texts and in every paragraphs i
have to fill information from data base like in word file there are
instances of text like
etc and these should be filled with actual data. But
i dont know how can i convert a normal word document as a OpenXML
template file .
How can i fill the values with data from db ? If i have a model say WordModel in hand with filled values of properties FirstName TotalAmount AmountUnit TotalCopies etc then how can i fill the details to template and allow user to download the file ?
What you want to do is called Mail Merge and means populating word documents that act as templates with your application data. There are some existing (commercial) solutions out there, but if you want to do it yourself using Open XML SDK, you need to set up some kind of tagging mechanism that you will use to tag certain parts of document where you want the data/text from the database should be placed. For Word documents you have the following options: Bookmarks, Content Controls, Merge Fields, or special text (<% FirstName %>). I would personally go with Content Controls as they offer the best user experience and they are pretty easy to parse and replace. So the templates would be ordinary word documents containing these tags and then you could use Open XML SDK to parse these templates, search the tags in them and replace them with your application data according to the tag's name/code/title. This a very abstract, high level picture of a mail merge processor. Of course system like this is not easy to implement and also note that using Open XML requires some learning. There was a similar question answered, but you can probably find many more - just google.

editable word document attachment

Its a general scenario when we provide an option of attaching a file (MS .doc) to end user. This file is stored in DB as binary. When user try to access this attachment next time, we allow them to download it. Now, here I want to give a feature to user where he should be able to open this doc file on click, edit it and save it without downloading.
.doc is a binary format and not easy to work with - a library such as Aspose, as mentioned by Christian, is definitely the way to go.
However, if .DOCX is acceptable (and that's Office 2007 and higher), then you can achieve what you want in three steps:
Convert .docx to HTML
Convert Word to HTML then render HTML on webpage
Display the HTML using any rich text control of your choice
What is the best rich textarea editor for jQuery?
Finally, convert HTML back to .docx:
Convert Html to Docx in c#
You would have to "reinvent" Microsoft Office Online (look into your skydrive account). I am unsure if there are any "out of the box" libraries for that, but you could build a simple editing app by leveraging Aspose word (or some other library). But that would be far from simple.
Link to aspose: http://www.aspose.com/.net/word-component.aspx
Word will only open files that are locally stored. What you are looking for is something similar to editing items that SharePoint provides using the WebDAV interface.
You may be able to use this approach to support your requirement. You should be cautious about the security aspects of the solution unless you have fully authenticated access to the shared folder on the server.
I am not sure if a standalone MS Word Document editor exists. However, this can be done with using a combination of rich text formatting / converting tool (for example, the DevExpress ASPxHtmlEditor + Document Server):
Load binary data from a DB;
Import loaded data (MS Word content) as HTML content into the ASPxHtmlEditor;
Edit imported data via the WYSIWYG ASPxHtmlEditor;
Convert the edited HTML back to MS Word content;
Save the converted / edited MS Word content back to the DB.
I believe, it is possible to do something like this if you have such products (free or commercial analogs) in your project.

Search and Replace PDF using Itext

I need to generate a PDF based on some user inputs. The output PDF have some images, tables and texts. I think that Itext is not user friendly for programmatically generate this report.
Since the report I need to generate is quite complicated, I was wondering if it is possible to create a template PDF and then load -> search -> replace the strings/images I want.
The template PDF can be a tagged pdf.
Is it possible to do that?
Is it the best approach?
EDIT: I´m using WPF + MVVM + .Net 3.5
Replacing text within a PDF file is not simple. The PDF fileformat uses a dictionary at the file end where elements are listet with their byte offset within the file, also some elements have a field where they give their own length given in bytes. If these offsets are not met, the reader will probably report a broken pdf.
You should have a look at reporting as it is made for these tasks:
http://msdn.microsoft.com/en-us/library/bb885185%28v=vs.100%29.aspx
You can create a template with the report designer, set your data and export it to pdf.

What's the best way to generate a file and print it in .net?

I am working in a desktop project in C# with .net. This project has a function that generates some information and i would like to print this generated info as a document (may be .doc, .pdf, etc). Summarizing, i need:
Get the data generated by a function;
Generate a document containing these information structured with title, texts and tables (things that every document have);
Print it;
I thought generating an .html file (because it's simple to generate this kind of file), but i couldn't find a way to print it directly from my program.
Which extension of file would you recommend to insert this kind of information and print it directly from my program??
Thanks in advance.
Here's an easy way that uses a RichTextBox
http://www.codeproject.com/KB/printing/simpleprintingcs.aspx
It's not trivial to print a PDF, HTML, or a doc unless you are going to use external programs or third-party libraries. ImageMagick/GhostScript could help you print PDF.
Disclaimer: I work at Atalasoft -- If you are willing to use commercial software, my company makes PDF rendering components for .NET. There are companies that do the same for HTML.
Directly? Open printer port...
Or you can do it with framework classes:
How to: Print with a WebBrowser Control
http://msdn.microsoft.com/en-us/library/b0wes9a3.aspx

Generate PDF document based on Word document

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,
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
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.

Categories