Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDAnnotationFileAttachment support #508

Closed
lindamarieb opened this issue Jul 7, 2020 · 8 comments
Closed

PDAnnotationFileAttachment support #508

lindamarieb opened this issue Jul 7, 2020 · 8 comments

Comments

@lindamarieb
Copy link

Is there any way to indicate that an anchor is a link to an attached file?

I can add annotations manually in my Java code to the attachment using PDAnnotationFileAttachment but I need to place the links in my html.

@syjer
Copy link
Contributor

syjer commented Jul 8, 2020

Hi @lindamarieb , as far as I know, currently there is no support for this feature, unfortunately.

I'll have a look and try to provide a pull request.

@syjer
Copy link
Contributor

syjer commented Jul 8, 2020

I did a first prototype, it's a little bit viewer dependent:

(note: I've been able to hide the icon in Evince, sumatrapdf and Adobe reader)

  • embedded pdf viewer from chrome and mac os: does not work, you see the text ("test") but it does nothing on click
  • evince (pdf viewer from gnome, linux), it works, but as you can see the text is hidden by the icon:
    Screenshot from 2020-07-08 14-53-15
  • embedded viewer in edge/ie (windows):
    Capture_png
  • sumatrapdf (windows):
    Capture2_png
  • adobe:
    Capture_3

It does not seems possible to hide the icon as far as I know. It's a little bit ugly unfortunately.

@syjer
Copy link
Contributor

syjer commented Jul 8, 2020

code: syjer@cdb5076

example of input file:

<html>
<head>
<style>
</style>
</head>
<body>
<a href="https://user-images.githubusercontent.com/498146/86921196-06cbde80-c12b-11ea-8e1b-36fca76c8805.png" data-embed-file="true" data-content-type="application/octet-stream">Test</a>
</body>
</html>

the presence of "data-embed-file" attribute on a a element, will trigger the download of the linked resource (could be a local file, or a custom protocol).

@syjer
Copy link
Contributor

syjer commented Jul 8, 2020

note: I've been able to find a way to generally hide the icon. Only the embedded viewer from ie/edge persist to show it.

@lindamarieb
Copy link
Author

Thanks for the fast response and work on my request @syjer and @danfickle !!

The files I need to attach to my pdf are stored encrypted on AWS S3; they do not have public access. I will need to download them first in order for openhtmltopdf to have access to them for embedding.

I have some questions regarding this:

  1. Will the file:// protocol work in the download attribute for attaching the local files?
  2. What is difference between embedding and attaching?
  3. Will the "embedded" files show up in the attachments panel of the pdf?

@syjer
Copy link
Contributor

syjer commented Jul 14, 2020

hi @lindamarieb :

  1. yes any supported protocol will work. In your case, you could even have a "custom" protocol that will fetch from S3, decrypt and return an InputStream so you don't even need to interact with the file system. (see the useProtocolsStreamImplementation
    public final TFinalClass useProtocolsStreamImplementation(FSStreamFactory factory, Set<String> protocols) {
    )
    2., 3.no idea :), I'll check and let you know if they appear in the attachments panel (I didn't know about that feature)

danfickle added a commit that referenced this issue Jan 21, 2021
Based heavily on code by @syjer whom I'm indebted to. Thanks.

Still todo:
+ Prevent duplicate file embeds. Possibly create a map of uris to PDComplexFileSpecification and reuse if encountered again. I have to peruse the PDF spec to see if this is allowed.
+ Logging on fail.
@danfickle
Copy link
Owner

Support now merged into main branch.

File embed documentation.

@lindamarieb
Copy link
Author

Thank you so much guys! I have not had time to test this, but will do in the near future :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants