Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri May 03, 2019 9:26 pm

Hi I tried to convert html to pdf in free version from html code as string , the style classes works well but if i added style for the element , the style for this element doesn't work
here is my code
Code: Select all
         public byte[] ExportAsPdf(string htmlCode, string reportContent)
        {
            MemoryStream output = new MemoryStream();
            PdfDocument doc = new PdfDocument();
            try
            {
                HtmlString htmlString2 = new HtmlString(htmlCode);
                string fullHtmlCode = htmlString2.ToHtmlString();
                fullHtmlCode = fullHtmlCode.Replace("#ReportContent", reportContent);


                PdfMargins margins = new PdfMargins(60, 60, 60, 60);
                //create a header template with content and apply it to page template
                doc.Template.Top = CreateHeaderTemplate(doc, margins);
                //create a footer template with content and apply it to page template
                doc.Template.Bottom = CreateFooterTemplate(doc, margins);

                PdfPageSettings setting = new PdfPageSettings();

                setting.Size = new SizeF(1000, 1000);
                setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);

                PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
                htmlLayoutFormat.IsWaiting = true;               
                Thread thread = new Thread(() =>
                {

                    doc.LoadFromHTML(fullHtmlCode, true, setting, htmlLayoutFormat);
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();
                //Save pdf file.
               
            }
            catch(Exception ex)
            {


            }

            doc.SaveToStream(output);
            return output.ToArray();
        }


and i need this style to be rendered well
Code: Select all
            table thead tr th:first-child {
                border-radius: 0 10px 0 0;
            }


is this available to read style for the element in this way ?
Thanks

manar_yousry
 
Posts: 1
Joined: Thu Mar 14, 2019 2:24 pm

Mon May 06, 2019 8:24 am

Hi,

Thanks for your inquiry and sorry for the late reply as weekend.
The conversion method you used does not support the CSS3 well. However, our Spire.PDF provides another method to convert HTML to PDF. Please refer to the tutorial: How to convert HTML to PDF with New Plugin. I tested it with the border-radius style, it worked well. Please have a try. Below is my testing code. Just feel free to write back if there is any question.
Code: Select all
String Htmltext = "<head><style>table thead tr th:first-child{border-radius: 0 10px 0 0;}</style></head><body><table border=1><thead><tr><th>1</th><th>2</th><th>3</th></tr><thead/></table></body>";
string input = Htmltext;
string outputFile = "ToPDF.pdf";
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(input,
outputFile,
//enable javascript
true,
//load timeout
 10 * 1000,
 //page size
new SizeF(612, 792),
 //page margins
 new Spire.Pdf.Graphics.PdfMargins(0),
//load from content type
 LoadHtmlType.SourceCode
);

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Wed May 08, 2019 9:50 am

Hi,

Has your issue been resolved? Could you please give us some feedback at your convenience? Thanks in advance.

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Return to Spire.PDF