Forum How do I...?

.NET Library Conversion Doesn't Match Command Line Version

Steve_Fenton
I'm trialling Prince currently - good working on being the only PDF converter that respects CSS Paged Media!

If I run the command line, everything looks perfect:

"C:\...\prince.exe" http://localhost/Test/ -o C:\Pdf\prince.pdf


The PDF is created using the web page, with all the styles from the stylesheet included and all the awesome paged media stuff working.

When I try to recreate this using the .NET library:

Prince prn = new Prince(runnerLocation);
prn.SetLog("C:\\Pdf\\log.txt");
 prn.Convert("http://localhost/Test/", "C:\Pdf\prince.pdf");


The PDF is rendered, but it seems to be missing all the default browser styles.

Do I have to explicitly point it to the default "browser" stylesheet (this is my current workaround) or can I tell Prince to use default styles using a setting?

prn.AddStyleSheet(GetDefaultCssUrl());


mikeday
So it isn't loading the style sheets referenced from the web page? Are any warning messages appearing in the output log?
Steve_Fenton
Thanks for the reply Mike.

It is loading the styles from the web page - but not any "default" styles (i.e. if I look at the page in the browser, the browser global default style sheet).

As a temporary fix, I'm loading in a copy of the Mozilla default stylesheet, which works fine.

Edited by Steve_Fenton

mikeday
Okay that is strange. Normally this will only happen if you explicitly pass --no-default-style, or if the document is XML, not HTML. Does the problem still occur if you convert a local file, instead of a HTTP URL?
Steve_Fenton
It only happens over HTTP - local files work perfectly.
mikeday
In that case, perhaps the HTTP includes an additional Content-type header, that is coming up as XML or XHTML instead of HTML? You could check page info in the browser, or use wget or curl to retrieve the URL and see what content-type it comes back with.
Steve_Fenton
Here are the headers...

Cache-Control	private
Content-Encoding	gzip
Content-Length	1643
Content-Type	text/html; charset=utf-8
Date	Fri, 10 Jan 2014 10:37:11 GMT
Server	Microsoft-IIS/8.0
Vary	Accept-Encoding


It's just a thought - but I'm calling Prince via .NET - perhaps I haven't included enough files as dependencies. Are the CSS files embedded or alongside?
mikeday
They are in the Prince\Engine\style directory.

Edit: all the files in the Engine folder are necessary, basically.

Edited by mikeday

Steve_Fenton
I have ensured all of those files are available and it has fixed the problem - thank you!