Embed arbitrary files into a PDF via "unoconv"

Discussion in 'Networking and Security' started by spy, Dec 6, 2022.

  1. :) That all sounds like good things.

    The script just bundles all the text; I wrote it that way on purpose, so you could use whichever PDF converter you wanted to. If the one you're using doesn't like STDIN, well - there's no exact equivalent to 'mktemp(3)' in the shell (auto-delete on exit), but this should do the job:

    Code:
     (trap 'rm -f $X' EXIT; X=$(mktemp); pdfgen demo.py>$X; pdfWhatever $X>demo.pdf)
    
     
    #21     Dec 9, 2022
  2. spy

    spy

    I noticed this and I like that you've bundled all the text. This eliminates the need to piece together the script manually. From a pedagogic perspective it may detract a little but I don't want to split hairs.

    However, I don't see how a reader couldn't follow the original post and not simply swap occurrences of "unoconv" with "text2pdf". You see what I mean? I other words, there was never a dependency on "unoconv" specifically AFAICT.

    Well, okay again, I may be approaching this from an instructional point of view as some small changes would be needed since I don't think "text2pdf" takes input from a file via argument. Again, I want to avoid splitting hairs.

    Yeah, this is basically what I needed to do in order to use "unoconv". Which is, by all accounts, "unoconvs" fault... I think. But, as Steven Wright once noted so acutely, "you can't have everything, where would you put it?"

    I think, in reality, if one wants to use unoconv vs text2pdf some small differences may be desired in the whole integration just for the sake of convenience. Or your mktemp suggestion could be put in a higher level script. But, at some point trying to cover all the bases does start to get exceptionally, uh... messy (imho)? For lack of a better word.

    If only the unoconv people could co-operate with the txt2pdf people and iron out each other's issues ;-)
     
    Last edited: Dec 9, 2022
    #22     Dec 9, 2022
  3. Easy enough to put it all in the same script and make the PDF converter an argument to it - you'd just have to use 'command' to run it. But that "messiness" is why the philosophy of UNIX has "small is beautiful" as its primary postulate... there's a certain Zen aspect to that, and over the years, I've found that it's better to build small and pipe the pieces together. IMO, Mike Gancarz got it right.

    https://en.wikipedia.org/wiki/Unix_philosophy

    Also:

    The handles of a craftsman's tools bespeak an absolute simplicity, the plainest forms affording the greatest range of possibilities for the user's hand. That which is overdesigned, too highly specific, anticipates outcome; the anticipation of outcome guarantees, if not failure, the absence of grace.
    -- William Gibson

    :)
     
    #23     Dec 9, 2022
    spy likes this.
  4. spy

    spy

    Amen!
     
    #24     Dec 9, 2022
  5. It does.

    Code:
    $ text2pdf -h
    
    text2pdf [options] [filename]
    
      text2pdf makes a 7-bit clean PDF file (version 1.1) from any input file.
      It reads from standard input or a named file, and writes the PDF file
      to standard output.
    
      There are various options as follows:
    
      -h            show this message
      -f<font>      use PostScript <font> (must be in standard 14, default: Courier)
      -I            use ISOLatin1Encoding
      -s<size>      use font at given pointsize (default 10)
      -v<dist>      use given line spacing (default 12 points)
      -l<lines>     lines per page (default 60, determined automatically
                    if unspecified)
      -c<chars>     maximum characters per line (default 80)
      -t<spaces>    spaces per tab character (default 8)
      -F            ignore formfeed characters (^L)
      -A4           use A4 paper (default Letter)
      -A3           use A3 paper (default Letter)
      -x<width>     independent paper width in points
      -y<height>    independent paper height in points
      -2            format in 2 columns
      -L            landscape mode
    
      Note that where one variable is implied by two options, the second option
      takes precedence for that variable. (e.g. -A4 -y500)
      In landscape mode, page width and height are simply swapped over before
      formatting, no matter how or when they were defined.
    
    text2pdf v1.1 (c) Phil Smith, 1996
     
    #25     Dec 9, 2022
    spy likes this.
  6. spy

    spy

    It's not open-source though. Or at least, maybe it's not... the jury seems to be out on that. And, I need to minimize my legal expenses.

    Just having some fun :D

    Honestly, if I had my complete druthers I would prefer text2pdf. A utf-8/encoding fix (w.r.t. the backtick problem) would be nice though and it should live in my distro's software repo. A big banner at the top that said it was BSD licensed wouldn't be bad.

    Which actually makes me wonder... what is your preferred distribution lately? Wait! Maybe we need another thread for that.
     
    Last edited: Dec 9, 2022
    #26     Dec 9, 2022
  7. spy

    spy

    This is the reason. Duh!
     
    #27     Dec 9, 2022