Ticket #9842 (closed defect: fixed)

Opened 1 year ago

Last modified 10 months ago

Internal problems of convert during creation of image from PDF file

Reported by: falkb Assigned to: ursaw
Priority: normal Component: GeneralLinkSyntaxPlugin
Severity: normal Keywords:
Cc: Mount, Carey Trac Release: 0.11

Description

My OS is Windows. ImageMagick? is installed properly, means creating the logo on command line works. I use the r11306.

Error: Macro PdfImg(spru198j_programmers_guide.pdf,width=400,page=100,caption="SPRU198j") failed

'PdfImgMacro' object has no attribute 'pdfinput'
[2012-02-22 09:31:49,015 p3116:t3268] formatter.py:720 ERROR: Macro PdfImg(spru198j_programmers_guide.pdf,width=400,page=100,caption="SPRU198j") failed: 
Traceback (most recent call last):
  File "build\bdist.win32\egg\trac\wiki\formatter.py", line 717, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "build\bdist.win32\egg\trac\wiki\formatter.py", line 304, in process
    text = self.processor(text)
  File "build\bdist.win32\egg\trac\wiki\formatter.py", line 291, in _macro_processor
    text)
  File "build\bdist.win32\egg\PdfImg\PdfImg.py", line 88, in expand_macro
    raise TracError( ("Cant display %s"%(self.pdfinput)) )
AttributeError: 'PdfImgMacro' object has no attribute 'pdfinput'

Attachments

adobe_example.png (29.9 kB) - added by ursaw on 02/23/12 12:00:46.
convert /home/uwi/Downloads/adobe_supplement_iso32000.pdf[0]

Change History

02/22/12 14:07:44 changed by ursaw

Works fine for me on Linux.

Can you please set your log Level to debug. You will see the convert command

self.env.log.debug("*** convert command %s ***", cmd )

source:pdfimageplugin/0.11/PdfImg/PdfImg/PdfImg.py#L77

but also correction with r11309

02/22/12 15:22:11 changed by falkb

  • summary changed from 'PdfImgMacro' object has no attribute 'pdfinput' to Macro doesn't work on Windows.

I've updated to r11309 (BTW: My Trac is 0.12.2). Then the error message has changed, see below. The following DEBUG log is a bit tweaked to mask my absolute pathes with X:\<myproject>:

[2012-02-22 15:08:59,559 p3940:t4272] formatter.py:285 DEBUG: Executing Wiki macro PdfImg by provider <PdfImg.PdfImg.PdfImgMacro object at 0x064ED250>
[2012-02-22 15:09:04,418 p3940:t4272] pdfimg.py:86 DEBUG: ***  convert command   convert X:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf[99]  -scale 400 PNG:'X:\<myproject>\htdocs\pfdimg-images/d5c764daa2a56c7eb74d474d5fdfe1235f598a317757770fb4b0bfd3.png' ***
...snip...
[2012-02-22 15:09:04,621 p3940:t4272] formatter.py:720 ERROR: Macro PdfImg(spru198j_programmers_guide.pdf,width=400,page=100,caption="SPRU198j") failed: 
Traceback (most recent call last):
  File "build\bdist.win32\egg\trac\wiki\formatter.py", line 717, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "build\bdist.win32\egg\trac\wiki\formatter.py", line 304, in process
    text = self.processor(text)
  File "build\bdist.win32\egg\trac\wiki\formatter.py", line 291, in _macro_processor
    text)
  File "build\bdist.win32\egg\PdfImg\PdfImg.py", line 89, in expand_macro
    raise TracError( ("Cant display %s"%(pdfinput)) )
TracError: Cant display X:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf

02/22/12 15:27:42 changed by falkb

...and X:\<myproject>\htdocs\pfdimg-images is still an empty directory after all those calls of convert

02/22/12 15:36:04 changed by falkb

Maybe that gives you a hint: I tried that convert call on command line and get this:

X:\bitnami-trac-0.12.2>convert x:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf[99]  -scale 400 PNG:'x:\<myproject>\htdocs\pfdimg-images/d5c764daa2a56c7eb74d474d5fdfe1235f598a317757770fb4b0bfd3.png'
convert.exe: `%s' (%d) "gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dFirstPage=100 -dLastPage=100 "-sOutputFile=C:/DOCUME~1/XXXX/LOCALS~1/Temp/1/magick-FrIgJrHz--0000001" "-fC:/DOCUME~1/XXXX/LOCALS~1/Temp/1/magick-RNJm8ZEk" "-fC:/DOCUME~1/XXXX/LOCALS~1/Temp/1/magick-3a4RCrSd" @ error/utility.c/SystemCommand/1896.
convert.exe: Postscript delegate failed `x:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/668.
convert.exe: missing an image filename `PNG:'x:\<myproject>\htdocs\pfdimg-images/d5c764daa2a56c7eb74d474d5fdfe1235f598a317757770fb4b0bfd3.png'' @ error/convert.c/ConvertImageCommand/3016.

X:\bitnami-trac-0.12.2>}}}

(follow-up: ↓ 6 ) 02/22/12 15:52:49 changed by ursaw

I was working with trac 11 and trac 12 but both on ubuntu.

Its new for me that convert internally calls ghostscript.... anyhow.

convert.exe: Postscript delegate failed `x:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/668.

Do you have the File x:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf ?

is spru198j_programmers_guide.pdf really attached to the Page TiDocs??

if this is not the point, then {{{#!py

## Resource to attachment pdfinput=( Attachment(self.env,self.desc) ).path

}}} doesnt work on Windows.

But I cant help you there....

(in reply to: ↑ 5 ) 02/22/12 16:06:06 changed by falkb

Replying to ursaw:

Do you have the File x:\<myproject>\attachments\wiki\TiDocs\spru198j_programmers_guide.pdf ?

Yes

is spru198j_programmers_guide.pdf really attached to the Page TiDocs??

Yes

I see in the call of convert that slash:

... PNG:'x:\<myproject>\htdocs\pfdimg-images/d5c764daa2a ....
                                            ^

Don't know if that could cause a problem... anyway I changed it in a direct command line call of convert and the error message remains the same (see 4).

02/22/12 16:34:48 changed by falkb

It seems to have a general problem with converting from PDF to another type. convert test.bmp test.png works well, but even a simple convert test.pdf test.png doesn't work:

x:\<myproject>\attachments\wiki\TiDocs>convert test.pdf test.png
convert.exe: `%s' (%d) "gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOP
ROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=
pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=C:/DO
CUME~1/XXXX/LOCALS~1/Temp/2/magick-baQ_RAQd--0000001" "-fC:/DOCUME~1/XXXX/LOCALS
~1/Temp/2/magick-ZGuvB8sY" "-fC:/DOCUME~1/XXXX/LOCALS~1/Temp/2/magick-trOxoAnV"
@ error/utility.c/SystemCommand/1896.
convert.exe: Postscript delegate failed `test.pdf': No such file or directory @
error/pdf.c/ReadPDFImage/668.
convert.exe: missing an image filename `test.png' @ error/convert.c/ConvertImage
Command/3016.

02/22/12 17:25:37 changed by falkb

If it was a problem with the content of my PDF file, you may reproduce it on Linux as well. Please, try http://www.engr.uconn.edu/~zshi/course/cse5095/doc/spru198j_programmers_guide.pdf

(follow-up: ↓ 10 ) 02/22/12 19:57:21 changed by ursaw

I wasn't able to convert your file as well. My next question would have been to try another pdf.

In Case you are able to work with Plugin using convertable PDFs, can you please close the ticket.

(in reply to: ↑ 9 ; follow-up: ↓ 12 ) 02/22/12 21:13:28 changed by falkb

Replying to ursaw:

I wasn't able to convert your file as well.

Searching the internet for "ImageMagick? Postscript delegate failed" shows we're not the only ones, and that seems to be the common error msg when converting fails.

My next question would have been to try another pdf.

Going to try that later... stay tuned...

In Case you are able to work with Plugin using convertable PDFs, can you please close the ticket.

I would rather like to keep it open until there's a way to avoid falling into that trap again. The error msg is "TracError?: Cant display ....pdf" which let us think there's a Trac plugin bug. Is it possible to process a return value of convert and tell via GUI that it's unable to create the image from PDF because of a problem in ImageMagick? and the user should report that problem to the ImageMagick? team? This way you prevent lots of bug reports to your plugin or even exhausting debugging sessions. :)

02/22/12 21:14:54 changed by falkb

  • summary changed from Macro doesn't work on Windows to Internal problems of convert during creation of image from PDF file.

(in reply to: ↑ 10 ; follow-up: ↓ 13 ) 02/23/12 08:57:52 changed by falkb

Replying to falkb:

Replying to ursaw:

My next question would have been to try another pdf.

Going to try that later... stay tuned...

I tried several PDF files but none of them works, we always get the same known error (see above), and an image is not created.

Please, try these standard PDF files available here. They doesn't work for me either, but at least they should work for you, otherwise there's something seriously broken with the current available ImageMagick converter.

02/23/12 12:00:46 changed by ursaw

  • attachment adobe_example.png added.

convert /home/uwi/Downloads/adobe_supplement_iso32000.pdf[0]

(in reply to: ↑ 12 ; follow-up: ↓ 14 ) 02/23/12 12:04:42 changed by ursaw

Replying to falkb:

Please, try these standard PDF files available here. They doesn't work for me either, but at least they should work for you, otherwise there's something seriously broken with the current available ImageMagick converter.

Works fine for me. I am using

Package: imagemagick
Architecture: i386
Version: 7:6.6.2.6-1ubuntu1

and Trac 0.11.7

convert /home/uwi/Downloads/adobe_supplement_iso32000.pdf[0]

(in reply to: ↑ 13 ) 02/23/12 13:47:27 changed by falkb

Replying to ursaw:

Package: imagemagick Architecture: i386 Version: 7:6.6.2.6-1ubuntu1

ImageMagick?-6.7.5-6-Q16-windows-x64-dll.exe on a 64bit Win Server 2003 R2. I also tried the static version and the 32bit version. They are the latest on the ImageMagick site

I noticed the command line call of convert has a return value = 1 when it fails, otherwise 0. Can you use that return value to let the PdfImg? macro return an appropriate error message?

(follow-up: ↓ 16 ) 02/23/12 15:45:01 changed by ursaw

source:/pdfimageplugin/0.11/PdfImg/PdfImg/PdfImg.py@11310#L78 gives you the return value

ret = os.system(cmd)
self.env.log.debug("PdfImg..convert command:   %s  %s ***",ret, cmd )
if ret > 0 :
  raise TracError( ("Cant display %s"%(self.pdfinput)) )

But I have only found

which give me no clue for detailed error handling, since your error is "1"

Therefore this is a weak point of the choosen external convertor.

(in reply to: ↑ 15 ; follow-up: ↓ 17 ) 02/23/12 16:08:22 changed by falkb

Replying to ursaw:

ret = os.system(cmd) if ret > 0 : raise TracError?( ("Cant display %s"%(self.pdfinput)) )

Hmm... maybe rather output something like "Cant display %s because internal ImageMagick? converter failed with %s" to give a hint what actually happened, right?

which give me no clue for detailed error handling, since your error is "1"

I checked the return value by

convert test.pdf test.png
echo %ERRORLEVEL%

IMO that is the return value of 'convert'.

(in reply to: ↑ 16 ; follow-up: ↓ 18 ) 02/29/12 20:20:56 changed by ursaw

  • status changed from new to closed.
  • resolution set to worksforme.

closed after r11340, because I gave more informations on the errormessage.

I've you dont like, please reopen or contribute to the source. Replying to falkb:

Replying to ursaw:

ret = os.system(cmd) if ret > 0 : raise TracError?( ("Cant display %s"%(self.pdfinput)) )

(in reply to: ↑ 17 ) 03/01/12 09:30:31 changed by falkb

Replying to ursaw:

closed after r11340, because I gave more informations on the errormessage.

Thanks, now the PdfImg? macro reports in red:

Can't display foo.pdf, ImageMagick->convert failed with errorcode=1 , command=convert x:\<myproject>\attachments\wiki\foo.pdf[0]  -scale 400 PNG:'x:\<myproject>\htdocs\pfdimg-images/5376ba903bd0caaceddb838921cabc9505b58c099cf43739b2cee1f4.png'

which the user could use to report that to at a bug tracking system of ImageMagick?.

BTW: I slightly wonder where the cryptic internal PNG filename comes from.

03/02/12 11:24:15 changed by falkb

Hi, I found out why convert fails. Read here. You additionally need to install Ghostscript for Windows, which is available here. I'll add this info on PdfImagePlugin.

03/02/12 12:08:24 changed by falkb

  • status changed from closed to reopened.
  • resolution deleted.

Sorry, a failed convert is not the only barricade on the way to a working PDF displaying.

Although I solved the initially seen problem by installing also Ghostscript, I'm still not able to get the PDF file displayed by [[PdfImg(...)]] .

Now your plugin reports an error about a failed execution of convert :

Error: Macro PdfImg(test.pdf) failed

Can't display test.pdf, ImageMagick->convert failed with errorcode=1 , command=convert x:\<myproject>\attachments\wiki\Test\test.pdf[0]  -scale 400 PNG:'x:\<myproject>\htdocs\pfdimg-images/5376ba903bd0caaceddb838921cabc9505b58c099cf43739b2cee1f4.png'}}}

I tried it on command line and see more errors:

convert x:\<myproject>\attachments\wiki\Test\test.pdf[0]  -scale 400 PNG:'x:\<myproject>\htdocs\pfdimg-image
s/5376ba903bd0caaceddb838921cabc9505b58c099cf43739b2cee1f4.png'
convert.exe: unable to open image `'x:\<myproject>\htdocs\pfdimg-images/5376ba
903bd0caaceddb838921cabc9505b58c099cf43739b2cee1f4.png'': Invalid argument @ err
or/blob.c/OpenBlob/2614.
convert.exe: WriteBlob Failed `'x:\<myproject>\htdocs\pfdimg-images/5376ba903b
d0caaceddb838921cabc9505b58c099cf43739b2cee1f4.png'' @ error/png.c/MagickPNGErro
rHandler/1728.

But I see it can easily be solved by removing the apostrophes from the filename. Then the conversion finally works!:

convert x:\<myproject>\attachments\wiki\Test\test.pdf[0]  -scale 400 PNG:x:\<myproject>\htdocs\pfdimg-images
/5376ba903bd0caaceddb838921cabc9505b58c099cf43739b2cee1f4.png

03/05/12 08:13:35 changed by ursaw

with r11356 I removed the single quotes ('). I think this will cause problems with filenames or pathes containing whitespace like spaces. Can you please check on windows if it is possible to work with double quotes (") maybe themslefquoted like (\") , because then whitespace is coverd.

Thanks in advance

03/05/12 08:32:53 changed by falkb

Cool, works now! P.S.: Nice plugin, like it! :-)

03/05/12 08:33:05 changed by falkb

  • status changed from reopened to closed.
  • resolution set to fixed.

07/20/12 03:45:32 changed by PildGellRiz

  • cc set to Mount, Carey.
  • component changed from PdfImagePlugin to GeneralLinkSyntaxPlugin.

Add/Change #9842 (Internal problems of convert during creation of image from PDF file)




Change Properties
Action