1

I want to transform images to pdf. I think fpdf is the best package. The version is the latest FPDF 1.7.2. Python version 3.7.2 64 bit.

from fpdf import FPDF
pdf = FPDF() 
pdf.add_page()
pdf.image(r'C:\Users\Bin\Desktop\a\tt.jpg')

An error happened:

RuntimeError: FPDF error: Missing or incorrect image file:
 C:\Users\Bin\Desktop\a\tt.jpg. error: No JPEG marker found

The file directory is correct. When I transform the file to a png, then it works. It does not work with any other file format such jpeg/jpg.How to solve it? This problem Python images to pdf has appeared in stackoverflow. However, all of them does not work for me.

balalala
  • 92
  • 1
  • 10
  • 1
    Sounds like an issue with that specific image. Did you try any other .jpg images? Maybe actually create a jpg image yourself with a graphics app of your choice and try that, just to be sure. – Mike Scotty Jun 25 '19 at 07:58
  • 1
    Did you ask the same question 4 hours ago? https://stackoverflow.com/questions/56746580/python-fpdf-package-error-no-jpeg-marker-found – Mike Scotty Jun 25 '19 at 07:59
  • Yes. Initially I found FPDF doesn't work even if I followed every step as others recommended. Then I found FPDF works for 'PNG' file and I updated my question. – balalala Jun 25 '19 at 09:50
  • I am sure it doesn't work for jpg file. I have tried many times – balalala Jun 25 '19 at 09:57
  • The source file is here. you can have try! [souce file](https://pan.baidu.com/s/10JSwKyMOmMs_rAIt_X2Dnw). The code is `sify`. It's a Chinese website. Let me know if you can't get in @Mike Scotty – balalala Jun 25 '19 at 10:13

1 Answers1

0

I ran into the same problem, for me, it was specific files that did not work. So I re-saved the images as jpg:s in paint and then I could use the file.

I also found that there are a couple of other ways (which I have not tested) that also should fix the problem:

  • A open source project that should fix the error
  • I also found this webpage with a few different solutions
Leo
  • 36
  • 5