English 中文(简体)
AbcPdf - document not applying CSS
原标题:
  • 时间:2010-01-20 20:18:53
  •  标签:
  • abcpdf

This may be more of a tech support issue, but I m wondering if any other developers have come across this:

I m using Abcpdf in my ASP.NET code to generate a PDF from HTML. It works fine, but one user is generating PDFs that don t have the CSS applied (IE8, Adobe Acrobat latest version - same as everyone else). Since this is the only user complaining, I m sure it s a local setting, but I can t figure out what would prevent the css from loading - a browser setting? An Acrobat setting?

Does anyone have any suggestions?

问题回答

Perhaps an issue with different versions of Acrobat reader? I d look into this.

This doesn t make a lot of sense because AbcPdf uses service side logic to create the PDF based on what methods you are using to create the document (ex. AddImageUrl vs drawing out the document manually, etc.).

For what it s worth the staff at WebSuperGoo (the vendor of AbcPdf) is great with replying to support questions such as this. I ve run across a few edge cases with their product that they ve always followed up with workarounds or alternatives to address in a timely manner.

make sure you have media="print" for the CSS style sheet! Just spent ages looking at this pulling my hair out and was about to email WebSuperGoo then that thought came to me. just about to back out all the changes I ve made to my code and test again but it looks like with EngineType.Gecko it needs to be media="print" where as with EngineType.MSHtml it can be media="screen".....

very odd but hope that helps someone!

Make sure that the CSS is an absolute URL rather than relative, or add a base tag to the header of the HTML

For example, rather than

<style type="text/css" href="/styles/somecss.css" rel="stylesheet" />

use

<style type="text/css" href="http://myserver.com/styles/somecss.css" rel="stylesheet" />

Also if you site is SSL or authenticated then you will have to either make the area with the stylesheet un-authenticated, or, set the password and username attributes of the PDF object so that ABCPdf can authenticate

You can try the following in version 9

doc.HtmlOptions.PageLoadMethod = 
     PageLoadMethodType.WebBrowserNavigate;

I am using Version 10 of ABCpdf and I found that the style sheet path should be absolute instead of relative.

I changed the stylesheet path from "C:MyProjectResourcesStyles.css" to "http:www.MyDomain.comResourcesStyles.css" and it worked.

Although, version 6 seems to be working with relative paths. I didnot check it with other versions

As per WebSuperGoo support:

(Query # : 6.17)

HTML does not exist within a file and so it does not have a location.

External stylesheets and images are often referenced via relative URLs. Because the HTML has no location it is impossible to resolve these relative references.

So you need to provide your stylesheet and image links as absolute references. Or you may be able to use the HTML BASE element to specify an appropriate base location. Or you can save your HTML to file in an appropriate location and then use AddImageUrl.

Have you tried;

theDoc.HtmlOptions.DoMarkup = true;

This forces the engine to process the HTML before rendering.





相关问题
Extra blank page when converting HTML to PDF using abcPDF

I have an HTML report, with each print page contained by a <div class="page">. The page class is defined as width: 180mm; height: 250mm; page-break-after: always; background-position: centre ...

Is it possible to modify PDF Form Field Names?

Here s the situation. I have a PDF with automatically generated pdf form field names. The problem is that these names are not very user friendly. They look something like : topmostSubform[0].Page1[...

Add background-image to <td> in PDF (ABCpdf)

I m dynamically creating a PDF using ABCpdf (HTML -> PDF) I m trying to create a Table Of Contents (with leaders), and I think the easiest way to get the leaders is using a repeat-x background-image. ...

Tell abcPdf to scale the html to fit on a single pdf page

I am using abcPdf to convert an HTML report into a pdf file. The pdf has to be a single landscape A4 page. Do you know if there is any way to tell abcPdf to scale the HTML page to fit on a single ...

AbcPdf - document not applying CSS

This may be more of a tech support issue, but I m wondering if any other developers have come across this: I m using Abcpdf in my ASP.NET code to generate a PDF from HTML. It works fine, but one ...

ABC PDF - create 256 color images

I am using ABCpdf7 to create pdf documents on the fly - Here is something that I do not understand. When I create the pdf document from a url - the images in the pdf document seems to be 256 colors. ...

热门标签