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.
Related
First of all I want to say hi to the programming community, what I am looking for is a way to generate a report from my Windows Forms Application in word preferably, this report is basically a list of pre-configured days in a tour creation software I am creating.
I have searched everywhere and I cant seem to find information on how to start creating the report, I have all the information saved into a database, I just need to be able to get this information into word and ordered as it should be ordered.
I just want to be pointed in the right direction so I can research on it even further.
The exact thing I want to create is a word file that I wish I could share here so you can actually see what I mean.
Thank you for all your attention and help if possible.
I can point you in the right direction. Word documents are stored in a format called OpenXml which can be created and manipulated without actually using Word directly. That's good because you don't want to deal with code that actually starts an instance of Word and automates it (Interop.) It sort of works but it's not something I recommend dealing with ever.
OpenXml isn't fun either, but it's better. You can create your document "normally" using Word, save it, and then have your application use it as a template, opening a copy, populating some data, and then saving it.
Here's the reference for OpenXml with Word. I'm not saying it's pretty. It's not. The documentation is lacking. This page on adding text isn't linked from the previous page, even though many other topics are.
There are some nuget packages like this one that can help.
I once did a POC that did exactly what you're describing by opening and altering a document used a template using OpenXml. I'll see if I can dig up the code. But this is definitely a good direction to look in if Word is an absolute requirement.
This is a long shot, but can you output in HTML? If you can that's an even easier alternative.
Can you use Excel? That's also OpenXml but there's easier-to-use tools like EPPlus that simplify dealing with it, because it's not just the friendliest thing to work with.
An option that I would suggest is Crystal Reports. You can download the Crystal Reports add-in for Visual Studio for free from here. Crystal Reports is an easy way to perform reporting from various data sources including SQL. There are also a lot of free tutorials online for learning how to use CR. The syntax is a little strange, but it is easy enough to use.
The add-in allows you to create reports for your application and also build applications that can display, print, and export Crystal Reports.
You can export reports to .RTF (Rich Text Format) files. MS Word can open, edit, and convert RTF documents. It does a fairly decent job, but special formatting might take some work. This route is a ton easier than trying to write XML or anything else. I've written several reports designed for export to RTF. My boss runs the report, exports it, then edits it in Word. He loves the reports.
If you are planning on developing a lot of reports, purchasing the full version of Crystal Reports is well worth it. I believe they are on version 2016 currently.
If you do want to deal with automating Word, Microsoft's guide "Automating Applications Using the Office Object Model" Word-specific task content is here: https://msdn.microsoft.com/en-us/library/78whx7s6(v=vs.80).aspx
A larger example: https://support.microsoft.com/en-us/kb/316384
To begin, simply add an assembly reference to your project file for the correct Office Object Library (example: "Microsoft Word ##.0 Object Library"). Note that you must have Office installed to take this approach.
Good luck!
I'm comfortable generating Word documents using Aspose.Word (which can also save as a PDF) but I've recently been asked to do the same thing using a PDF as the starter template. We recently bought Aspose.Total and whilst Aspose.Pdf looks like it can do some manipulations it doesn't look to be all that flexible/easy (like adding a big line of text and getting it to wrap, and shifting other content down the page if it takes up more space).
What would be the best way of using a PDF as a template for what is basically a bit like a mail merge from a database? Should I turn it into a PDF form and merge it from an XML data source? Is this even viable or would such a form still have a limitation on spacing (so that longer lines/paragraphs of text won't reflow the document where necessary)?
From what I can tell it doesn't look like InDesign can be manipulated in c# even via a COM object (which would be nasty on a web server anyway).
If I recreated the InDesign/PDF as a Word document I'm sure I could work wonders, but you know what these publishing types are like, who think Word documents are the tool of the devil. These PDFs are never going to a professional printer anyway; they're just brochures for a client to download from a web page (based on information in a database) for printing/use at home.
You have indeed many solutions for such a web to print project. Choosing one is a matter of budget, requirements and users count. Placing dynamic contents can be done at the simpliest with PDF forms fillable with xml data.
On the other hand you can work with InDesign Server and output PDF based on InDesign templates. That's generally a good choice when a large amount of users needs to get rich pdf files in parallel. But the costs are heavy.
You can also envision A pitstop server or Callas PDFToolBox Server to place dynamic texts based on variables as supplied by you. The good point here is that you don't need much coding here. Those apps are ready to use.
You can at last consider command line tools. A few of them may have some useful commands such as pdfTk or cPdf to merge texts.
I know this is a little subjective, but I'm looking into the following situation:
I need to produce a number of documents automatically from data in a SQL Server database. There will be an MVC3 app sat on the database to allow data entry etc. and (probably) a "Go" button to produce the documents.
There needs to be some business logic about how these documents are created, named and stored (e.g. "Parent" documents get one name and go in one folder, "Child" documents get a computed name and go in a sub-folder.
The documents can either be PDF or Doc(x) (or even both), as long as the output can be in EN-US and AR-QA (RTL text)
I know there are a number of options from SSRS, Crystal Reports, VSTO, "manual" PDF in code, word mail merge, etc... and we already have an HTML to PDF tool if thats any use?
Does anyone have any real world advice on how to go about this and what the "best" (most pragmatic) approach would be? The less "extras" I need to install and configure on a server the better - the faster the development the better (as always!!)
Findings so far:
Word Mail Merge (or VSTO)
Simply doesn't offer the simplicity, control and flexibility I require - shame really. Would be nice to define a dotx and be able to pass in the data to it on an individual basis to generate the docx. Only way I could acheive this (and I may be wrong here) was to loop through controls/bookmarks by name and replace the values...messy.
OpenXML
Creating documents based on dotx templates, even using OpenXML is not as simple as (IMHO) it should be. You have to replace each Content control by name, so maintenance isn't the simplest task.
SSRS
On the face of it this is a good solution (although it needs SQL Enterprise), however it gets more complicated if you want to dynamically produce the folders and documents. Data driven subscription gets very close to what I want though.
Winnovative HTML to PDF Convertor*
This is the tool we already have (albeit a .Net 2.0 version). This allows me to generate the HTML pages and convert those to PDF. A good option for me since I can run this on an MVC3 website adn pass the parameters into the controllers to generate the PDF's. This gives me much finer-grained control over the folder and naming structures - the issue with this method is simply generating the pages in the correct way. A bonus is that it automatically gives me a "preview"...basiclly just the HTML page!
Office OpenXML is a nice and simple way of generating office files. XSLT's can be strong tool to format your content. This technology will not let you create pdf's.
Fast development without using any third party components will be difficult. But if you do consider using a report server, make sure to check out BIRT or Jasper.
To generate pdf's I have been using the deprecated Report.net. It has many ports to different languages and is still sufficient to make simple pdf's. Report.net on sourceforge
I dont think SQL Server itself can produce pdf files. What you can do is, as you mentioned, install an instance of SSRS and create a report that produces the information you need. Then you can create a subscription to deliver your report to where you want, when you want.
Here is an example of a simple subscription:
Go for SSRS only if you are OK with setting it up on a server and there is a definite need for schedule reporting and complex reports.
If you have code for manual PDF/docx generation, I would suggest to go ahead with it. Hopefully the complexity of its code is not a matter to you.
I have used both in separate scenarios. We used excel classes and objects from .NET for a minimal reporting from a web application.
But went for an elaborate reporting scheme for a system which required 1000s of reports to be generated in a scheduled manner and delivered to selected set of people.
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
I'm in need of a solution to print or export (pdf/doc) from C#. I want to be able to design a template with place holders, bind an object (or xml) to this template, and get out a finished document.
I'm not really sure if this is a reporting solution or not.
I also don't want to have to roll my own printing / graphics code -- I'd like all display concerns handled in a template.
I initially think of this as something Crystal Reports can do (although I've never used CR), but I'm not sure if I'm abusing the system here -- I'm not really interested in binding ADO.NET datasets at the moment (screw datasets). Can Crystal deal with binding to objects?
Does SSRS or WPF play in this field too?
A subset of WPF-P is XPS which can be used to present your objects via databinding.
One of the best choices if you are already using WPF.
Google Keywords: XPS, FixedDocument, FlowDocument, WPF Printing
Might read through this thread:
http://groups.google.com/group/nhusers/browse_thread/thread/e2c2b8f834ae7ea8
Seems a lot of people like iTextSharp
http://itextsharp.sourceforge.net/
For Word docs, look into Word's Mail Merge feature and Word automation. I did this recently in a form letter printing project. Basically what I did was create a Word template file (file extension .dot) and in this template file I defined MergeFields in a standard form letter. My application queries a database for the records it needs to print and then for each record it returns it matches fields in the database with these merge fields and sends the result (the merged doc) to the printer.
It's working really well and if I had a link that gave a definitive explanation, I'd provide it (check back here, I'll see if I can't find the most useful ones). Hopefully I've provided enough keywords to let you find your own resources. I can go into more detail if you need.
I've never had to export PDF files but for a project I'm working on now I'll have to. For a free solution my research has lead to iTextSharp (like Will Shaver points out) but I've only done the initial investigations and I have found a few pay solutions I might end up resorting to.