0

I have been trying to convert a pdf to an image and display on a tkinter canvas. I have it working but every time i convert a pdf i get this error(I borrowed this code from here (PDF Viewer for Python Tkinter). Is there anyway to just set it to 300DPI? or better yet why is this happening and what can i do about it? I have searched for hours trying to find other convert pdf to image solutions and came up with nothing I could figure out easily(I am quite new to python).

pypdfocr issue: 'pdfimages' is not recognized as an internal or external command, operable program or batch file. WARNING: Could not execute pdfimages to calculate DPI (try installing xpdf or poppler?), so defaulting to 300dpi

import pypdfocr.pypdfocr_gs as pdfImg
from PIL import Image, ImageTk
import Tkinter as tk
import ttk

import glob, os

root=tk.Tk()

__f_tmp = glob.glob(pdfImg.PyGs({}).make_img_from_pdf("1.pdf")[1])[0]
   #                             ^ this is needed for an "default"-Config
__img=Image.open(__f_tmp)



__tk_img = ImageTk.PhotoImage(__img.resize((800,1000), Image.ANTIALIAS))


ttk.Label(root, image=__tk_img).grid()

__img.close()
os.remove(__f_tmp)

root.mainloop()
Community
  • 1
  • 1
Mathieas
  • 5
  • 5
  • Have you tried "installing xpdf or poppler" as the error message helpfully suggests? – ChrisGPT was on strike Jan 20 '16 at 01:41
  • @Chris : I tried and failed. I could not find an .exe to install either. I did find a few binaries but in truth i was unsure what to do with them. I read a few places that building these for windows was difficult. I am working under windows. – Mathieas Jan 20 '16 at 01:46
  • Well, you'll have to install one of them. Maybe this question will help? https://stackoverflow.com/questions/18381713/how-to-install-poppler-on-windows – ChrisGPT was on strike Jan 20 '16 at 01:47
  • @Chris, thank you very much. I did find this before posting here and even downloaded the poppler windows 0.37. The issue is it looks like a compiled program. How would i make my python program aware of these executables? – Mathieas Jan 20 '16 at 01:51
  • It looks like you actually need the `pdfimages` program, which is included in the `poppler-utils` package on my Ubuntu system. Unfortunately, it doesn't seem to be included in the list of releases from that question. I don't have a Windows machine available for testing at the moment, and I generally avoid installing code from strange resources, but the [`.7z` archive on this page](http://blog.alivate.com.au/poppler-windows/) seems to include it. Make sure to add it to your `%PATH%` and try again. You may have to ask `pypdfocr` to use `pdfimages.exe` instead of `pdfimages` somehow. – ChrisGPT was on strike Jan 20 '16 at 02:01
  • OK so i went into the pypdffocr_gs.py and found there it references pdfimages. I am now trying to find a way to point to my pdfimages.exe that i have placed within my python program folder - no luck so far. Also, I am embarrassed to say I have very little experience setting the %PATH% environmental variables. I did it for python when i installed and that is it. Any additional instruction would be most appreciated. – Mathieas Jan 20 '16 at 02:34

0 Answers0