You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Nicola Cisternino <nc...@gmail.com> on 2021/10/26 12:07:55 UTC

PDF Rendering

Hi all
I've an html resource (e.g. "pagecontent.html" stored in "apps" JCR structure and mapped as sling:resourceType in a "content" node (e.g. /content/test/page1).
So, using a browser, a request of: http://localhost:8080/test/page1 returns a text stream containing html tags ... while a request of http://localhost:8080/test/page1.html is normally parsed and correctly displayed.
Can Sling return a PDF rendering of my HTML resource? (something like http://localhost:8080/test/page1.pdf... or http://localhost:8080/test/page1.html.pdf)
Thanks a lot.


Re: PDF Rendering

Posted by Nicola Cisternino <nc...@gmail.com>.

On 2021/10/26 12:07:55, Nicola Cisternino <nc...@gmail.com> wrote: 
> Hi all
> I've an html resource (e.g. "pagecontent.html" stored in "apps" JCR structure and mapped as sling:resourceType in a "content" node (e.g. /content/test/page1).
> So, using a browser, a request of: http://localhost:8080/test/page1 returns a text stream containing html tags ... while a request of http://localhost:8080/test/page1.html is normally parsed and correctly displayed.
> Can Sling return a PDF rendering of my HTML resource? (something like http://localhost:8080/test/page1.pdf... or http://localhost:8080/test/page1.html.pdf)
> Thanks a lot.
> 
> 
Thank you Konrad and Robert !
I need a generic html2pdf converter usable with any existing (or generated) html resource ... so I was looking to use "Output Rewriting Pipelines" (https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html) in conjunction with "Flying Saucer and OpenPDF"

Re: PDF Rendering

Posted by Robert Munteanu <ro...@apache.org>.
Hi Nicola,

On Tue, 2021-10-26 at 12:07 +0000, Nicola Cisternino wrote:
> Hi all
> I've an html resource (e.g. "pagecontent.html" stored in "apps" JCR
> structure and mapped as sling:resourceType in a "content" node (e.g.
> /content/test/page1).
> So, using a browser, a request of:
> http://localhost:8080/test/page1 returns a text stream containing
> html tags ... while a request of
> http://localhost:8080/test/page1.html is normally parsed and
> correctly displayed.
> Can Sling return a PDF rendering of my HTML resource? (something like
> http://localhost:8080/test/page1.pdf... or
> http://localhost:8080/test/page1.html.pdf)

If you are looking for a way to have Sling automatically render your
resources in PDF format like it does for HTML, see Konrad's answer.

If you want to add support yourself, it's quite easy to add a renderer
for a different extension, see for instance [1] in the Sling project
archetype. You can register a Servlet for the 'pdf' extension and
generate the output using whatever PDF library you prefer.

Hope this helps,
Robert

[1]: https://github.com/apache/sling-project-archetype/blob/master/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java


Re: PDF Rendering

Posted by Konrad Windszus <ko...@gmx.de>.
This requires additional tools, Sling does not come with an automated HTML -> PDF transformer but you can probably look into http://xmlgraphics.apache.org/fop/ to convert XML -> PDF with the help of XSL-FO. XML can be easily generated with Sling scripting languages.
Konrad

> On 26. Oct 2021, at 14:07, Nicola Cisternino <nc...@gmail.com> wrote:
> 
> Hi all
> I've an html resource (e.g. "pagecontent.html" stored in "apps" JCR structure and mapped as sling:resourceType in a "content" node (e.g. /content/test/page1).
> So, using a browser, a request of: http://localhost:8080/test/page1 returns a text stream containing html tags ... while a request of http://localhost:8080/test/page1.html is normally parsed and correctly displayed.
> Can Sling return a PDF rendering of my HTML resource? (something like http://localhost:8080/test/page1.pdf... or http://localhost:8080/test/page1.html.pdf)
> Thanks a lot.
>