chromic_pdf icon indicating copy to clipboard operation
chromic_pdf copied to clipboard

Add info option to print_to_pdf/2

Open maltoe opened this issue 2 years ago • 2 comments

Now that we're calling Ghostscript from print_to_pdf/2 (optionally, for multiple sources), we may as well benefit from it.

  • Make the embedding of metadata pieces a separate logic in Ghostscript*
    • While you're at it, refactor the GhostscriptWorker/Interface/Impl mess
  • Move the info_option to pdf_option and add it as optional flag to print_to_pdf/2
    • Mention in the docs that this requires ghostscript
    • And writing the file to disk (mention this for the "join multiple sources" section as well)

maltoe avatar Dec 22 '22 09:12 maltoe

  1. Split the postscript snippet (PDFA_def_ext.ps.eex or so)
  2. Optionally render the postscript info snippet in the GhostscriptWorker.join/2 function
  3. Render both snippets in GhostscriptWorker.convert/2

maltoe avatar Jan 11 '23 09:01 maltoe

With the limited knowledge I have about the code base, I tried to come up with a (high level) plan about how to "smoothly" introduce a unified/smart print_to_pdf/3 that allows to print both pdf or pdfa files.

Implementation Details

Version ChromicPDF::API

  • Add lib/chromic_pdf/api/v1/
    1. Add behaviour.ex specifying its behaviour
    2. Add impl.ex (or a better name if you can think of one) and move the code from ChromicPDF::API here.
    3. Update ChromicPDF::API to delegate function calls to ChromicPDF::API::V1::Impl

Add V2

The goal of the second version is to have a unified/smart print_to_pdf/3, capable to print both pdf and pdfa files based on the given function parameters. This version is also smart enough to know when to use Ghoshscript.

  • Add lib/chromic_pdf/api/v2/

    1. Add behaviour.ex specifying its behaviour

    2. Add impl.ex (or a better name if you can think of one) and move the code from ChromicPDF::API here.

      How should a unified print_to_pdf looks like?

      The key is to have a well defined type for the opts that can be passed.

      For example:

      • any options related to pdfa files could be passed through a archival key.
      • any related to annotating a the file (author, title etc), could be passed through annotations key.
      • and so on ...

      The presence of one (or a combination) of the top level key of the opts map suffice to determine wether a pdf or a pdfa file should be printed and wether goshscript should be used or not.

    ```elixir
    @type opts :: {
         archival: map() | true,
         annotations: { title: atom() ... }
    }
    ```
    
    1. Update ChromicPDF::API to delegate function calls to ChromicPDF::API::V2::Impl.

ammancilla avatar Jan 11 '23 11:01 ammancilla