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

Add getAttachments to PDFDocument #1242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sverch
Copy link

@sverch sverch commented May 27, 2022

What?

This adds the getAttachments method to get all the attachments from a pdf document.

Why?

This is basically implementing the suggestion in #534 (comment), where the use case was discussed. Mine is that I am looking into how to delete attachments, and this seemed like a prerequisite for that.

How?

I mostly copied the code from comments in that issue. There's some interesting behavior with save, as the attachments don't show up until after save is called. That's tested and described in the README, just so it's clear that's the behavior, but I don't know if it's desired.

Testing?

Added some unit tests for this function and for attach.

New Dependencies?

N/A

Screenshots

N/A

Suggested Reading?

No, I hadn't seen that (and unfortunately the link is currently a 404). Besides the broken link I appreciate that section and am curious if you know if the spec is still available somewhere.

Anything Else?

I don't know how to do all that great jsfiddle setup, so for the README I just copied the basic example from that issue to start somewhere.

Also, thank you for this project!

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
    • I haven't, but I see "They also require manual inspection of the PDFs they create to make sure nothing is broken", which makes me wonder about adding something there for this change which is about reading files rather than writing them.
  • I ran the integration tests.
    • I'm getting "cannot find module" errors when I try them.
  • I tested my changes in Node, Deno, and the browser.
    • See above about this being read only.
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
    • See above about this being read only.
  • I added/updated doc comments for any new/modified public APIs.
    • I added a bit of documentation, open to suggestions if there's more that someone would want to know though.
  • My changes work for both new and existing PDF files.
    • This is where the weird save behavior comes in, so I'm not sure.
  • I ran the linter on my changes.

This adds the getAttachments method to get all the attachments from a
pdf document.

This is basically implementing the suggestion in
Hopding#534 (comment)

There's some interesting behavior here, as the attachments don't show up
until after save is called. That's tested in the test and described in
the README, just so it's clear that's the behavior.

I don't know how to do all that great jsfiddle setup, so for the README
Ijust copied the basic example from that issue for now.
@pranavburnwal
Copy link

Can we merge this? Need this

+1

@SpinatmitBlub
Copy link

Hello sverch,

is this feature still available? I want to read the data out of a .csv attachment and I think with this feature I can do it.

Thanks in advance and keep up the great work

@sverch
Copy link
Author

sverch commented Dec 4, 2022

@SpinatmitBlub I don't have contributor access to this repository, and it needs one approving review.

There may be more things @Hopding wants to see before this is merged, or he may just be busy with other things.

If you want to use this right now, you'd have to use a custom version of this library based off this branch. I haven't tested it, but it might be something like npm install sverch/pdf-lib#master. See https://docs.npmjs.com/cli/v6/commands/npm-install.

@SpinatmitBlub
Copy link

@SpinatmitBlub I don't have contributor access to this repository, and it needs one approving review.

There may be more things @Hopding wants to see before this is merged, or he may just be busy with other things.

If you want to use this right now, you'd have to use a custom version of this library based off this branch. I haven't tested it, but it might be something like npm install sverch/pdf-lib#master. See https://docs.npmjs.com/cli/v6/commands/npm-install.

Thx for the quick response. I will give it a try and hope that it will work. Otherwise i hope that it will be implemented in the next version.

@NotTheSamAdamsGuy
Copy link

Are there any updates on this? I'd love to see it get merged into the code base.

@beyluta
Copy link

beyluta commented Mar 22, 2023

Truly a great feature. Shame that this library isn't getting the love that it deserves. Great project. But hasn't received any merges since 2021.

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

Successfully merging this pull request may close these issues.

None yet

5 participants