Forum Bugs

Unable to load any external resources

dseptimus
I'm using Prince 10 rev 4 patch 1 on windows and it seems that even when loading a page via HTTP, any external resource that doesn't use a fully qualified url is resolved against the local file system.

Setting --baseurl to http://some-url doesn't seem to have any effect.

For example:

input url: http://some-url/page1
base url: http://some-url
image tag: <img src="..\..\..\assets\images\img1.jpg"></img>

Here'e the error I get:
prince: \..\..\..\assets\images\img1.jpg: warning: can't open input file: No such file or directory

If the src attribute contains "http://some-url/assets/images/img1.jpg" the image loads.

Is this a known issue with this version of prince or am I missing something?
mikeday
Those slashes should be going the other way, like this: /
dseptimus
Sorry, the example was incorrect. I was working backwards from the error output. The actual paths use a forward slash.
mikeday
That's very odd, what is the exact command-line you are using?
dseptimus
Here's the command line:
prince.exe http://localhost:8000/static/f57cc592-bc69-4d78-bbd7-2bc3b20ab3af.html --baseurl=http://localhost:9000 --output=debug-output\f57cc592-bc69-4d78-bbd7-2bc3b20ab3af.pdf --style=print-styles/landscape.css

where localhost:8081/static/[FILE] represents the output of intermediate phantomjs processing step and localhost:9000 is the web app containing the external resources.


mikeday
Does that mean that no images with relative paths load at all, even simple ones like "image.jpg"?
dseptimus
Given image.jpg, prince complains about being unable to find \image.jpg.

Edit: additional details

prince: loading image: \image.jpg
prince: debug: error loading resource: can't open input file: No such file or directory

Edited by dseptimus

mikeday
Can you try running this command:
prince http://yeslogic.com --baseurl https://www.princexml.com -o out.pdf

It should warn about one missing style sheet and three missing images, but the PDF should include the purple Prince "box" (taken from /images/fakebox.png which is available on both servers).
mikeday
I've tested this command on Windows with Prince 10 and it works fine, so if it also works for you we will need to establish what differs in your input documents or configuration.
dseptimus
Here's the output.

 ./prince.exe http://yeslogic.com --baseurl https://www.princexml.com -o out.pdf
prince: https://www.princexml.com/css/style2.css: warning: The requested URL returned error: 404 Not Found
prince: https://www.princexml.com/images/princelogo.png: warning: The requested URL returned error: 404 Not Found
prince: https://www.princexml.com/images/protoforumscreenshot.png: warning: The requested URL returned error: 404 Not Found
prince: https://www.princexml.com/images/protoforumlogo.png: warning: The requested URL returned error: 404 Not Found


I'm seeing 404 for the resources, but at least it seems to be attempting to load them from the correct location.
mikeday
That's correct, and it looks like it successfully loaded the image that was present.

Does your document have a <base> element in the <head>, or any xml:base attributes?
dseptimus
That was it, thanks! It was the base tag generated by Angular.

<base href="/">


I just added a quick function to our phantomjs script to strip the base tag from the intermediate output. Our images are now being loaded successfully. Is there a different non-phantomjs based solution that you would generally recommend for cases like this?
mikeday
You could strip out the tag with JavaScript in Prince, if that's more convenient?
dseptimus
Got it. For now, we'll stick with doing it in phantom. Thanks again.