From time to time we all need to print a document from our .NET programs. Let's say a simple one page document with some text and image.
So far I know 2 ways to do it:
Using standard PrintDocument class
Generate a pdf/doc document using such tool like PdfSharp
First way I don't like because it takes a lot of time to write all these routines for handling events and standard PrintPreviewDialog is just ugly. Beside that you need to generate and scale 2 different documents on print preview and actual printing.
Second way bothers me because these free components quite often are limited and poorly documented.
What other solutions for printing do you know?
use Crystal Reports for printing. Best Option IMO
I haven't seen an elegant printing solution in .NET yet, except for WPF and XPS. In that case, you can just create a UI in Xaml and print it. But XPS isn't often a viable option. I've worked with XSL-FO also (using NFop and later FO.Net - the latter is better because newer and it doesn't require Visual J#), which works but has a moderately steep learning curve.
I have tried to analyze possible options in the article pdf reports in c#.
iTextSharp - imperative way of doing reports in c#, (-) produce not very readable code
Telerik Reporting, DevExpress reporting, Crystal Reports - similar approach, report editor, great for simple job, able to produce multiple formats, (-) harder to team merge and print complex reports
phantomjs, wkhtmltopdf - html to pdf conversion, (-) extra dependency
jsreport - my solution, javascript templating engines to assemble html report and phantomjs to print it into pdf (-) overhead for simple solutions, extra dependency
Long story short. I was not satisfied with the current options and developed jsreport as a solution for designing and printing pdf reports. Check it out, it's free.
Related
I have a project where I need to create an HTML form (no problem) and then create a PDF file from the results using C#.
I have done this before in PHP using FPDF but this one needs to be C#. Ideally I want to put the code into a user control and then stick it in an Umbraco website.
Can anyone recommend a good way to do this? PDF doesn't need to be fancy, it'll just display text, we aim to create a generic purchase order based on what the customer wants from the form, which can then be emailed to them to print off on headed paper.
Thanks
There are a couple of recent problems with iTextSharp. The most annoying is that in the latest version they've deprecated the HTML parser. So now everything has to work through the XMLWorkerHelper singleton and parses through ParseXHtml. I find this a real pain, since HTML pages which aren't well formed appear fine on browser, parse OK in the old method and now crash out with an exception. So it necessitates an extra step to make sure your HTML is well formed (as XHTML) first. If you are generating your HTML from an ASPX page, then using Server.Execute() to get the stream, then this might be useful to you for iTextSharp:
http://jwcooney.com/2012/12/30/generate-a-pdf-from-an-asp-net-web-page-using-the-itextsharp-xmlworker-namespace/
Be mindful that iTextSharp has a distinct lack of any decent documentation of the modern changes (being mindful that the Java iText documents don't translate perfectly to C#), it makes the learning curve far too long and steep for any practical use in short spaces of time. I've basically given up on that platform, though may just create a baseline system to get something working lean whilst I then learn another framework.
As a result, I'm looking at PDFizer and PDFSharp libraries. If I have some success, I'll report back.
here is a library for converting HTML to PDF
http://pdfcrowd.com/web-html-to-pdf-net/
I like the PDFsharp library. Not sure how it would work for your needs, though.
We are using Report Definition laguage (RDL) templates to define various reports in one of our Sharepoint applications. These reports are (then) saved as PDFs into various SharePoint Document Library's. One report in-particular renders, but is considered to be "failing" due to the styling needs of the report. So it appears RDL only understand "very simple" HTML.
For Example:
Trademark characters are not rendering as superscript (they render as normal text instead)
The ability to assign Line Height fails
The ability to assign Word Spacing fails (so printers "leading" requirements fail)
Both of these point to various marked Microsoft limitation for RDL's to interprint various HTML...of which we are now aware.
So...
I need a better tool...and we are scratching our heads on this one!
QUESTION:
What tools take-in HTML, understand CSS (well!) and can generate PDFs from C-Sharp objects?
Please keep in-mind I need the to PDF generator tools you recommend (below) to understand CSS and HTML.
NOTE:
I looked at the various other StackEchange sites to see if there is a better forum for this particular question, but this one was the only one that seemed to fit-the-bill. If you are a mediator, and feel this question is mis-placed, please feel free to move this question.
This HTML to PDF converter has the most accurate conversion of a complex html/css page. There is also a demo to try the conversion with your html
Maybe you can give Amyuni WebkitPDF a try. It is a Free component for converting HTML+CSS into PDF files. From the home page:
Directly convert HTML files into PDF without the use of a web browser or a printer driver
Convert HTML files into XAML/XPS for rendering within Silverlight
Integrate and deploy the HTML conversion feature within your applications
Generate either a single continuous PDF page or split the HTML into multiple PDF pages
Amyuni WebkitPDF is distributed as a library with a sample application, and sample code for C++ and C#.
Disclaimer: I currently work as software developer at Amyuni Technologies.
I only know a workaround for the "leading space" issue. This example "leads" the value with 10 spaces:
=space(10) & Fields!FieldName.Value
This should work for any renderer, I'll update this if I come around other tricks.
Have a look at Aspose.Pdf for .NET: http://www.aspose.com/categories/.net-components/aspose.pdf-for-.net/default.aspx
Is there a way to programmatically create PowerPoint presentations? If possible, I'd like to use C# and create PowerPoint 2003 presentations.
Yes, you can.
You will want to look into MSDN which has a pretty good introduction to it.
I might give you a word of warning, Microsoft Office interop is compatible with an API which is now more than 10 years old. Because of this, it is downright nasty to use sometimes. If you have the money to invest in a good book or two, I think it would be money well spent.
Here's a starting point for you. Use the search feature on MSDN MSDN Webpage. It's good for any Microsoft C# .NET style stuff.
Specifically in regards to your question, this link should help: Automate PowerPoint from C#. EDIT LINK NOW DEAD :(. These two links are fairly close to the original KB article:
Automate Powerpoint from C# 1/2
Automate Powerpoint from C# 2/2
Finally, to whoever downvoted this: We were all learning one day, how to do something as a beginner is most definitely programming related, regardless of how new someone might be.
OpenXML looks like the way to go from a web app.
Using the interop libraries is not recommended, as others have stated.
You can also look at Aspose Slides, a component for .NET and Java that makes it easy to generate powerpoint documents.
If you don't really need PowerPoint compatible output, consider using a markup language such as LaTeX with the Beamer package to produce a PDF of the presentation, or use HTML and javascript in a manner similar to Slidy. If you need fancy effects, it might still be easier to use SVG, and you'd have the benefit of getting output that can be reliably viewed with free software.
http://msdn.microsoft.com/hi-in/magazine/cc163471(en-us).aspx
Use this link. Although this is in VB.NET, C# supports the same.
You may also try out SlideMight, a tool for merging hierarchical data with PowerPoint templates.
SlideMight supports:
text substitution in text fields, tables and notes
image substitution, from raw data, files and URLs
images in tables nested
iterations over data to create slides
iterations to populate tables, possibly spanning multiple slides
special formatting for specific cell values
hyperlinks to generated slides
Input data format is at this time just JSON.
There are versions for Windows and Mac OS X.
More information is at http://www.SlideMight.com
Disclaimer:
I am the owner of Delftware Technology, the company that developed SlideMight.
And I am one of the developers.
You can use Essential Presentation product from Syncfusion Software Private Limited. This product can be used to
Create and manipulate PowerPoint presentations
Open, modify, and save existing PowerPoint presentations
Convert PowerPoint presentations to PDF or Image
More information is at https://help.syncfusion.com/file-formats/presentation/overview
Disclaimer:
I work for Syncfusion Software Private Limited
I need to generate a high quality report based on information in a SQL Server database, and I want very explicit control of the layout and appearance from inside C#.
I have several choices that I know of that are already being used for various other reports at our company:
1) SQL Server's built in Reporting Services
2) Adobe Forms
3) Crystal Reports
This information I need as PDF directly parallels what is already being displayed in the user's web browser as HTML, so creating a print stylesheet and converting the browser body to PDF is an option as well.
So this creates option 4:
4) JavaScript convert HTML to PDF (my preference at this time)
Does anybody have a recommendation as to which approach I should take, or even better an alternative? All the choices seem pretty horrible.
I've used iTextSharp with very good results. It is an open-source .NET port of a java library. It works really well for creating PDFs from scratch. Remember that editing PDFs will always be hacky with any library, because PDF is an output format, not a read-write format.
Provided your HTML is fairly clean (remove javascript postbacks, anchors, ...),the iText HtmlWorker can convert HTML to PDF, if you prefer that route.
HTML to PDF in using iTextSharp:
Document doc = new Document(PageSize.A4);
HTMLWorker parser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc, Response.OutputStream);
Also here.
Use SSRS, it has a built in PDF rendering mode.
I have used two other PDF report libraries with great success; Active Reports and Telerik Reporting. Personally I prefer the latter when it comes to programmatic control of layout and such.
Take a look also at the DevExpress Reporting (non-free 3rd party tool):
Overview
Online Demos
Documentation
Yes, you should use the best tools to get the best solution. The best tool in this case probably is SSRS.
But that's just looking at the capabilities of the tool.
Don't forget to look at your own capabilities!
My story: I know SQL, I know C#. (Both intermediate, I'm not a guru.)
Then I lay my hands on SSRS. And burnt them, once, twice, etc.
At the end, there was a nice result. So burning your fingers is not a wrong thing to do.
But first try to pull your html through an html to pdf converter (demo version) and see if the result it serves your needs.
Currently I'm using both:
SSRS for creating invoices, because amounts have to be transported from one page to the next
Winnovative to generate documents that only need page numbers
I would suggest using .Net ReportViewer control in local mode (no report server required). It works in both webforms and winforms. You create a client-side report (.rdlc) file (which contains all the visuals as well as placement of data fields), link it up to the ReportViewer, and supply the data (DataTable or collection of objects, as long as the fields match, it doesn't matter). In client mode it supports exporting to pdf and excel (and Word too? don't remember). By default these done by a dropdown in the control itself however you can programmatically export to any of the supported formats as well. You'll end up with a byte array you can shove into a file stream.
Basically you get most of the good parts of SSRS without all of that backend complexity. There should be a ReportViewer folder in %programFiles%\Microsoft Visual Studio 10.0\ReportViewer - but versions exist for 2005 and 2008 as well. Check out http://gotreportviewer.com/
I think the 4th option is the best. In this case you don't need to change either layout of the HTML page or a layout of PDF, if one of them has been changed.
It is also more convenient making a nice design via HTML than programmatically via C# :)
Take a look at WebToPDF.NET which is a .NET component written in C# that converts HTML to PDF. The converter supports HTML 4.01, XHTML 1.0, XHTML 1.1 and CSS 2.1 including page breaks, forms and links. It passes all W3C tests (except BIDI).
You can use Fast Report it's good tool and i has a free version
Well, heres my scenario.
Client/Server winforms application with SQL Express as the DB. I need to be able to print invoice, packing slips etc..
i would like the customer to be able to modify the invoices. ie. be able to put their logo or change font sizes etc...basically format the display.
Things i have considered so far are.
1) Use a template engine (similar to codesmith or mygeneration) and use templates that output HTML. Then print the html page.
2) Use ReportViewer in local mode. I've heard that users can download a plugin for web dev express and edit the local report files. can anyone confirm this?
3) Use Reportviewer in remote mode.
I don't have much experience with ReportViewer so I'm not sure if i should use local or remote mode as well.
Those of you that have done this kind of thing before whats your recommendation?
After just completing a project with it, I would heartily recommend iTextSharp to create your invoices and other forms as PDFs. In addition to creating PDFs from scratch, you can also use it to fill in PDF forms and/or templates created with Acrobat (or even MS Office/OpenOffice). And it's free.
It's pretty easy to use in Windows apps or in ASP.Net applications. Most of the documentation and the books on it (iText in Action, for example) are about the original Java version, iText. However, there are tutorials and example code on the conversion process and, for the most part, all of the functions and libraries work the same in the .Net version, so adapting the book and reference code has been no problem.
I definitely learned the hard way that HTML and CSS are great for browsers (well, great except for the "every browser interprets it different" problem), but horrible for trying to generate consistent, attractive, and precise printed output and forms.
I'm personally using Aspose Words: they use word documents as templates, and I'm using Words bookmarks function to mark and retrieve the fields I need to fill.
Aspose works nicely with Tables (ie: you can add lines to a table, etc...) and sees Word documents as XML documents. You can then save the document as MSWord or PDF.
I wouldn't say it's the greatest library in the world, but it's definitely worth having a look :)
you can use Crystal Report for this. But first you need to scan the INVOICE and save it as an image,
Next is, on your crystal report, export the image on to it, and DRAG the fields to where they must print on the invoice (IMAGE SERVES AS YOUR GUIDE). Then after everything has been set-up, DELETE THE IMAGE and try it.
hope this helps.