How to generate a PDF within application with no reporting framework - asp.net-mvc-3

I need to create pdf reports in my app. I'm using asp.net mvc3. What's the best way to do this? I don't really want to use a reporting framework if i can avoid it, it's just a few reports, table layout, groupings, pagination possibly, totals, ability to merge pdfs into 1 pdf....any ideas? what would be ideal is if i could convert my html view into a pdf simply...

There is nothing built into .NET allowing to create PDF files. So you have two possibilities: write one yourself from scratch or use one that exists.
In case you decide to go with the second you may take a look at flying-saucer which along with ikvmc.exe could be used to convert XHTML files into PDF. I have blogged about some of the required steps in order to get this working.

Some possibilities:
I think you can do this with SQL Server reporting services (in SQL rather than a 3rd party reporting framework)
Low level PDF libraries that can be used: PDFSharp, iTextSharp.
You could print an html file to a postscript driver using word automation, then convert the PS to PDF via GhostScript

Related

Preparing PDFs for use as Prawn templates

We've got a system that takes in a large variety of PDFs from unknown sources, and then uses them as templates for new PDFs generated by Prawn.
Occasionally some PDFs don't work as templates for Prawn- they either trigger a generic Prawn error ("Prawn::Errors::TemplateError => Error reading template file. If you are sure it's a valid PDF, it may be a bug.") or the resulting PDF comes out malformed.
(It's a known issue that some PDFs don't work as templates in Prawn, so I'm not trying to address that here:
[1]
[2])
If I take any of the problematic PDFs, and manually re-save them on my Mac using Preview > Save As [new PDF], I can then always use them as Prawn templates without any problem.
My question is, is there some (open source) server-side utility I can use that might be able to do the same thing- i.e. process problematic PDFs into something Prawn can use?
Yarin, it at least partially depends on why the PDFs don't work in the first place. If you can use them after re-saving with Apple's (quite bad) preview PDF code, you should be able to get the same result using a number of different tactics:
-) Use an actual PDF library to open and save the PDF files (libraries from Adobe and Global Graphics come to mind). These are typically commercial products but (I know the Adobe library the best) they do allow you to open a file and save it, performing a number of optimisations in the process. The Adobe libraries are currently licensed through a company called DataLogics (http://www.datalogics.com)
-) Use a commercial product that embeds these libraries. callas pdfToolbox comes to mind (warning, I'm affiliated with this product). This basically gives you the same possibilities as the previous point, but in a somewhat easier to use package (command-line use for example).
-) Use an open source product. I'm not very well positioned to provide useful links for that.
There is another approach that may work depending on your workflow and files. In graphic arts bad files are sometimes "made better" by a process called re-distilling; you basically convert the PDF file to PostScript and re-distill the postscript into PDF again. Because this rewrites the whole file structure, it often fixes fundamental problems. However, it also comes with risks as you're going through a different file format. Libraries such as GhostScript (watch the licensing conditions) may allow you to do this.
Given that your files seem to be fixed simply by using preview, I would think a redistilling approach would be overly dangerous and overkill. I would look into finding a good PDF library that can automatically open and save your files.

Generate .rdl file from Excel file

In a current project I have to generate an Excel report. I do have the the Excel file as a template which contains some static data along with some fields which contain parameter values.
On the bottom of the Excel file there should be a table which contains data from Dataset.
Now I am wondering if there is a way/ tool to generate the rdl file from the Excel file rather than creating it by myself (which would be very cumbersome...)
On the other hand is there a way to link static Excel content into the .rdl file?
You could use the excel spreadsheet as a data source for the report to pull the information in. But then it would need to be accessible from the report manager server if you're planning on deploying the report. So unless the information in the spreadsheet is going to change I think this will likely be more trouble than it is worth.
If it isn't necessary to deploy it to report manager then you could also try embedding the report in the excel file itself and use SSRS to update the dynamic content and you can just leave the static stuff already there. (Of course, depending on the complexity of what you're doing you could also just automate all of the dynamic stuff in Excel VBA code too.) I've personally never done this, but I've found a couple of blog posts detailing how it could possibly be pulled off. I think this is nifty enough I may have to try it if I ever get the chance. You can even use cell values in the spreadsheet and pass them as parameter values to the report.
I've found a post on embedding the report data as an image that refreshes from the report server. On the upside it seems simple to pull off, but the downside is that it is an image and the numbers won't be available to be individually selected only looked at. So it would be best for charts but not your data table.
Then there is this article which shows how to actually import the values into the spread sheet by pulling it in from SSRS in CSV format and using some VBA code to put it into the excel file. It is a more complicated solution but I think its a pretty cool idea, though I dunno how well it will work in practice.
Otherwise, I think you're stuck recreating the static information and formatting from the excel file in your report.

Is there a common solution to generate msoffice, libreoffice and pdf documents on the fly?

I would like to generate office documents (msoffice, oo) and pdf on the fly from one source document. Currently i think about opendocument as templates files and libreoffice-headless as converter.
Does anybody have experience on this topic and is there a (commercial?) ready to use solution?
A commercial solution is Docmosis which has a downloadable and cloud-service solutions using MSWord/OpenOffice documents as templates and providing template-population features, load balancing, doc/docx/odt/pdf/rtf/html production and quite a few other features. One of it's key features is to generate point-in-time output in multiple formats (from the same template and data) as you mentioned. It has at least one Ruby example to show the population features. Please note I work for the company that created Docmosis.
Another option is the open source JOD Reports.
I hope that helps.

Ruby: delete columns by name in MS Excel on Windows?

Is there a way to use Ruby to delete columns in an Excel spreadsheet by name (i.e. the value in the first row of the spreadsheet) on a Windows machine?
Background if you want it:
I am going to be receiving a large number of Excel spreadsheets on a regular basis. Some of these spreadsheets will contain columns that need to be deleted. I will know the names (first-row values) of the columns, but their positions in their respective spreadsheets will change from time to time, so I won't be able to automatically refer to the columns by letter. I would really like to be able to automate this process...
POI is the Apache project to create a library for reading MS Office files; it appears they have Ruby extensions. I have never used it before, but the code looks easy enough to understand. Good luck! Check it out here
You probably want to use the WIN32OLE library, built into the standard library on Windows. There's an example in PickAxe about using Microsoft Excel through the WIN32OLE library, and other examples here. You just need to learn how to use the Excel COM API to make the particular changes you're interested in.

Load MS Word files with AJAX

I want to dynamically load (AJAX) the text from some Microsoft Word files into a webpage. So I might have a link to essays I've written and upon mouseover have it load the first few sentences in a tooltip.
Only if you have a parser. I think the new format is a zip archive with XML schema. But the old one is just binary.
There are some parsers out there.
I know of wvWare but it seems it's outdated. (http://wvware.sourceforge.net/)
This is maybe something worth looking at: http://poi.apache.org/hwpf/index.html
And yeah, forgot to mention how to do this. :-)
First you need to make the javascript ask for the data through ajax. The serverside has to take care of the parsing and return the text to the javascript. This will be a pain in the ass. I haven't done this myself and have never tried the parsers I linked, so I'm not sure if they suit you. Images, stylesheets, etc.... not sure if that will be useable.
At least, good luck.
For security reasons, it is not possible to directly load a local file (such as a Word document) into the page using simply Javascript. The user will need to upload the file to the server, which you will want to parse on the server and then you can load whatever result you like into the page using Ajax.
It sounds like you mean to upload your files (e.g. essays) to your server to allow users to download them, and want to create a server-side page that will parse the files and print the first few lines (so it can be called by an AJAX method that displays a preview on hover).
To suggest a tool for this, we'll need to know whether these are "old" Word format (Office 2003 - extension is .doc) or "new" Word format (Office 2007 - extension is .docx).
It will also be good to know what you're using to create your pages server-side, since different document-reading tools support different programming languages. If you're using Java to read .doc files, you can use the tool we use at my place of work, which is POI (http://poi.apache.org/). If you're using something else, try searching google for {read in }, e.g. {read .docx in ruby}.
If all of this is Greek to you and you have no prior experience with developing custom server-side web code, this is probably going to be unnecessarily painful and you should consider an alternative (like manually creating a 3-line text "preview" page for each regular page, and then just showing that).

Resources