RazorPDF encoding

1.1k Views Asked by At

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.

1

There are 1 best solutions below

4
On

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;
}