Exemple #1
0
        /// <summary>
        /// Creates the PDF file.
        /// </summary>
        /// <param name="html">the HTML file as a byte array</param>
        /// <param name="baseUri">the base URI</param>
        /// <param name="dest">the path to the resulting PDF</param>
        public void CreatePdf(byte[] html, String baseUri, String dest)
        {
            ConverterProperties properties = new ConverterProperties();

            properties.SetBaseUri(baseUri);
            OutlineHandler outlineHandler = new OutlineHandler();

            outlineHandler.PutTagPriorityMapping("h1", 1);
            outlineHandler.PutTagPriorityMapping("p", 2);
            properties.SetOutlineHandler(outlineHandler);
            HtmlConverter.ConvertToPdf(new MemoryStream(html), new FileStream(dest, FileMode.Create),
                                       properties);
        }
Exemple #2
0
        public virtual void HtmlToElementsTest09()
        {
            //Test OutlineHandler exception throwing

            /*
             * Outlines require a PdfDocument, and OutlineHandler is based around its availability
             * Any convert to elements workflow of course doesn't have a PdfDocument.
             * Instead of throwing an NPE when trying it, the OutlineHandler will check for the existence of a pdfDocument
             * If no PdfDocument is found, the handler will do nothing silently
             */
            String html = "<html><p>Hello world!</p><meta name=\"author\" content=\"Bruno\"><table><tr><td>123</td><td><456></td></tr><tr><td>Long cell</td></tr></table><p>Hello world!</p></html>";
            ConverterProperties props          = new ConverterProperties();
            OutlineHandler      outlineHandler = new OutlineHandler();

            outlineHandler.PutTagPriorityMapping("h1", 1);
            outlineHandler.PutTagPriorityMapping("h3", 2);
            outlineHandler.PutTagPriorityMapping("p", 3);
            props.SetOutlineHandler(outlineHandler);
            HtmlConverter.ConvertToElements(html);
        }