How to embed external pdf/txt file into another using XSL-FO?
Asked Answered
M

3

5

Is it possible to embed an external PDF or TEXT document into a master PDF by using XSL-FO/XSLT?

I have xslt stylesheet to produce PDF documents. But, the input XML contains inlined TEXT or Base64 encoded PDF documents. So what I do in my HTML version of my stylesheet I extract the TEXT or PDF and dump it on disk. Then in the xslt I have this:

<xsl:when test='(n1:text/@mediaType="application/pdf") or (n1:text/@representation="B64")'>
    <IFRAME name='documentFrame' id='documentFrame' WIDTH='100%' HEIGHT='65%' src='{$DOC_URI}'/>
</xsl:when>

For HTML conversion it is working perfectly. Is it possible to achieve the same result (embed document) inside a PDF? I have an XSLT for pdf generation but have been unsuccessful at accomplishing the same result.

I have tried add-ons for Apache FOP like this one (PDF Image Support):

 <fox:external-document src="my-doc.pdf"/>

Apparently it is only for images.

Any hints?

Thank you

Mammoth answered 20/5, 2011 at 18:54 Comment(0)
M
7

So I found it is possible using my previous solution, I was just not doing it right. Check it out here: FOP Extension

Also, here is an example of how to use it:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="A4">
            <fo:region-body/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="A4">
        <fo:flow flow-name="xsl-region-body">
            <fo:block-container>
                <fo:block>Hello W3Schools</fo:block>    
                <fo:block>
                </fo:block>
            </fo:block-container>
        </fo:flow>
    </fo:page-sequence>

    <fox:external-document content-type="pdf" src="../example_file/test.pdf"/>
</fo:root>
Mammoth answered 20/5, 2011 at 21:37 Comment(3)
Oh, and I can only embed the pdf at the end or beginning of the master pdf.Mammoth
If you can use it, XEP (RenderX) will allow you to embed a PDF using fo:external-graphic.Winser
Maybe useful: You can also reference an URI in the src-attribute like so: <fox:external-document content-type="pdf" src="url(http://www.someplace.de/somedocument.pdf"/>Hiroko
C
1

code-gijoe a very late response since I just started using fop, but you can do (with FOX extension)

    <fo:block-container absolute-position="absolute">
        <fo:block>
            <fo:external-graphic src="src/main/resources/externalpdf/test.pdf"/>
            <fo:block-container absolute-position="absolute" left="0pt" top="100pt" right="200pt" bottom="270pt">
                <fo:block font-weight="bold" font-size="15pt" border="{$border}" text-align="center" line-height="18pt" font-style="italic">
                    Hello
                </fo:block>
            </fo:block-container>
        </fo:block>
    </fo:block-container>

to embed it to the same page and overlay it with some text

Celt answered 9/2, 2018 at 15:26 Comment(1)
Did you manage to add multi page pdf ? Only the first page is added in my solution; I can't find a way to address this problem.Milagrosmilam
I
1

@Bancarel According to the Docs you can choose a particular page: something like
<fo:external-graphic src="my-doc.pdf#page=1"/>
That was found on the Apache™ FOP: PDF Images Plug-In page: Link

Interminable answered 18/9, 2021 at 6:38 Comment(1)
This is the proper answerPersas

© 2022 - 2024 — McMap. All rights reserved.