Modify

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#9842 closed defect (fixed)

Internal problems of convert during creation of image from PDF file

Reported by: falkb Owned by: 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 (1)

adobe_example.png (29.9 KB) - added by ursaw 12 years ago.
convert /home/uwi/Downloads/adobe_supplement_iso32000.pdf[0]

Download all attachments as: .zip

Change History (25)

comment:1 Changed 12 years ago 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

comment:2 Changed 12 years ago by falkb

Summary: 'PdfImgMacro' object has no attribute 'pdfinput'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

comment:3 Changed 12 years ago by falkb

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

comment:4 Changed 12 years ago 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>}}}

comment:5 Changed 12 years ago 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

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

doesnt work on Windows.

But I cant help you there....

comment:6 in reply to:  5 Changed 12 years ago 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).

comment:7 Changed 12 years ago 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.

comment:8 Changed 12 years ago 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

comment:9 Changed 12 years ago 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.

comment:10 in reply to:  9 ; Changed 12 years ago 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. :)

comment:11 Changed 12 years ago by falkb

Summary: Macro doesn't work on WindowsInternal problems of convert during creation of image from PDF file

comment:12 in reply to:  10 ; Changed 12 years ago 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.

Changed 12 years ago by ursaw

Attachment: adobe_example.png added

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

comment:13 in reply to:  12 ; Changed 12 years ago 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]

comment:14 in reply to:  13 Changed 12 years ago 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?

comment:15 Changed 12 years ago 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.

comment:16 in reply to:  15 ; Changed 12 years ago 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'.

comment:17 in reply to:  16 ; Changed 12 years ago by ursaw

Resolution: worksforme
Status: newclosed

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)) )

comment:18 in reply to:  17 Changed 12 years ago 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.

comment:19 Changed 12 years ago 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.

comment:20 Changed 12 years ago by falkb

Resolution: worksforme
Status: closedreopened

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

comment:21 Changed 12 years ago 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

comment:22 Changed 12 years ago by falkb

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

comment:23 Changed 12 years ago by falkb

Resolution: fixed
Status: reopenedclosed

comment:24 Changed 12 years ago by PildGellRiz

Cc: Mount Carey added; anonymous removed
Component: PdfImagePluginGeneralLinkSyntaxPlugin

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain ursaw.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.