Unix & Linux
text-processing pdf imagemagick conversion
Updated Mon, 04 Jul 2022 19:04:24 GMT

How to convert TXT to PDF?


I want to convert .txt files to .pdf. I'm using this:

ls | while read ONELINE; do convert -density 400 "$ONELINE" "$(echo "$ONELINE" | sed 's/.txt/.pdf/g')"; done

But this produces one "error" -- if there's a very long line in the text file, it doesn't get wrapped.

Input text

Screenshot of the input file

Output PDF

Screenshot of the output PDF

--

Also, it would also be great if the output PDF could contain text, instead of images of text.

I have many-many-many TXT files. So don't want to do it by hand. I need an automatic solution, like the one I mentioned above.




Solution

One method is to use CUPS and the PDF psuedo-printer to "print" the text to a PDF file.

Another is to use enscript to encode to postscript and then convert from postscript to PDF using the ps2pdf file from ghostscript package.





Comments (3)



External Links

External links referenced by this document: