I'm not able to display Hebrew characters when using RazorPDF. I would love to know if it is possible or if there are any other good solution to covert HTML to PDF. The best thing wold be to specify the view (I'm using MVC 4) and get a PDF document.
Asked
Active
Viewed 1,128 times
0
-
http://www.codeproject.com/Articles/335595/Rotativa-how-to-print-PDF-in-Asp-Net-MVC – Steve Sep 02 '13 at 10:37
-
rotativa is great solution but it doesn't work on the cloud unless you are not running in shared environment. – UshaP Sep 02 '13 at 11:04
1 Answers
0
For cloud you can use iTextSharp library to accomplish that. Take a look at itextsharp.text.html.simpleparser.htmlworker.
Other reliable way would be to use Ghostscript library ( i'm not sure you can use it in cloud ). You can first convert Html to Postscript and then Postscript to PDF.
If you need most complete Ghostscript wrapper for .NET, take a look at: Ghostscript.NET.
Here is a sample for iTextSharp Html to PDF:
private MemoryStream createPDF(string html)
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(html);
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, msOutput);
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
// step 4: we open document and start the worker on the document
document.Open();
worker.StartDocument();
// step 5: parse the html into the document
worker.Parse(reader);
// step 6: close the document and the worker
worker.EndDocument();
worker.Close();
document.Close();
return msOutput;
}

HABJAN
- 9,212
- 3
- 35
- 59
-
Dos it support non English chars? how do you display the PDF on screen? when i tried with FileResult(i'm using mvc 4) i got an error – UshaP Sep 04 '13 at 12:12
-
Take a look: http://stackoverflow.com/questions/11524293/displaying-pdf-asp-net-mvc – HABJAN Sep 04 '13 at 12:29
-
Sorry, I didnt' mean how to diplay existing file but how to show the file i just generated - download/in the same window. – UshaP Sep 04 '13 at 15:53
-
Let say the file generated is a MemoryStream. MVC File function can accept MemoryStream so you dont need to save it to the disk first. – HABJAN Sep 04 '13 at 17:41