[ 
https://issues.apache.org/jira/browse/FOP-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17833714#comment-17833714
 ] 

BlueMountain edited comment on FOP-3173 at 4/3/24 6:50 PM:
-----------------------------------------------------------

hi peter,

thank you for your prompt reply.

i actually made the test case work using ...

```
{color:#9e880d}@Test{color}{color:#0033b3}public void 
{color}{color:#00627a}testAddEmbeddedFileDash {color}() {color:#0033b3}throws 
{color}{color:#000000}IFException {color}{
{color:#000000}  PDFDocumentHandler docHandler {color}= {color:#0033b3}new 
{color}PDFDocumentHandler({color:#0033b3}new 
{color}IFContext({color:#871094}ua{color}));
{color:#000000}  docHandler{color}.setFontInfo({color:#0033b3}new 
{color}FontInfo());
{color:#000000}  ByteArrayOutputStream out {color}= {color:#0033b3}new 
{color}ByteArrayOutputStream();
{color:#000000}  docHandler{color}.setResult({color:#0033b3}new 
{color}StreamResult({color:#000000}out{color}));
{color:#000000}  docHandler{color}.startDocument();
{color:#000000}  docHandler{color}.startPage({color:#1750eb}0{color}, 
{color:#067d17}""{color}, {color:#067d17}""{color}, {color:#0033b3}new 
{color}Dimension());
{color:#000000}  String unicodeFilename {color}= 
{color:#067d17}"filename#1.txt"{color};
{color:#000000}  docHandler{color}.handleExtensionObject(
    {color:#0033b3}new   
{color}PDFEmbeddedFileAttachment({color:#000000}unicodeFilename{color}, 
{color:#067d17}"src"{color}, {color:#067d17}"desc"{color})
  );
  *{color:#8c8c8c}// if the file name contains characters that are 
considered{color}{color:#8c8c8c}  // as fragment or query, the 
'embedded-[file:$|file:///$]{filename}{color}{color:#8c8c8c}  // will fail at 
returning the actual file name{color}{color:#8c8c8c}  // we are relying, here, 
on the URI to perform actual{color}{color:#8c8c8c}  // character 
conversion{color}{color:#8c8c8c}  {color}{color:#0033b3}final 
{color}{color:#000000}String uri{color};*
  *{color:#0033b3}try {color}{*
    *{color:#000000}URI tmp {color}= {color:#0033b3}new {color}URI 
({color:#067d17}"embedded-file"{color}, {color:#000000}unicodeFilename{color}, 
{color:#0033b3}null{color});*
    *{color:#000000}uri {color}= {color:#000000}tmp{color}.toString ();*
  *}*
  *{color:#0033b3}catch {color}({color:#000000}URISyntaxException e{color}) {*
    *{color:#0033b3}throw new {color}IllegalStateException 
({color:#000000}e{color});*
  *}*
{color:#000000}  docHandler{color}.getDocumentNavigationHandler().renderLink(
{color:#0033b3}    new {color}Link({color:#0033b3}new 
{color}URIAction({*}{color:#000000}uri{color}{*}, {color:#0033b3}false{color}), 
{color:#0033b3}new {color}Rectangle())
  );
{color:#000000}  docHandler{color}.endDocument();
}
```

but actually, even doing some change in the original program to test the file, 
i was still getting errors.

the way embedded content was used in pdf was:
1- include it in the list of pdf attachments
2- include in the page, 1 link for each embedded attachment.

in order to allow access to these attachments either browsing the document, 
page by page ... or accessing directly the list of pdf embedded files from the 
pdf viewer application.

the fop was looking like:

```
{color:#000000} {color}{color:#800000}<fo:layout-master-set>
...{color}
{color:#000000} {color}{color:#800000}<fo:declarations>{color}
{color:#000000} {color}{color:#800000}<pdf:embedded-file{color}{color:#000000} 
{color}{color:#e50000}filename{color}{color:#000000}={color}{color:#0000ff}"error#1.log"{color}{color:#000000}
 
{color}{color:#e50000}description{color}{color:#000000}={color}{color:#0000ff}"some
 error"{color}{color:#000000} 
{color}{color:#e50000}src{color}{color:#000000}={color}{color:#0000ff}"url([file:/Users/thebluemountain/tmp/error%231.log|file:///Users/thebluemountain/tmp/error%231.log])"{color}{color:#800000}/>{color}
{color:#000000} {color}{color:#800000}</fo:declarations>{color}
...

{color:#000000} {color}{color:#800000}<fo:block>{color}
{color:#000000} {color}{color:#800000}<fo:basic-link{color}{color:#000000} 
{color}{color:#e50000}color{color}{color:#000000}={color}{color:#0000ff}"blue"{color}{color:#000000}
 
{color}{color:#e50000}external-destination{color}{color:#000000}={color}{color:#0000ff}"url(embedded-[file:error#1.log|file:///error#1.log])"{color}{color:#800000}>{color}{color:#000000}error#1.log{color}{color:#800000}</fo:basic-link>{color}
{color:#000000} {color}{color:#800000}</fo:block>
{color}```

the reported error was dumping stack trace that was carying:
java.lang.IllegalStateException: {+}No embedded file with name *error* 
present{+}.
    at 
org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
    at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
    at 
org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
    at 
org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
    at 
org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:594)
    at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:123)

i was thinking the issue was comming from the <pdf:embedded-file> and it's 
filename ...
but the actual cause of the error was the link:

```

{color:#000000} {color}{color:#800000}<fo:block>{color}
{color:#000000} {color}{color:#800000}<fo:basic-link{color}{color:#000000} 
{color}{color:#e50000}color{color}{color:#000000}={color}{color:#0000ff}"blue"{color}{color:#000000}
 
{color}{color:#e50000}external-destination{color}{color:#000000}={color}{color:#0000ff}"{*}url(embedded-[file:error#1.log|file:///error#1.log]){*}"{color}{color:#800000}>{color}{color:#000000}error#1.log{color}{color:#800000}</fo:basic-link>{color}
{color:#000000} {color}{color:#800000}</fo:block>
{color}```

i was able to correct the problem, by generating ...

```

{color:#000000} {color}{color:#800000}<fo:block>{color}
{color:#000000} {color}{color:#800000}<fo:basic-link{color}{color:#000000} 
{color}{color:#e50000}color{color}{color:#000000}={color}{color:#0000ff}"blue"{color}{color:#000000}
 
{color}{color:#e50000}external-destination{color}{color:#000000}={color}{color:#0000ff}"{*}embedded-[file:error%231.log|file:///error%231.log]{*}"{color}{color:#800000}>{color}{color:#000000}error#1.log{color}{color:#800000}</fo:basic-link>{color}
{color:#000000} {color}{color:#800000}</fo:block>
{color}```

i therefore guess the issue can be closed:
{*}Q{*}: shall i close it myself ?

note: however, it would be good to keep some test that exhibits what is 
required to have the link working for other user that might encounter the same 
issue.

thank you, again, for your help, peter,


was (Author: JIRAUSER304810):
hi peter,

thank you for your prompt reply.

i actually made the test case work using ...

```
{color:#9e880d}@Test
{color}{color:#0033b3}public void {color}{color:#00627a}testAddEmbeddedFileDash 
{color}() {color:#0033b3}throws {color}{color:#000000}IFException {color}{
{color:#000000}  PDFDocumentHandler docHandler {color}= {color:#0033b3}new 
{color}PDFDocumentHandler({color:#0033b3}new 
{color}IFContext({color:#871094}ua{color}));
{color:#000000}  docHandler{color}.setFontInfo({color:#0033b3}new 
{color}FontInfo());
{color:#000000}  ByteArrayOutputStream out {color}= {color:#0033b3}new 
{color}ByteArrayOutputStream();
{color:#000000}  docHandler{color}.setResult({color:#0033b3}new 
{color}StreamResult({color:#000000}out{color}));
{color:#000000}  docHandler{color}.startDocument();
{color:#000000}  docHandler{color}.startPage({color:#1750eb}0{color}, 
{color:#067d17}""{color}, {color:#067d17}""{color}, {color:#0033b3}new 
{color}Dimension());
{color:#000000}  String unicodeFilename {color}= 
{color:#067d17}"filename#1.txt"{color};
{color:#000000}  docHandler{color}.handleExtensionObject(
    {color:#0033b3}new   
{color}PDFEmbeddedFileAttachment({color:#000000}unicodeFilename{color}, 
{color:#067d17}"src"{color}, {color:#067d17}"desc"{color})
  );
  *{color:#8c8c8c}// if the file name contains characters that are considered
{color}{color:#8c8c8c}  // as fragment or query, the 'embedded-file:${filename}
{color}{color:#8c8c8c}  // will fail at returning the actual file name
{color}{color:#8c8c8c}  // we are relying, here, on the URI to perform actual
{color}{color:#8c8c8c}  // character conversion
{color}{color:#8c8c8c}  {color}{color:#0033b3}final 
{color}{color:#000000}String uri{color};*
  *{color:#0033b3}try {color}{*
    *{color:#000000}URI tmp {color}= {color:#0033b3}new {color}URI 
({color:#067d17}"embedded-file"{color}, {color:#000000}unicodeFilename{color}, 
{color:#0033b3}null{color});*
    *{color:#000000}uri {color}= {color:#000000}tmp{color}.toString ();*
  *}*
  *{color:#0033b3}catch {color}({color:#000000}URISyntaxException e{color}) {*
    *{color:#0033b3}throw new {color}IllegalStateException 
({color:#000000}e{color});*
  *}*
{color:#000000}  docHandler{color}.getDocumentNavigationHandler().renderLink(
{color:#0033b3}    new {color}Link({color:#0033b3}new 
{color}URIAction({*}{color:#000000}uri{color}{*}, {color:#0033b3}false{color}), 
{color:#0033b3}new {color}Rectangle())
  );
{color:#000000}  docHandler{color}.endDocument();
}```

but actually, even doing some change in the original program to test the file, 
i was still getting errors.

the way embedded content was used in pdf was:
1- include it in the list of pdf attachments
2- include in the page, 1 link for each embedded attachment.

in order to allow access to these attachments either browsing the document, 
page by page ... or accessing directly the list of pdf embedded files from the 
pdf viewer application.

the fop was looking like:

```

{color:#000000} {color}{color:#800000}<fo:layout-master-set>
...
{color}
{color:#000000} {color}{color:#800000}<fo:declarations>{color}
{color:#000000} {color}{color:#800000}<pdf:embedded-file{color}{color:#000000} 
{color}{color:#e50000}filename{color}{color:#000000}={color}{color:#0000ff}"error#1.log"{color}{color:#000000}
 
{color}{color:#e50000}description{color}{color:#000000}={color}{color:#0000ff}"some
 error"{color}{color:#000000} 
{color}{color:#e50000}src{color}{color:#000000}={color}{color:#0000ff}"url(file:/Users/thebluemountain/tmp/error%231.log)"{color}{color:#800000}/>{color}
{color:#000000} {color}{color:#800000}</fo:declarations>{color}
...

{color:#000000} {color}{color:#800000}<fo:block>{color}
{color:#000000} {color}{color:#800000}<fo:basic-link{color}{color:#000000} 
{color}{color:#e50000}color{color}{color:#000000}={color}{color:#0000ff}"blue"{color}{color:#000000}
 
{color}{color:#e50000}external-destination{color}{color:#000000}={color}{color:#0000ff}"url(embedded-file:error#1.log)"{color}{color:#800000}>{color}{color:#000000}error#1.log{color}{color:#800000}</fo:basic-link>{color}
{color:#000000} {color}{color:#800000}</fo:block>{color}```

the reported error was dumping stack trace that was carying:
java.lang.IllegalStateException: {+}No embedded file with name *error* 
present{+}.
    at 
org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
    at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
    at 
org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
    at 
org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
    at 
org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:594)
    at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:123)

i was thinking the issue was comming from the <pdf:embedded-file> and it's 
filename ...
but the actual cause of the error was the link:

```

{color:#000000} {color}{color:#800000}<fo:block>{color}
{color:#000000} {color}{color:#800000}<fo:basic-link{color}{color:#000000} 
{color}{color:#e50000}color{color}{color:#000000}={color}{color:#0000ff}"blue"{color}{color:#000000}
 
{color}{color:#e50000}external-destination{color}{color:#000000}={color}{color:#0000ff}"{*}url(embedded-file:error#1.log){*}"{color}{color:#800000}>{color}{color:#000000}error#1.log{color}{color:#800000}</fo:basic-link>{color}
{color:#000000} {color}{color:#800000}</fo:block>{color}```

i was able to correct the problem, by generating ...

```

{color:#000000} {color}{color:#800000}<fo:block>{color}
{color:#000000} {color}{color:#800000}<fo:basic-link{color}{color:#000000} 
{color}{color:#e50000}color{color}{color:#000000}={color}{color:#0000ff}"blue"{color}{color:#000000}
 
{color}{color:#e50000}external-destination{color}{color:#000000}={color}{color:#0000ff}"{*}embedded-file:error%231.log{*}"{color}{color:#800000}>{color}{color:#000000}error#1.log{color}{color:#800000}</fo:basic-link>{color}
{color:#000000} {color}{color:#800000}</fo:block>{color}```

i therefore guess the issue can be closed:
{*}Q{*}: shall i close it myself ?

note: however, it would be good to keep some test that exhibits what is 
required to have the link working for other user that might encounter the same 
issue.

thank you for your help, peter,

> cannot include attachment whose name contains hash ('#') in the name
> --------------------------------------------------------------------
>
>                 Key: FOP-3173
>                 URL: https://issues.apache.org/jira/browse/FOP-3173
>             Project: FOP
>          Issue Type: Bug
>          Components: fo/unqualified
>    Affects Versions: 2.9
>            Reporter: BlueMountain
>            Priority: Major
>         Attachments: PDFAttachmentTestCase.java
>
>
> hi,
> we are relying on the fop to generate PDF given data held in database + file 
> storage.
> we need to represent some ( file.name, file.data) as a pdf embedded 
> attachment.
> some users have encountered issue when the file.name value carries hash sign 
> ('#')
> upon generating the pdf, an exception is thrown about missing attachment name.
> I have added a new test to the  PDFAttachmentTestCase class (see attachment) 
> to reproduce the issue.
> The added test that generates the error is:
> @Test
> public void testAddEmbeddedFileDash () throws IFException {
> PDFDocumentHandler docHandler = new PDFDocumentHandler(new IFContext(ua));
> docHandler.setFontInfo(new FontInfo());
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> docHandler.setResult(new StreamResult(out));
> docHandler.startDocument();
> docHandler.startPage(0, "", "", new Dimension());
> docHandler.handleExtensionObject(new 
> PDFEmbeddedFileAttachment("filename#1.txt", "src", "desc"));
> // issue occurs at this line
> *docHandler.getDocumentNavigationHandler().renderLink(new Link(*
>  *new URIAction("embedded-file:filename#1.txt", false), new Rectangle()));*
> docHandler.endDocument();
> }
>  
> running the command: 
> mvn test -pl fop-core -Dtest=PDFAttachmentTestCase
> I get the following output:
> Running org.apache.fop.pdf.PDFAttachmentTestCase
> Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.15 sec <<< 
> FAILURE! - in org.apache.fop.pdf.PDFAttachmentTestCase
> testAddEmbeddedFileDash(org.apache.fop.pdf.PDFAttachmentTestCase)  Time 
> elapsed: 0.003 sec  <<< ERROR!
> {*}java.lang.IllegalStateException: No embedded file with name filename 
> present{*}.
> at org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
> at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
> at 
> org.apache.fop.pdf.PDFAttachmentTestCase.testAddEmbeddedFileDash(PDFAttachmentTestCase.java:119)
>  



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

Reply via email to