Oleksandr created FOP-3290:
------------------------------

             Summary: Issue with <fo:basic-link> to external .pdf files
                 Key: FOP-3290
                 URL: https://issues.apache.org/jira/browse/FOP-3290
             Project: FOP
          Issue Type: Bug
    Affects Versions: 2.11
            Reporter: Oleksandr
         Attachments: broken_pdf_link_example.zip

h3. *Description*

When generating a PDF using XSL-FO, the links to external local {{.pdf}} files 
behave differently from the links to files with another extensions ( .png, .txt 
etc ). In some PDF viewes ( for example in Chrome PDF viewer ) when a user 
clicks such a link the target file is not opened. If the same link points to a 
{{.png or }}{{.txt}} file, it works properly ( the targer file is being opened).
h3. Steps to Reproduce
 # Use the following XSL-FO to generate a PDF:
<fo:basic-link show-destination="new" external-destination="targetFile.pdf">
    Test Link (PDF)
</fo:basic-link>
<fo:basic-link show-destination="new" external-destination="targetFile.png">
    Test Link (PNG)
</fo:basic-link>{{}}
 # Open the resulting PDF in Chrome PDF viewer

 # Click the PNG link (the PNG file is opened, as expected)

 # Click the PDF link

*Actual Result:* the targetFile.pdf file is not opened

*Expected Result:* The targetFile.pdf is opened ( the PDF link behaves like the 
PNG link)

Some PDF viewers handles the PDF link correctly ( for example, Acrobat Reader 
on Windows 10 )
h3. Technical Analysis

The current implementation seems to have a hardcoded "special case" for files 
ending in {{.pdf in }}{{PDFFactory#getExternalAction().}}
It forces creation of a {{PDFGoToRemote}} action of all external .pdf files. 
For all other extensions it returns {{PDFUri}} which works correctly

I've tested other variations of link url, but none of them works for link to 
.PDF file
 * {{{{url('targetFile.pdf')}}}}

 * {{url(&quot;targetFile.pdf&quot;){{{}{}}}}}

 * {{{{file:///targetFile.pdf}}}}

 * {{{{targetFile.pdf#page=1}}}}

 * {{{{etc}}}}

The issue doesn't appears in Apache FOP version 2.7 ( before the following code 
was added to PDFFactory.java

{{if (scheme == null && filename.toLowerCase().endsWith(".pdf")) {}}
{{   scheme = "file";}}
{{}}}

 

Here is the full sample XSL-FO code and the archive with generated PDFs

 

 
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>

    <fo:layout-master-set>
        <fo:simple-page-master master-name="A4" page-height="29.7cm" 
page-width="21cm" margin="2cm">
            <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 font-family="sans-serif" font-size="12pt">

                <fo:block margin-bottom="10pt">
                    1. PDF Link (Expected to open file):
                    <fo:basic-link external-destination="targetFile.pdf" 
color="blue" text-decoration="underline">
                        targetFile.pdf
                    </fo:basic-link>
                </fo:block>

                <fo:block>
                    2. Image Link (Working correctly):
                    <fo:basic-link external-destination="targetFile.png" 
color="blue" text-decoration="underline">
                        targetFile.png
                    </fo:basic-link>
                </fo:block>

            </fo:block>

        </fo:flow>
    </fo:page-sequence>

</fo:root> {code}
 

 

{{{{}}}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to