Free Support Forum - aspose.com

HTML to PDF with inline Styles

Hi,

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();
        mainHTML.AppendLine("<head>");

        // All page CSS
        mainHTML.AppendLine(Styles());

        // render Form Page style
        foreach (HtmlNode linkNode in doc.DocumentNode.Descendants("style"))
        {
            mainHTML.AppendLine(linkNode.OuterHtml);
        }
       
        mainHTML.AppendLine("</head>");

        mainHTML.AppendLine(formHTML);

        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
                document.RenderTo(device);
            }
        }
    }

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

document.zip (399.2 KB)

@meghatp

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