Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Convert HTML to PDF issue

$
0
0
I am using the following code to load an html file and save it as PDF the issue is the main div has an image embeded as background (base64). That image does not show in the rendered pdf also how can I make the pdf fit to page when rendered.

See the attached files for html sample & the code below:

        private void ConvertHTMLToPDF(string filePath)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../Data/");

            // Instantiate an object PDF class
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            pdf.PageSetup.Margin.Left = 0;
            pdf.PageSetup.Margin.Top = 0;

            // add the section to PDF document sections collection
            Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

            //// Read the contents of HTML file into StreamReader object
            //StreamReader r = File.OpenText(dataDir + filePath);
       
            StreamReader r = File.OpenText(filePath);

       
            //Create text paragraphs containing HTML text
            Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());

            // enable the property to display HTML contents within their own formatting
            text2.IsHtmlTagSupported = true;

            //Add the text paragraphs containing HTML text to the section
            section.Paragraphs.Add(text2);

            // Specify the URL which serves as images database
            //pdf.HtmlInfo.ImgUrl = "D:/pdftest/MemoryStream/";

            //Save the pdf document
            pdf.Save(dataDir + "HTML2pdf.pdf");
        }

Viewing all articles
Browse latest Browse all 3131

Trending Articles