[PLUG] alternatives for creating scaled, searchable pdf from plain text?

Galen Seitz galens at seitzassoc.com
Tue Jul 15 00:35:44 UTC 2025


On 7/10/25 14:15, King Beowulf wrote:
> On 7/9/25 11:00, Galen Seitz wrote:
>> Hi,
>>
>> I often create a pdf of sdiff output using a command like this:
>>
>> sdiff -w100 old new | enscript -o sdiff.pdf
>>
>> This works okay, but the resulting pdf is not searchable.  Can someone
>> suggest an alternative that will properly scale the wide output (-w100)
>> to a letter size pdf, yet retain the ability to search for text strings?
>>
> Hello Galen,
> 
> 
> If you have a CUPS installed, you can print text file to pdf. This pdf
> will be text searchable.  At least using okular pdf reader.
> 
> https://www.cups.org/doc/options.html
> 
> You can apply paper size etc to the CLI lp/lpr.  I just tested the GUI
> print version Xfce mousepad.
> 
> This converts a text to pdf that okular can search:
> 
> enscript --output=- bond_movies.txt | ps2pdf - bond_movies.pdf

Thanks to everyone for all of the suggestions.

Using ps2pdf, although convoluted, does accomplish what I want.  The 
following command line will create a searchable pdf from the 160 
character wide sdiff output.  The -r option to enscript selects 
landscape mode, and changing the font to Courier9 allows for 160 
characters in landscape mode without wrapping.  ps2pdf creates a 
searchable pdf from the postscript output, which is not the case if 
enscript creates the pdf directly.

sdiff -w160 netlist-old.txt netlist.txt | enscript -r -f Courier9 -p - | 
ps2pdf - sdiff.pdf

I briefly experimented with using the soffice command (libreoffice from 
the command line), but it doesn't support taking input from stdin, which 
kind of defeats the purpose here.


And to answer Tomas' questions...

> 1. Why do you convert text output of sdiff to pdf? Txt seems portable
> enough, no?
In retrospect, yes.  In the future, I'll just save the sdiff output to a 
txt file, then use enscript if I want to print it.  I think I initially 
went down this path because I knew I wanted to print the sdiff output. 
It was only later that I wanted to search it.

> 2. Assuming you really need the pdf - you could save it as text, then load
> it to libre office, format it as needed, and export it as pdf
I'm comparing two netlists, so bringing the sdiff output into a word 
processor just feels wrong.

> 3. You could use libreoffice from command line like: libreoffice
> --convert-to pdf file.txt It will use default page format and font.
See the comment about soffice above.


BTW, in case you're wondering whether I'm really printing out an entire 
netlist, the answer is no.  I left out of the pipeline the grep command 
(grep -B1 '[<>|]') that I use to only see the relevant diffs.

And for those who don't what a netlist is:
<https://en.wikipedia.org/wiki/Netlist>


galen
-- 
Galen Seitz
galens at seitzassoc.com



More information about the PLUG mailing list