Q: How do I convert an HTML string into either a XAML string or an XPS stream with PDFNet SDK ?
A:
The PDFNet Convert add-on can perform HTML to XPS conversion. Direct conversion from HTML to PDF (or XPS/SVG etc) is possible using ‘pdftron.PDF.HTML2PDF’. HTML2PDF converter supports HTML conversion from a string or URL and offers many options to control page size and formatting. To gain a better understanding, you can check out some sample code of how to do the conversions by looking at the sample projects “Convert” and “HTML2PDF” on http://www.pdftron.com/pdfnet/samplecode.html.
Q:
Thanks for the answer! I’ve examined the Convert add-on and found the ToXPS method: http://www.pdftron.com/pdfnet/PDFNetAPIRef/html/01802023-9c0c-3ce8-a0b4-f43496d293fb.htm This method takes in a filename though, and not a string representation of a document. I have the HTML document I want to convert stored in a string, and I would prefer not to write it to disk in order to convert to XPS. Is there a way to do this?
A:
You can convert an HTML string into XPS with something like this:
using (PDFDoc doc = new PDFDoc())
{
HTML2PDF converter = new HTML2PDF();
// Our HTML data
string html = "<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>";
// Add html data
converter.InsertFromHtmlString(html);
// Note, InsertFromHtmlString can be mixed with the other Insert methods.
if ( converter.Convert(doc) )
// Now convert the PDF to XPS with toXPS()
}
On Friday, May 24, 2013 12:40:07 PM UTC-7, Support wrote:
Q: How do I convert an HTML string into either a XAML string or an XPS stream with PDFNet SDK ?
A:
The PDFNet Convert add-on can perform HTML to XPS conversion. Direct conversion from HTML to PDF (or XPS/SVG etc) is possible using ‘pdftron.PDF.HTML2PDF’. HTML2PDF converter supports HTML conversion from a string or URL and offers many options to control page size and formatting. To gain a better understanding, you can check out some sample code of how to do the conversions by looking at the sample projects “Convert” and “HTML2PDF” on http://www.pdftron.com/pdfnet/samplecode.html.