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

Attach/Detach to/from PDFs #12

Open
sebastianludwig opened this issue Dec 15, 2024 · 3 comments
Open

Attach/Detach to/from PDFs #12

sebastianludwig opened this issue Dec 15, 2024 · 3 comments

Comments

@sebastianludwig
Copy link

Hey, awesome project! Will probably end up using it some time soon. In the README you write

This does not contain any code to attach the XML to a PDF file, mainly because I have yet to find a ruby library to do that.

HexaPDF can do that.

Attaching is easy. See the documentation or unit tests.

Extraction:

irb(main):001> require "hexapdf"
=> true
irb(main):002> pdf = HexaPDF::Document.open("corpus-master/ZUGFeRDv2/correct/Mustangproject/MustangGnuaccountingBeispielRE-20190610_507.pdf")
=> <HexaPDF::Document:21960>
irb(main):003> pdf.files
=> #<HexaPDF::Document::Files:0x000000010337fbf0 @document=<HexaPDF::Document:21960>>
irb(main):004> pdf.files.each { |f| puts f }
#<HexaPDF::Type::FileSpecification:0x000000010337cc70>
=> #<HexaPDF::Document::Files:0x000000010337fbf0 @document=<HexaPDF::Document:21960>>
irb(main):005> pdf.files.first
=> #<HexaPDF::Type::FileSpecification [8, 0] value={:Type=>:Filespec, :F=>"zugferd-invoice.xml", :AFRelationship=>:Alternative, :UF=>"zugferd-invoice.xml", :Desc=>"Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)", :EF=>#<HexaPDF::Reference [17, 0]>}>
irb(main):006> pdf.files.first.embedded_file_stream
=> #<HexaPDF::Type::EmbeddedFile [107, 0] value={:Length=>10338, :Type=>:EmbeddedFile, :Subtype=>:"text/xml", :Params=>#<HexaPDF::Reference [239, 0]>}>

and then

fiber = obj.embedded_file_stream.stream_decoder
while fiber.alive? && (data = fiber.resume)
    file << data
end

I don't think it should be secretariat's job to do that, just wanted to let you (and others) know.

@halfbyte
Copy link
Owner

halfbyte commented Jan 8, 2025

Hi @sebastianludwig Thanks for the pointer! I've been scanning rubygems.org again when I did the push for the latest ZUGFeRD versions but did not find HexaPDF. I think it would be useful to add this functionality to this library, but it'll probably take me a couple of weeks to get to that.

@sebastianludwig
Copy link
Author

Hey, I understand the temptation but would argue that it's best left to the user of this library. Either they are already using HexaPDF, then an example in the README would be all they need. Or they are using a different PDF library in which case ruby-secretariat would add another PDF library as dependency (not a lightweight one - HexaPDF depends on OpenSSL 🙄) just for the attach functionality. Also not being required to maintaining compatibility with HexaPDF will also reduce the long term maintenance effort and give you more time to focus on the core functionality. </2c> ;-)

@mck9
Copy link

mck9 commented Jan 31, 2025

HexaPDF is AGPL, so not everybody would like that. Like @sebastianludwig said, PDF handling should not be part of this lib.

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