png image generation (windows)

26 views
Skip to first unread message

Oscar Levin

unread,
Jun 1, 2021, 9:54:30 PM6/1/21
to PreTeXt support
If I use the pretext script in hopes of converting a latex-image to a png, I get the following error:

PTX: cropping test-image.pdf to test-image.pdf
PTX:DEBUG: locating "pdfpng" in [executables] section of configuration file
PTX:DEBUG: pdfpng executable: convert, options:
PTX:DEBUG: pdfpng executable: convert
PTX: converting test-image.pdf to test-image.png
Invalid Parameter - 300

Any idea if this is a windows issue or something that needs to be fixed?  

Oscar.

Alex Jordan

unread,
Jun 1, 2021, 10:38:33 PM6/1/21
to pretext...@googlegroups.com
In the latest, the verbose output should be:
PTX: cropping test-image.pdf to cropped-test-image.pdf

and then shortly after:
PTX: renaming cropped-test-image.pdf to test-image.pdf

So not that I have any reason to think it would fix things, but
pulling mathbook is one thing to look into.

The "300" is the argument to the -density option for ImageMagick's convert. "
Invalid Parameter - 300" makes it sound like it tried to run
convert -300
or something like that instead of
convert -density 300

It is odd that you have both these lines:
PTX:DEBUG: pdfpng executable: convert, options:
PTX:DEBUG: pdfpng executable: convert

but maybe the pull will change things.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/27b18eed-3467-454f-984b-a50e6737b0f5n%40googlegroups.com.

Oscar Levin

unread,
Jun 1, 2021, 11:02:37 PM6/1/21
to PreTeXt support
Pulling did not help.  Now the full -vv output is:

PTX:DEBUG: locating "tex" in [executables] section of configuration file
PTX:DEBUG: tex executable: xelatex.exe, options: 
PTX:DEBUG: tex executable: xelatex.exe
PTX: converting test-image.tex to test-image.pdf
PTX:DEBUG: locating "pdfcrop" in [executables] section of configuration file
PTX:DEBUG: pdfcrop executable: pdf-crop-margins, options: 
PTX: cropping test-image.pdf to cropped-test-image.pdf
PTX: renaming cropped-test-image.pdf to test-image.pdf
PTX:DEBUG: locating "pdfpng" in [executables] section of configuration file
PTX:DEBUG: pdfpng executable: convert, options:
PTX:DEBUG: pdfpng executable: convert
PTX: converting test-image.pdf to test-image.png
Invalid Parameter - 300

Alex Jordan

unread,
Jun 1, 2021, 11:09:17 PM6/1/21
to pretext...@googlegroups.com
Can you see if "convert" is working?

Find a pdf file, image.pdf, and do:
convert -density 300 image.pdf -quality 100 image.png
and check to see that succeeds at making a png image file.

I don't understand why you get to lines:
PTX:DEBUG: pdfpng executable: convert, options:
PTX:DEBUG: pdfpng executable: convert

There is only one line in the pretext script that would say this:
https://github.com/rbeezer/mathbook/blob/25491a6f2f96643bb17ce3e0552818da3125d1c2/pretext/pretext.py#L312
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/b02c409a-488f-40df-b83f-586821b851e9n%40googlegroups.com.

Rob Beezer

unread,
Jun 2, 2021, 12:29:31 AM6/2/21
to pretext...@googlegroups.com
Kiran's recent cropping issue suggests we should echo the full suspect command line when the output does not exist.

Sometimes the verbose messages seem to appear sort of out-of-order.

Oscar Levin

unread,
Jun 2, 2021, 2:47:57 PM6/2/21
to PreTeXt support
Calling the `convert` command directly works fine.  Also tested with an earlier version of python (3.6.8) and get the same error.  Any suggestions for some debug messages I can add?

Alex Jordan

unread,
Jun 2, 2021, 2:52:38 PM6/2/21
to pretext...@googlegroups.com
I see now why there are the two lines:
PTX:DEBUG: pdfpng executable: convert, options:
PTX:DEBUG: pdfpng executable: convert

Because also the subroutine get_executable_cmd is printing such things.

Right after:
subprocess.call(png_cmd)

Add this line:
_debug("png_cmd is called as: {}".format(png_cmd))

I think it should come out as:
png_cmd is called as: convert -density 300 image.pdf -quality 100 image.png

But the error message sounds like it comes out maybe like:
png_cmd is called as: convert -300 image.pdf -quality 100 image.png

or...something.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/704581ee-a0b4-47e5-b55f-b25e6461c44an%40googlegroups.com.

Oscar Levin

unread,
Jun 2, 2021, 5:31:12 PM6/2/21
to PreTeXt support
The output of _debug("png_cmd is called as: {}".format(png_cmd)) is

PTX:DEBUG: png_cmd is called as: ['convert', '-density', '300', 'test-image.pdf', '-quality', '100', 'test-image.png']

Following this (https://www.reddit.com/r/Python/comments/6ilok4/when_you_use_subprocess_in_windows_10_do_the/) I tried replacing `subprocess.call(png_cmd)` with `subprocess.call(png_cmd, shell=True)`, and this fixed the problem.  But the link also mentions that `shell=True` can be a "security hazard", so I don't know whether this change should be made or not.

Rob Beezer

unread,
Jun 2, 2021, 7:28:50 PM6/2/21
to pretext...@googlegroups.com
I believe "subprocess.run()" is preferable. Search on that and see a code
comment or two. Perhaps it'll behave better?
> >https://github.com/rbeezer/mathbook/blob/25491a6f2f96643bb17ce3e0552818da3125d1c2/pretext/pretext.py#L312 <https://github.com/rbeezer/mathbook/blob/25491a6f2f96643bb17ce3e0552818da3125d1c2/pretext/pretext.py#L312>
> >https://groups.google.com/d/msgid/pretext-support/27b18eed-3467-454f-984b-a50e6737b0f5n%40googlegroups.com <https://groups.google.com/d/msgid/pretext-support/27b18eed-3467-454f-984b-a50e6737b0f5n%40googlegroups.com>.
> >> >>
> >> >> --
> >> >> You received this message because you are subscribed to the Google
> >> >Groups "PreTeXt support" group.
> >> >> To unsubscribe from this group and stop receiving emails from it,
> >> >send an email to pretext-suppo...@googlegroups.com.
> >> >> To view this discussion on the web visit
> >>
> >https://groups.google.com/d/msgid/pretext-support/b02c409a-488f-40df-b83f-586821b851e9n%40googlegroups.com <https://groups.google.com/d/msgid/pretext-support/b02c409a-488f-40df-b83f-586821b851e9n%40googlegroups.com>.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> email to pretext-suppo...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/704581ee-a0b4-47e5-b55f-b25e6461c44an%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/704581ee-a0b4-47e5-b55f-b25e6461c44an%40googlegroups.com>.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/abb4ea9e-0e76-468b-a6d0-f85798378434n%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/abb4ea9e-0e76-468b-a6d0-f85798378434n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages