Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Nov 24, 2016 3:17 pm

Hello,

we are using the Spire.Doc Pro Version.
Now we need additional convert HMTL files to pdf - now we have the question regarding the format:
I have css in HTML file, could this be parsed with Spire.Doc?

Extract from the HMTL File:
<Html>
<header>
<link rel="stylesheet" type="text/css" href="c:\temp\CSS\bootstrap\css\bootstrap.css" media="screen">
….
</header>
<body>

</body>
</html>


Thanks for your response!

Katja2016
 
Posts: 3
Joined: Thu Nov 24, 2016 3:01 pm

Fri Nov 25, 2016 2:47 am

Dear Katja2016,

Thanks for your inquiry.
Spire.Doc supports to parse css file. If there is any issue, please provide us sample files for investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Dec 19, 2016 7:53 am

Hello support,

could you provide me an example how the conversion from HTML -> PDF with CSS files works?
My collegue has tried it with the following code snippet:
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(HTMLString, fileName + ".pdf", true, 10 * 1000, new SizeF(612, 792), new Spire.Pdf.Graphics.PdfMargins(0), Spire.Pdf.HtmlConverter.LoadHtmlType.SourceCode);

This seems not to work, the format isn´t taken over from the CSS files and furthermore there is Spire.PDF used.
You told me that it is possible to use only the Spire.Doc license and no Spire.PDF is needed?

Thanks in advance!

Greetings,
Katja

Katja2016
 
Posts: 3
Joined: Thu Nov 24, 2016 3:01 pm

Mon Dec 19, 2016 8:40 am

Dear Katja,

Thanks for your feedback.
Both the Spire.Doc and Spire.PDF can support to convert HTML to PDF, and according to your first description, I answered the question with Spire.Doc. So sorry for this.
Sorry that the HTML code method you mentioned in Spire.PDF doesn't support to recognize the CSS files. We suggest you use URL method in Spire.PDF, that can work fine.
Code: Select all
Convert(string url, string fileName, bool enableJavaScript, int timeout, SizeF pageSize, PdfMargins margins);

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Dec 19, 2016 2:50 pm

Hello support,

I think there were some missunderstandings, following we would like to do:
- Convert HTML with CSS files to PDF

We would like to use only Spire.DOC because we have only a license for this.

Could you provide me a code snippet for this?

Greetings,
Katja

Katja2016
 
Posts: 3
Joined: Thu Nov 24, 2016 3:01 pm

Tue Dec 20, 2016 1:42 am

Dear Katja,

Sorry that I misunderstood your meaning.
I have tested the scenario with the latest Spire.Doc Pack(hot fix) Version:5.8.24. And it works fine, please check the files on attachment.
Here is my testing code.
Code: Select all
            Document document = new Document();
            document.LoadFromFile(@"F:\testing\doc form\original document\9371.html", FileFormat.Html, XHTMLValidationType.None);
            document.SaveToFile("9171.pdf", FileFormat.PDF);

If you still encounter the issue, please provide us your sample files and code you were using.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Dec 23, 2016 7:27 am

Dear Katja,

Has the issue been resolved ?
If not, please provide us your sample files and code you were using.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Apr 22, 2021 3:38 pm

Hello Support:

We are using Spire.DOC Pro version (for .NET and it was updated to 9.4.12 version) and we are with same problem with CSS referenced into HTML page when try to parse with Spire.DOC.

In my HTML file (Cartao-4.html) a have the following references to CSS files:
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="./_assets/css/font-awesome-all.min.css" media="screen" />
<link rel="stylesheet" type="text/css" href="./_assets/css/grid.css" media="screen" />
<link rel="stylesheet" type="text/css" href="./_assets/css/style.css" media="screen" />

When we open this html file directly from a browse it opens ok, but when i load using Spire.DOC LoadFromFile and save as PDF using SaveToFile seems like CSS was not applied:

doc.LoadFromFile(htmlFile, FileFormat.Html, XHTMLValidationType.None)
doc.SaveToFile(caminho, FileFormat.PDF)

I send all examples files for your investigation.

Greetings,
Eduardo Y. Tsuzuki

carolina.foltran
 
Posts: 5
Joined: Thu Apr 08, 2021 11:07 am

Fri Apr 23, 2021 3:21 am

Hello,

Thanks for your inquiry!

I have reproduced the issue of losing CSS when converting HTML to PDF, and logged it in our issue tracking system with the ticket SPIREDOC-5896 for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Apr 23, 2021 12:08 pm

Hello Marcia:

Is there any other way to do what i want? Before purchase the Spire.DOC license i was using the plugin from SPire.PDF free (it is just one page to convert to PDF and worked perfect) but when i installed Spire.DOC, i could not use SPire.PDF free anymore (the Spire.doc installed other Spire.PDF changing the free version).

Greetings
Eduardo

carolina.foltran
 
Posts: 5
Joined: Thu Apr 08, 2021 11:07 am

Fri Apr 23, 2021 12:26 pm

Hello Marcia:

Just to explain, I purchased the Spire.DOC version because I need convert big RTF files to PDF and the Spire.DOC fits what I need.

Greetings,
Eduardo

carolina.foltran
 
Posts: 5
Joined: Thu Apr 08, 2021 11:07 am

Sun Apr 25, 2021 2:13 am

Hello Eduardo,

Thanks for your feedback!

As a temporary method, you can use the Spire.PDF to convert HTML to PDF, please refer to the following article: Convert HTML to PDF with New Plugin.

Besides, if you want to use two or more products of our products in one project, please use the Spire.Office to achieve this. Please download the latest Spire.Office V6.4.2, clean up and re-build your project and try again.

If you encounter any issues in the future, please feel free to contact us.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Apr 26, 2021 8:00 am

Dear Eduardo,

Thanks for your patience!

Our Spire.Doc follows the rules of MS Word. After further investigation, we found that even opening your file (Cartao-4.html) directly in the MS Word, the style is also different from that opened in the browser. Kindly note that the internal principle of Word is different from that of HTML, and many of the CSS styles in the HTML have no corresponding settings in the Word, thus it is impossible to make the converted PDF look the same as the original HTML. Sorry our Spire.Doc can't keep the same style while converting your HTML to PDF.

I suggest that you use the feature Convert HTML to PDF with New Plugin provided by our Spire.PDF. I did a test with the latest Spire.Office Platinum(Hotfix) Version:6.4.2 and found the result has a better effect, but there was still wrongs with the style. In fact, our plugin method is based on the Qt plugin of the Chrome kernel, if using the Google Chrome to print preview your HTML, there is still the problem. After investigation, I found the cause is the style media="screen" in your HTML. After removing it, our Spire.PDF will get the same style as the original HTML. Here I uploaded my modified HTML and generated PDF for your reference.

Thanks for your understanding again.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Apr 26, 2021 6:09 pm

Hello Marcia:

As i said before, i used the feature "Convert HTML to PDF with NewPlugin" from Spire.PDF FREE (because i just have to convert one HTML page and free version allow until 3 pages), but after that, i had to convert BIG RTF files to PDF then i purchased Spire.DOC PRO version but, when i installed this version, the old Spire.PDF free was changed and i can not use the Html-TO-pdf plugin feature anymore. This is why i tried to convert HTML to .DOC and then convert .DOC to PDF using Spire.DOC PRO only.

I have a budget limitation and can not buy Spire.Office version.

Is there any way to use Spire.DOC PRO version with Spire.PDF FREE version together?

Greetings,
Eduardo

carolina.foltran
 
Posts: 5
Joined: Thu Apr 08, 2021 11:07 am

Tue Apr 27, 2021 2:59 am

Dear Eduardo,

Thanks for your reply.

Since there is conflict between the free version and the commercial version, using Spire.DOC PRO version and Spire.PDF FREE version together is not allowed.

For your situation, you do not need to purchase the Spire.Office, and just purchase the Spire.PDF to use both Spire.Doc and Spire.PDF to meet your needs. We could offer you a 30% off discount to purchase a license for Spire.PDF. After discount, it costs $419.3. Please get back to us for the coupon code if/when you decide to purchase.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.Doc