News for hackers. Stuff that matters.

Ask HN: Best way to convert PDFs to other file formats?

Some types of PDFs have always been a challenge to convert to other file formats like Word or plain text. I've had many go from perfectly formatted PDFs to useless text when converted.

Has anyone found a good converter? In the age of AI you would think that there would be a fool proof way to do it.

( 3 comments | 2 points | on HN )
Re:Ask HN: Best way to convert PDFs to other file formats? by bluehorseray on Friday May 19, 2023 @01:21AM (#35998081)
pdftotext in python works pretty well:

  import pdftotext
  import sys
  
  with open("test.pdf", "rb") as f:
    pdf = pdftotext.PDF(f,physical=True)

  for page in pdf:
    print(page)
Re:Ask HN: Best way to convert PDFs to other file formats? by simonblack on Friday May 19, 2023 @08:04PM (#36008168)
As an extra bit of help, use the '-layout' option to give you a formatted text document that's laid out the same way as the original .pdf document:

       pdftotext -layout my_file.pdf
will produce 'my_file.txt',

Note also that the .pdf must contain TEXT as such. An IMAGE of text will not work as expected with 'pdftotext'.

Re:Ask HN: Best way to convert PDFs to other file formats? by sarcasmatwork on Friday May 19, 2023 @12:59AM (#35997946)
calibre? (https://calibre-ebook.com)

You can convert various types of ebooks.