How to generate a PDF from a view using media=print for styles - razor

Most of the questions in stackoverflow or in other forums, show how to generate views and sends them by email.
But my goal is to generate a PDF from a view with the media=print format and sends it in attachment by email.
I have a view that displays a report.
I use CSS Print to display this report in a print format. (Basically I display some elements and hide others).
How can I generate a PDF from this view (with format media=print) and send it by e-mail in attachment.
I am using ActionMailer to send emails and iTextSharp to generate PDFs

I also had the same problem and did a lot of googling. but could not find a proper solution. There was a 3rd party dll called "PDFGenerator" but the output is not neat and nice.
So I chose another solution.
I created a report file(.rdlc) with the UI i want print it as a pdf by the code.
Here is my sample code
GitHub

Related

Using IcePDF or PDFBox to generate HTML page from PDF

I want to use IcePDF or PDFBox to extract content from PDF. But I don't now the way to continue generating HTML web pages from the text and images extracted.
You can convert pdf to html with PDFBox. Try this link.
By adding -html as parameter when you extract text, you will get html of the pdf. But it will not contain any image, graphics and other details. It will be only the text extracted from the pdf in html format.
If you want to create the exact look and feel of the pdf, there is no single step method in PDFBox. In my knowledge no library provides this facility to create exact html of the pdf. But using PDFBox you can extract images, text and its details. Using these details you have to create a logic to produce the html. We have done a project to convert pdf to html for azzist.com. We have accomplished the conversion using PDFBox. In azzist we are converting the resume to html format. (Still some font issues are there).
Scribd, google, dropbox, zoho etc have accomplished this conversion in a better way. You can have a look at any of these sites to check how they have accomplished this. (You will not get the logic. You have to find it out).

Display Invoice via HTML rathen than PDF?

I'm using Prawn to generate invoices as PDFs on the fly, which open in Adobe Acrobat. Is there a quick way to have that same invoice display as HTML, or at least be viewable from within my web app while retaining the layout, rather than opening up a new window/PDF? I've been unable to find any good example or suggestions. Thanks for your time and assistance.
use send_data in your controller action to open required files in the browser.
Check out the following SO question for more info

Sending a html form via email as a pdf

I have made an html form. What i want to happen is when the user clicks submit for the page to be emailed as a pdf (like the pdf that comes up if you print the webpage). I've been looking a all sorts of script but nothing seems to do what I want.
You will have to have a server-side component that takes the values, creates the PDF, and then e-mails it appropriately.
You'll be surprised to hear that not all browsers can easily make pdfs out of web pages. Hence, there is no universal JavaScript command that simply taps into a browser's capabilities. That leaves you with options:
Generate the pdf on the server (using, say, pdfbox, and send the email right from the server (using good old sendmail).
Generate the pdf on the server, have the user download it, and then transfer it all to his email client. (Might just work, see on Stackoverflow).
Generate the PDF in the browser, cross-platform. There are some Javascript-only libraries that can generate PDF.
Use Safari's PDF capabilities. Safari can make PDFs just in the print dialog. Explain that to your users and call window.print().

PdfSharp, GDI+ and HTML printing

I currently have a "PrintingWebService" that I call from an AJAX page with all the information that is needed to construct a highly customized PDF printout using PDF Sharp and the PDFSharp's GDI+ mode, which takes DrawString and other commands that work basically just like GDI+ only they are drawn to the PDF.
I then save the PDF file to a location on the webserver and return the file name from the web service, and the AJAX page opens a new window with the pdf file.
So far, it works well, however, there is one part of my AJAX page that I want to printout and I haven't come up with a solution for yet. I've got a string of the HTML content of a TinyMCE editor that I want to dispay in the bottom part of the PDF page.
I'm looking for some sort of tool I could use for this purpose. Even something opensource that prints to GDI+ I could use by taking the source code and translating it to use PdfSharp's GDI+ (the class names are like XGraphics, with each class having X before the GDI+ name).
If I have to I will limit what HTML can be generated by TinyMCE and write my own renderer, but that will be a big challenge, so I'm looking for other solutions first.
I've stayed away from a printer-friendly page approach because I wanted to construct a page that was a near identical of an existing WinForms printout, using my existing code. With PdfSharp I was able to convert all the code except the text area stuff (which used the RichTextBox and RTF in the WinForms version).
Tony,
I personally have used WebSupergoo's ABCPdf library with much success. You can actually render HTML directly to the PDF and it does fairly well in regards to accuracy.
Another free software that will allow you the flexibility of writing HTML to PDF that I have used in the past with much success is iTextSharp.
Otherwise, I think you'll have to write something to render HTML to GDI.
Either way, you may want to consider using an HttpHandler that you map to using your web.config to generate the PDF file. This will allow for you to render the PDF to a bytestream and then dump it directly to the user (as opposed to having to save each PDF receipt to the web server). It will also allow for you to use the .pdf extension in the page that returns the receipt (PurchaseReceipt.pdf could be mapped to a HttpHandler)... making it more cross-browser friendly. Older versions of Adobe / Browsers will not display correctly if you start throwing a PDF byte stream from an ASPX page.
Hope this helps.

Is there an application that generates an HTML form from a PDF?

Is there an application out there that Generates an HTML form from a PDF file? Also, it would need to generate the HTML form so that it would be able to submit to the PDF to fill out the fields inside the PDF.
PDF is not so good at validation and it's just a kluge interface to begin with.
Not sure of your full requirements but docudesk does this conversion as well as a number of others.
Adobe also have an online conversion tool that does this.