Making PDF file from C# application - c#

How do I make a PDF with C# application?
I would like to make an application which creates a PDF document, but it could be Excel too.
I wish to make a file which contains tables and header.

You could use ITextSharp to create your PDF file.
And this post to help you with Excel.

Take a look at PDFFlow library for generation of PDF in C#. It has features that you need: tables, multi-page spread tables, repeating areas (headers, footers, left, right), table repeating headers... and even more unique features (like automatic page creation, multi-level list, word-like tabulation, barcodes/QR codes, etc...) and easy fluent syntax:
var DocumentBuilder.New()
.AddSection()
.AddParagraph("Hello World!").SetFontColor(Color.Red)
.ToSection()
.AddImageToSection("Smile.png")
.AddTable()
.AddColumnToTable("Column1").AddColumnToTable("Column2")
.AddRow().AddCellToRow("Row1, Cell1").AddCell("Row1, Cell 2")
.ToTable()
.AddRow().AddCellToRow("Row2, Cell1").AddCell("Row2, Cell 2")
.ToDocument()
.Build("Result.pdf");
This is first pages of my business document with multi-page spread table and repeating headers, which I created using this library:
There are examples with source code and explanation, I found them very useful: examples.
Hope, this will help.

Related

Headers lose styles after merging documents with Xceed Docx

Let me explain my scenario.
I am making use of Xceed Docx library to merge and manipulate word documents.
I have multiple templates that needs to be merged to form one customer facing document.
All of them having individual document headers, tables and images.
As per business requirements, we need to make use of content controls as there will be manual intervention.
PROBLEM:
All goes well and the merge works as expected, but it seems to drop the styling of the headers in merged document. But this only occurs when I include CONTENT CONTROLS (rich text content control)!
For example: Header 1, Header 2 becomes normal text....
Has anyone experienced anything similar with this library?
Is there something I am doing wrong or missing?
I did try and contact the developers of DocX, with no avail.
I tried merging the files with OpenXml using AltChunk.
This did work but not to the extend that I required.
Let me explain.
AltChunk inserts the entire file (doc2.docx) into the base file(doc1.docx)
and then only add reference of doc2 inside doc1's XML file.
Hope that makes sense.
MS Word can open this file, but when I want to make changes using DocX it is unable to load the file.
I ended up using Docx for all the document manipulation and OpenXmlPowerTools to merge the documents.
OpenXmlPowerTools seems to resolve the above mentioned issue as its does seem to do a complete image, chart and text merge.
I hope this helps someone in the near future ;-P

itext create pdf based on existing one with changed content

I got quite complicated ready pdf file. It has got barcode and fancy looking table.
I have to create based on it application which will generate pdfs that will look the same but contain different records in the table and different barcode.
Is it possible to copy existing pdf and just change content of barcode and table ?
What would be the best approach to create the same looking pdf but with different content ?
Whank You very much for help
If the barcode and table are static I would open it in photoshop or illustrator delete everything I dont want, Then save it as a pdf again. Then follow this guide iText - add content to existing PDF file and use it as a template to put my custom content in.
If the table and bar code are dynamically generated (each one is different) and you need to crop out content on the fly I would pull some hacky crap and draw white squares over all the content I want gone. then proceed to use it as a template.
Just my 2 cents given the information provided.

Generate PDF based on a Word document for each data item

There're a data list with hundreds of data items (suppose each item is a customer), and a predefined word document as template, the requirement is - for each data item, fill corresponding data into template fields, and generate a readonly PDF file as result.
Prefered platform is ASP.NET with C#.
I found two solutions:
Change the word document into a PDF form, and use iTextSharp to fill the form fields. But create the PDF form with correct format (font, layout, etc.) is a difficult work, and it needs particular tool and new skill when system user wants to add new template (unless the PDF form is always created by developer).
Add text placeholder in the word file, and the program can read word file, replace text, and convert into PDF. But I'm not sure which components should be used.
I'd like to get some advices on this problem. tks.
Update 20130416:
After some searching & experiments, my conclusion is below:
Client solution: use Microsoft.Office.Interop.Word (Office2007+plugin or Office2012) to read data, convert to pdf, etc. But this method running on server side may be unsafe.
Server solution:
Make PDF form, and use iTextSharp to fill the form fields. The disadvantage has been mentioned above.
Make HTML template, and replace field placeholders, and use iTextSharp+XMLWorker to convert HTML to PDF. The difficulty is create the HTML template manually and optimize the PDF effect.
MS SharePoint Office Automation Service is a server solution based on MS Office, perhaps this method will be easier, but it needs license and SharePoint server cost.
Finally, I chose the HTML template solution for this request. QED.
Another option would be to use Tx Text Control for ASP.NET. They have a
mailmerge feature that allows you to fill data into a word template.
The merged document can easily be saved as a pdf.
For the second option you can use iTextsharp or Aspose which supports the placeholder replacement and generation PDF, it supports creating files based on templates of MSWord and Openoffice which could be usefull for user who do not want to buy MSWord only to create a template.
Another option, you can use nustache templates, fill them with list data and then use xmlworker from ItextSharp to render to pdf.

How to recognize tables inside a pdf file

I want to recognize tables inside a pdf files. What SDK is used in C# to recognize tables inside pdfs and some mechanism to read cell by cell, can any one please suggest?
PDF Sharp is good and its free. I've never done this in specific but it does correlate to all the major objects in the PDF format.
Tables do not exist inside a PDF as a structure unless it was created as Marked content with additional tagging in it. I wrote a blog post explaining some of the issues with text extraction from PDF files at http://www.jpedal.org/PDFblog/2009/04/pdf-text/

Generating reports using custom data (html table) not dataset

I read several articles on this site and many others recommending report generating tools of various kinds but all use dataset as there datasource.
This is not my requirement!
I need some way to export the data which is displayed in the htmltable on mypage.aspx.
user clicks view record
a pdf opens (it should contain the data of the html table which is made dynamically)
I want to generate a pdf on the fly using a htmltable as a source of data and displaying it a a pdf doc in the browser but not having to save the result to the webserver.
You may take a look at iTextSharp and here's a tutorial on how to get started. There's also a section in the documentation which illustrates how to create tables in PDF documents.
Check out this thread regarding abcPDF. What you are describing is very similar to what I have used their library for. When I was originally testing out various methods, I had tried iTextSharp but found for the very minimal cost, abcPDF did everything that I required (sepcifically HTML to PDF generation) with minimal lines of code.
Generation PDF from HTML (component for .NET)

Categories

Resources