Convert HTML to PDF respecting CSS @media print

We show an ASP.NET web-form to customers to order goods.
The users have the possiblity to print the ordering-form from theier browsers. (by clicking a button)

We use a css-file with
@media print
{
.description { display: none }
}
to hide some html-elements on the printed output.
Now we want to also send an Email with a pdf file containing the print-view of our form.
we used the folloing code to generate the pdf
Code Snippet
  1. using (HtmlTextWriter tw = new HtmlTextWriter(sw))
  2. {
  3. this.RenderControl(tw);
  4. string html = sw.GetStringBuilder().ToString();
  5. Aspose.Pdf.HtmlLoadOptions htmlLoadOptions = new Aspose.Pdf.HtmlLoadOptions(@"http://myWebPage");
  6. using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(html)))
  7. {
  8. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(ms, htmlLoadOptions);

the generated PDF looks different from the output when clicking on "Print" in browser.

Is there a way to make the generated PDF look the same as when clicking on print-button?
(respecting css @media print)


kind regards

Markus

Hi Markus,


Thanks for your inquiry. In HTML to PDF conversion, you need to pass resource files(CSS/Images/Fonts) base path through HtmlLoadOptions object and it seems you are specifying it in your code correctly. However we will appreciate it if you please share a sample project with resource files, so we will replicate the issue at our end and will provide you information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

I found out, what the problem was.


Aspose.Pdf for .NET supports CSS3.
But it does not run java-scripts.

So pages which are using jquery-ui will NOT be converted correctly.

jquery-ui modifies the HTML received from the server on the client-side using javascript.

Hi Markus,


Thanks for your feedback. Yes you are right currently Aspose.Pdf does not support to run Java script during HTML to PDF conversion. However we will appreciate it if you please share your sample HTML along with related resources, so we will address your issue exactly.

We are sorry for the inconvenience caused.

Best Regards,