Free Support Forum -

HTML to PDF with inline Styles


I have below code
indent preformatted text by 4 spaces
public static void inLineCSSForFormInst(string outputPath, string formHTML, string formInstanceID)
outputPath += “InCSS.pdf”;

        string appPath = clsConfigurationSettings.appFilePath(sConnStr);

        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(File.ReadAllText(appPath + "RenderForm.aspx"));

        StringBuilder mainHTML = new StringBuilder();

        // All page CSS

        // render Form Page style
        foreach (HtmlNode linkNode in doc.DocumentNode.Descendants("style"))


        formHTML = mainHTML.ToString();

        File.WriteAllText("document.html", formHTML);

        using (var document = new Aspose.Html.HTMLDocument(formHTML, "."))
            // Create the PDF Device and specify the output file to render
            using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(outputPath))
                device.Options.PageSetup.AnyPage.Margin = new Aspose.Html.Drawing.Margin(0, 0, 0, 0);
                device.Options.PageSetup.AdjustToWidestPage = true;
                device.Options.Css.MediaType = MediaType.Screen;

                // Render HTML to PDF

But problem is as per HTML PDF is not rendering correctly. I need same as HTML view.
Can you help on this

attached is my HTML and PDF output (399.2 KB)


We were also able to notice similar issue in our environment and logged it as HTMLNET-2718 in our issue tracking system. We will further check it in details and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like