Programmatically Generate PDF Report with design - c#

The background right now is that I coded website for the client and as part of the website I have a service calling a webpage every 5-10 minutes to generate some PDFS that become available on the website. The PDFs just contain a data dump of a table that is displayed on the website.
The new requirements are to add a cover page and apply a color scheme to the PDF report which replicates the view on the website.
I'm unsure how to go about this using C# and VS2008 with the backend database being MySQL. I originally thought about creating a report and then somehow programmatically rendering and saving it as a PDF, but because we are using MySQL that throws out the possibility of using Sql Server Reporting Services. Is there any other open source and/or free solution that will allow me to create and design the report and then programmatically create and save as a pdf without any user interaction?

Your best bet is iText here. It supports creating pdf programmatically in java or C#. We use it where I work to do just this thing (also using MySQL on the backend). I also recommend buying the book. It has lots of good examples, and if you purchase the book, you get a pdf version of the book.

Try TCPDF. Though written in PHP, it has no external dependencies, has plenty of options and examples included. Works fast and reliable, no problems with fonts, etc.

jsreport supports exactly this kind of pdf generation. You first create a report layout and dynamic structure using html, css and javascript templating engines. Then you just send the data and invoke the rendering using c# classes.
This blog post should give you more info how to do it.
Disclaimer: I am the author of jsreport.

Related

Creating a complicated PDF in C#/MVC

This is .NET 4.6/MVC 5. I'm trying to create a rather complicated PDF in C#, but I can't quite figure out a good way to do so.
We use Kendo UI and it has PDF export capabilities (demos), but that requires creating a print layout with HTML/CSS. I was unable to figure out how to use #page with images in the header/footer.
We've used iTextSharp in the past, but it now requires a very expensive license for commercial use.
PDFsharp and MigraDoc (API) look nice, but they have almost no documentation and I've been unable to figure out how to use them.
How can I accomplish the task of creating a PDF in the format of the below screenshot? I don't need to be spoonfed, just given a general idea. I have no preference for or against any specific method, I just don't know what would work well.
This is the layout I'm attempting to create. The green lines separate the header/body/footer. The header and footer are the same on all pages. The table in the body will display data from a list--it needs to display only what can fit on a page, then move to the next page and the next items in the list.
Essential PDF can create complex PDFs with any custom layout. You can also create a template in Word and convert into PDF with your data merged in.
The entire product is available for free and can be used in commercial applications also (if the organization makes less than 1 million USD in annual revenue) through the community license.

Asp.net webform to pdf

I have a simple asp.net registration form where users fill out the information to register. I have it captured in an oracle database.
Is there a way i can generate a pdf from the data in the database and show it like a actual pdf form?
I looked at itextsharp and it has some licensing restrictions. What are some of the other free solutions that stackoverflow users has used that will help my problem?
Thanks
itextsharp is free to use for non-commercial development, but if you use for commercial development then you either need to obtain a license or make your code available under the GPL license.
Here are some alternatives to itextsharp:
PDFSharp is a free option, however its latest release is from 2009.
There is an open-source version of PDFjet.
PDF Clown
You can get the form with contents as PDF, by using the service pdfmyform.com - this is a commercial service that lets you convert the whole webpage including form contents in one go to a PDF, without any development. There's a free plan for limited use.

Visualise map data in Excel

I have postcode level data in an Excel workbook and ideally I would like to have a map on another sheet of the area that I am interested in. The postcodes in my dataset should be highlighted within that map. I am using Excel 2010 and have no prior experience with GIS but plenty of experience with C#, Java. Any ideas of how I can achieve this? I looked for open source add-ins and didn't find an awful lot. Is there another way I can achieve what I want?
I use Topo.ly. You can just copy all your post codes from Excel and paste them in Topo.ly, and it will plot them on Google Maps. It also hosts your maps, so you can save it and come back to it later, or share it with others.
You can take a look to that solution for non-gis-users:
http://www.esri.com/software/esri-maps-for-office
It requires Office 2010 (that's no problem in your case) and it is based on a privative GIS software (no FLOSS). On the videos section there are some examples.
This can be a good starting point. You will need some knowledge of WPF
Bing Maps Windows Presentation Foundation (WPF) Control, Version 1.0
Then using VSTO you can integrate it into Excel
Using WPF Controls in Office Solutions
Sample WPF application is # Integrating Bing Maps With WPF
Edit :
Didnt find much on non WPF solution but you can give this a try
Integrating Virtual Earth Maps and Excel 2007 Using Visual Studio 2005 Tools for Office Second Edition
Download here http://archive.msdn.microsoft.com/VSTOVirtualEarthXL
For future reference or someone who has similar porblem, you can use an Excel add-in called Funfun to create data map in Excel 2016. I made two examples here.
As you could see, there is some code in the middle section of the screenshot. That is because Funfun allows you to write and run JavaScript code directly in Excel, also, the JavaScript code could use the data stored in the sheet. The capability of using JavaScript means that you could use 3rd party libraries like HighCharts.js or D3.js to plot charts like data map. In those two examples, I actually used highmaps which is part of the HighCharts.js library. The highmaps.js already has different templates from world map to specific map of different countries. I believe you could find the map you need.
Funfun also has an online editor in which you could test your JavaScript code with you data. You could check the detailed code of the examples above on the link below.
https://www.funfun.io/1/#/edit/5a5c9a50404f66229bda3ae0
https://www.funfun.io/1/#/edit/5925036104ce702ccfb22b0e
If you are satisfied with the result you achieved in the online editor, you could easily load the result into you Excel using the URL above. Of couse first you need to insert the Funfun add-in from Insert - My add-ins. Here are some screenshots showing how you could do this.
Disclosure: I'm a developer of Funfun

A Silverlight reporting solution where silverlight tables can be scheduled to be delivered as pdf/excel

first of all let me give you the context. I've been asked to create a Silverlight reporting application which allows users to view tables/charts of data and then schedule these controls to be emailed (in pdf or excel format) at a later date when new data becomes available.
I have written an application to do this using webforms for a previous company, essentially the report generation was triggered via a service which executed the web application pages and i was able to generate pdfs from the html strings, however my new company would like a silverlight app and I'm not so sure whether it's possible.
I DO KNOW: That I can use WriteableBitmap to render an image of a report control (ok for PDF), for excel I can use the export to excel functions on various grids.
Questions:
Can I talk to a silverlight app from a windows service and execute methods on the app including rendering controls? (I have a feeling that the client side nature of silverlight may stop me doing this).
If i can execute methods, then i assume that i will be able to intercept an export to excel stream and create an attachment with the excel mime type (if not already set)?
Please don't hit me with "why don't you just use Reporting Services" argument.
I'd be grateful for any comments and guidance.
I think you may try ActiveReports to accomplish the task you are looking for . ActiveReports does come with a SilverLight report viewer,Windows Forms Viewer and a Web based viewer. ActiveReports also has the ability to create charts and lets you add custom controls to the report.About exporting capabilities ,yes ActiveReports lets you export reports to PDF,Excel,Tiff,RTF,Html etc even on the SilverLight environment.
You can find some information regarding this here:
http://blogs.gcpowertools.co.in/2012/05/exporting-reports-using-active-reports.html

Easiest way to create dynamic-content documents (like invoices, delivery notes)

I was searching the web with a few results, but none of them seems to fit the task. I was looking für possibilites for .NET, but would also like to know how Java/PHP/etc. developers finish tasks like this.
As far as I found out, I have the option to:
Use MigraDoc/PDFSharp and go the "code" way, without any visual designer
I could use HTML and convert it to a PDF (which is the best approach in theory, but practically it's awful to get good looking HTML 1:1 into a PDF file)
I could use some weird MS Word templateing/batch stuff
LaTeX?
What are your solutions?
We use SoftArtisans OfficeWriter
A solution that we settled on in a previous project was XSL-FO. Although it did not have a visual designer, we found it to be very developer friendly and more suitable to run in a server type environment. It also deals with document "flow" a lot better than most of the reporting software that offer a designer. I do know that we had a lot of trouble with Crystal Reports around deployment, COM exceptions being thrown and limitations on how many reports can be generated concurrently. One downside to using XSL-FO is all the syntactic sugar that comes with XML.
This question lists a few XSL-FO engines.
Regarding your "3.) weird MS Word templateing/batch stuff":
I love to use Aspose.Words, a commercial package to create/edit/export Microsoft Office Word documents, without any Office components being installed.
Aspose.Words is capable of doing Mail Merge stuff and write PDF files, so I often start on my desktop computer with a DOC that I edit in Word and use this with Aspose.Words on my server to produce PDFs.
One method I've used before for Windows desktop applications is to use XAML/WPF. The nice thing about this solution is that there are a lot of good tools and documentation around building layouts with XAML. Then you just pass the canvas to a PrintDialog and you're done. If you've been doing a lot with WPF/XAML already this is a very easy solution and I've had a lot of success with it. I learned most of what I needed to get started here: http://www.switchonthecode.com/tutorials/printing-in-wpf
The downside, of course, is your dependency then on .NET and WPF.
Similar to Matt Fs solution of using Crystal Reports, I use SQL Server Reporting Services. You can create add a rdlc file to your solution and use the WYSIWYG editor to design your report. Then in your code, all you have to do it assign your data source to your report in code and it should work. This even supports exporting to PDF.
Seems as no-one has mentioned Latex-based solutions, there was a stack overflow Tex question answered by jason. Short version: uses MikTex, beautiful documents, big hassle to use build/maintain.
Thanks for all your answers...
I finally decided to implement my own solution using Visual Studio 2010 and the Office-Tools... This is not the "perfect" solution, but it was easy & fast to implement, while i still have the flexibility to change the documents witch excel or word...
Downside of course: You need Office installed.
It depends on how you get your template documents. For example, if you have others in your organization responsible for generating the "standard" invoice document, you'll probably have a solution that involves mail merges in the Microsoft Word API, because you need to work with Word-formatted input files. Alternately, if you are merely given the specs for the appearance of the document ("Logo in the top-right, 5 inches down, then a horizontal line two inches below that, then... etc.") You could do it entirely in code. Even if you're designing a solution from scratch, take into account who your document suppliers WILL be, and plan accordingly. Finally, if this is from-scratch for a small set of documents that won't change much (i.e., you're starting your own software company and want to send invoices) don't do it. Just buy something off the shelf or use Word :)
We use xaml FixedPage, can use a designer like Kazaml, it has a lot of layout flexablity, and databinding works great with dynamic objects like expando. In code we bind a datacontext and then render that to XPS, since we need the final output to be pdf we use GhostXPS which is free but has to be executed in a separate processs, there are third party fully managed converters for xps to pdf though.
We use Crystal Reports which comes free with Visual Studio. You can easily create a report/document that is bound to a database or unbound.
For example you could suppress the header and footer, expand the details section to be approx. A4 size, then add either bound fields or use parameters for unbound content. Then at runtime for bound documents set the selection formula to only pull in data for one transaction or for unbound documents just pass in the parameters.
A nice feature of Crystal Reports is there are export features, so export to PDF, Word, etc. Also it's easy to auto print to a specified printer.
Crystal reports can be a pain! On a basic level the outsourced developers for our in house software for Works Order, Invoices etc we use Dev Express although I think it can be pricey.
For reports being generated by the software I ended up choosing to have exports into a raw CSV which of course can be opened up by any spreadsheet software

Categories

Resources