Generating reports using custom data (html table) not dataset - c#

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)

Related

Making PDF file from C# application

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.

C#: How to convert HTML5/CSS3 into PDF document?

It's obvious from the title what I want to do. I know it is possible to convert html to PDF document using a very popular library iTextSharp. But what I acknowledged from this post is iTextSharp cannot render HTML5 and CSS3 styles correctly. Is there any free library to achieve this?
Backgroud:
I am using DevExtreme for report generation. It has supported chart export in PDF but my client wants some extra content in PDF apart from charts. It is not supported by DevExtreme, so I took decision to write my own custom PDF exporter.
There are some libraries available but I cannot rely them since I can't predict in advance what issues will it cause in production in future. Correct me if I am wrong, there is no API given by Microsoft for manipulating PDF files. We can create and manipulate excel and doc files using Microsoft.Office.Interop.Excel.dll and Microsoft.Office.Interop.Word.dll but I didn't find anything for PDF manipulation.
Please suggest me what options I have.
Hope this makes sense..!
A few years back I was using iTextSharp to get our html manuals in xhtml/css/wiki to pdf. It was...painful and a lot of work. So, the first news is: You will need quite a few weeks (2,3,4 weeks, depending on the grade of perfection you want) of time if what you have is not only a few html pages.
If you only have a very limited amount of pages, the quickest and dirtiest way is to make screenshots from your rendered pages and add those images to the pdf. Not very high-tech but quickly done.
If your style sheets can be sacrificed and you do not care about the formatting of the content to be identical, you can convert your html5 pages to xhtml so you can load them as XmlDocuments. Then you simply create a program which does some mapping from xml elements, such as <h1>MyTitle</h1> to some section of code which creates a pdf entity using iTextSharp. Basically that was the way I did it in my case. I also did some mapping from css style classes to some specific pdf formatting, but not to the extreme.
Also worth trying is converters from html (or xml) to tex/latex. If you are lucky you find one which does a good enough job. Then you can use pdftex and get your pdf.
Also, it is possible that you can print your documents to an xps printer and then convert the xps to pdf. Or you simply convince your customer that xps is what they want.

How can I convert my report into pdf without using a gridview (Visual Studio)

I was able to convert gridviews into pdfs but now I want to generate a pdf for my pay slip.
It has a different format because I fixed the layout using an HTML table, and ASP Labels.
How can I convert that into PDF?
If you don't have a built tool for converting to PDF (like teleriks builtin methods for exporting RadGrids to PDF) I'd go for generating the PDF by hand.
Instead of trying to parse the UI into a PDF you can construct the PDF directly from the data source. I've used iTextSharp for composing PDF:s manually. It's a bit clunky but it get the job done. Beware of the license for iTextSharp version > 5 if you have a commercial site.

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/

Categories

Resources