xaringanBuilder::build_pdf() fails with local images

Hi - I have a xaringan-presentation with local images that I include with:

<img src="../01b_DataPrep/img/test.png" width=600>

adding in the YAML: self_contain: trueproperly includes the images in the .html-output.
When using xaringanBuilder::build_pdf() this fails with:

Error in force(expr) :
Failed to generate output. Reason: Failed to open (HTTP status code: 404)

Does anyone have a pointer as to why this happens ?

edit: Can overcome it with rendering html, then opening in chrome and manual printing (from the xaringan-wiki) - but still curious about the reasoning behind..Thanks!

This would be a test-repo: xaringan-test/01b_DataPrep at main · cathblatter/xaringan-test · GitHub

I believe this is because you are using a relative like based on a folder in the parent directory.
build_pdf() will serve your document before printing (it uses pagedown::chrome_print(), but the root folder serve must be the folder of the document by default, this means that the image in the parent folder cannot be reached.

You can try serving the presentation yourself using server::httpd() and choose the parent folder as root. You would then be able to pass the local http URL to print.

Otherwise, you need to organize you file and project differently so that resources are copied in the prez folder, or just not stored in parent directory.

If you want xaringanBuilder::build_pdf() to handle that for you, you could open a FR in there repo maybe

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.