t-houssian / fillpdf

A python library to make filling pdfs much easier
MIT License
134 stars 23 forks source link

issue with pdf flatten #51

Open EthanC-8 opened 11 months ago

EthanC-8 commented 11 months ago

Hey there, bacially i am trying to flatten my pdf using poppler method aka

fillpdfs.flatten_pdf(file_name, file_name, as_images=True)

now issue with the pdf has some bar code images as well issue is it reducses the resoloution which breaks the barcode

it bascially makes the barcode lines blurry which makes it unscanable..

is there a way to flatten because the as_images=False method isn't working..

image

top image is after flatten and bottom is before

darlenepetal commented 9 months ago

this is how i solved this issue personally, as flatten_pdf doesn't quite seem to work properly in my experience (some text will still be editable). i find it better to use pdf2image's convert_from_path() directly.

  1. download poppler-windows: https://github.com/oschwartz10612/poppler-windows
  2. extract to project folder
  3. add to your python header "from pdf2image import convert_from_path"
  4. create variable to store the path of poppler's bin folder
  5. use "image = convert_from_path(outputPath, 500, poppler_path=poppler)" (500 is a higher dpi than the standard that fillpdf uses, i haven't found a way to use an arg of any kind to change the dpi in fillpdf, feel free to use a number other than 500 until the barcode works)
  6. use "image[0].save(outputPath, "PDF")"

this is incredibly slow and probably shit but it does work for me. hopefully it helps at all lol