Page 1 of 2

How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T10:36:39-07:00
by jauson
https://www.dropbox.com/sh/0w7fv0iucs6r ... eG34a?dl=0

Rotate 5 degrees:

Code: Select all

convert -density 288 cross.pdf -colorspace sRGB +repage -virtual-pixel White -distort SRT '5' -alpha remove rotate-pdf-1-5deg-out.pdf
Rotates the image

Rotate -5 degrees output with same command as above on the resulting pdf:

Code: Select all

convert -density 288 rotate-pdf-1-5deg-out.pdf -colorspace sRGB +repage -virtual-pixel White -distort SRT '-5' -alpha remove rotate-pdf-1-5deg-out-rev.pdf
Produces a page with 3 small images.

Version: ImageMagick 6.9.9-10 Q16 x64 Win 8.1

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T11:01:31-07:00
by snibgo
What version of IM on what platform?

With v6.9.9-50 on Windows 8.1, I get the expected result with only one cross.

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T11:12:38-07:00
by jauson
Upgraded to Version: ImageMagick 6.9.10-11 Q16 x64, getting expected results.

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T11:30:10-07:00
by jauson
Still seeing issue with multi-paged pdf.


The output is proper, it rotates each page, but the second rotate creates 3 little images per page, or single page.

Code: Select all

convert -density 288 crosses.pdf                    -colorspace sRGB +repage -virtual-pixel White -distort SRT '5' -alpha remove rotate-pdf-1-5deg-out.pdf
convert -density 288 rotate-pdf-1-5deg-out.pdf    -colorspace sRGB +repage -virtual-pixel White -distort SRT '-5' -alpha remove rotate-pdf-1-5deg-out-rev.pdf
convert -density 288 rotate-pdf-1-5deg-out.pdf[0] -colorspace sRGB +repage -virtual-pixel White -distort SRT '-5' -alpha remove rotate-pdf-1-5deg-out-rev-page0.pdf

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T11:50:35-07:00
by snibgo
Is your Ghostscript reasonably current, eg 9.19 or later?

You posted crosses.pdf in your dropbox. Processing that, I get two pages each with one cross.

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T12:07:50-07:00
by jauson
gswin64c.exe --version
9.21


Even updating to 9.24, still same output.

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T12:16:47-07:00
by jauson
I updated the dropbox with the results im seeing. file rotate-pdf-1-5deg-out-rev-x.pdf

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T15:54:20-07:00
by snibgo
I don't know why you are getting three crosses per page. I guess Ghostscript is doing this. To verify, try:

Code: Select all

convert -verbose  rotate-pdf-1-5deg-out.pdf x.png
This should create two files, named x-0.png and x-1.png, each with one cross. The text output will be something like:

Code: Select all

[ghostscript library 9.19] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMax
Bitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlpha
Bits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=C:/Users/Alan/AppData/Loca
l/Temp/magick-7260pFTNc_XWNNyE%d" "-fC:/Users/Alan/AppData/Local/Temp/magick-726
0n4KoWexGBk0_" "-fC:/Users/Alan/AppData/Local/Temp/magick-7260c04di0Hlqs6r"C:/Us
ers/Alan/AppData/Local/Temp/magick-7260pFTNc_XWNNyE1 PNG 500x500 500x500+0+0 8-b
it sRGB 27579B 0.031u 0:00.031
C:/Users/Alan/AppData/Local/Temp/magick-7260pFTNc_XWNNyE2 PNG 500x500 500x500+0+0 8-bit sRGB 27579B 0.016u 0:00.015
rotate-pdf-1-5deg-out.pdf[0] PDF 500x500 500x500+0+0 16-bit sRGB 27579B 0.109u 0:00.171
rotate-pdf-1-5deg-out.pdf[1] PDF 500x500 500x500+0+0 16-bit sRGB 27579B 0.094u 0:00.156
rotate-pdf-1-5deg-out.pdf=>x-0.png[0] PDF 500x500 500x500+0+0 8-bit sRGB 207c 18855B 0.063u 0:00.109
rotate-pdf-1-5deg-out.pdf=>x-1.png[1] PDF 500x500 500x500+0+0 8-bit sRGB 207c 18855B 0.141u 0:00.187
Check that the options gven to Ghostscript on your computer are like mine.

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T16:03:54-07:00
by jauson
I just tried this on a fresh Windows 10 machine with GS 9.24 and Version: ImageMagick 6.9.10-11 Q16 x64 2018-08-29 http://www.imagemagick.org

Still getting same results. https://imgur.com/a/SrTkjQl

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-12T16:09:29-07:00
by jauson
It created 3 files, 2 files with 3 little crosses and an empty x.png.

Image

Code: Select all

convert -verbose  rotate-pdf-1-5deg-out-x.pdf x.png
magick-10756ZjGD0ApxU51H1 PNG 500x500 500x500+0+0 8-bit sRGB 24162B 0.000u 0:00.002
magick-10756ZjGD0ApxU51H2 PNG 500x500 500x500+0+0 8-bit sRGB 24162B 0.000u 0:00.003
rotate-pdf-1-5deg-out-x.pdf[0] PDF 500x500 500x500+0+0 16-bit sRGB 24162B 0.016u 0:00.023
rotate-pdf-1-5deg-out-x.pdf[1] PDF 500x500 500x500+0+0 16-bit sRGB 24162B 0.016u 0:00.020
rotate-pdf-1-5deg-out-x.pdf=>x-0.png[0] PDF 500x500 500x500+0+0 8-bit sRGB 24907B 0.031u 0:00.018
rotate-pdf-1-5deg-out-x.pdf=>x-1.png[1] PDF 500x500 500x500+0+0 8-bit sRGB 24907B 0.047u 0:00.037
[ghostscript library 9.24] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=magick-10756ZjGD0ApxU51H%d" "-fmagick-10756qpjdrZJufZR6" "-fmagick-10756gDhP2uiYy_1q"
Also tried with 9.19, same 3 little x's

Code: Select all

convert -verbose  rotate-pdf-1-5deg-out-x.pdf x.png
magick-1056060vfiqGMgpfr1 PNG 500x500 500x500+0+0 8-bit sRGB 21888B 0.000u 0:00.003
magick-1056060vfiqGMgpfr2 PNG 500x500 500x500+0+0 8-bit sRGB 21888B 0.000u 0:00.003
rotate-pdf-1-5deg-out-x.pdf[0] PDF 500x500 500x500+0+0 16-bit sRGB 21888B 0.016u 0:00.023
rotate-pdf-1-5deg-out-x.pdf[1] PDF 500x500 500x500+0+0 16-bit sRGB 21888B 0.016u 0:00.020
rotate-pdf-1-5deg-out-x.pdf=>x-0.png[0] PDF 500x500 500x500+0+0 8-bit sRGB 22663B 0.016u 0:00.014
rotate-pdf-1-5deg-out-x.pdf=>x-1.png[1] PDF 500x500 500x500+0+0 8-bit sRGB 22663B 0.031u 0:00.031
[ghostscript library 9.19] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=magick-1056060vfiqGMgpfr%d" "-fmagick-10560xeIjPA78Xc6T" "-fmagick-105606WRiAl2dO2LX"

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-13T10:30:11-07:00
by jauson
When I do this command on on multi-page crosses pdf:

Code: Select all

convert -verbose  crosses.pdf crosses.png
I get 2 images, with regular sized crosses, https://imgur.com/4BoShyL

Then rotating the same crosses, and running this:

Code: Select all

convert -verbose -density 288 crosses.pdf -colorspace sRGB +repage -virtual-pixel White -distort SRT '-5' -alpha remove rotate-pdf-1-5deg-out-x.pdf

Code: Select all

convert -verbose  rotate-pdf-1-5deg-out-x.pdf x.png
I get 2 images of little crosses, https://imgur.com/ogKExLQ


However, when doing the same commands on single page PDF, the results seem normal.

https://imgur.com/dVyxwUP

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-13T10:49:58-07:00
by fmw42
I can confirm wrong results of his two commands on IM 6.9.10.11 Q16 Mac OSX. I modified the first command slightly, but still get the bad results.

Code: Select all

convert -verbose -density 288 -units pixelsperinch -colorspace sRGB crosses.pdf -virtual-pixel White -distort SRT '-5' -alpha remove +repage rotate-pdf-1-5deg-out-x.pdf
convert -verbose  rotate-pdf-1-5deg-out-x.pdf x.png
The x-0.png and x-1.png are incorrect.

But if you do the same first command but save to png or tiff, it is correct. I get two large rotated crosses as separate images for the png and a two-page tiff.

Code: Select all

convert -verbose -density 288 -colorspace sRGB crosses.pdf -virtual-pixel White -distort SRT '-5' -alpha remove +repage rotate-pdf-1-5deg-out-x.png

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-13T12:49:31-07:00
by jauson
Seems to be a problem how it's saving multi-paged pdfs?

Code: Select all

convert -verbose -density 288 crosses.pdf -colorspace sRGB -alpha remove out-2-x.pdf
convert -verbose  out-2-x.pdf x.png

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-13T12:56:41-07:00
by fmw42
Properly, you should use -colorspace sRGB before reading the PDF. But as in my commands above, it still produces bad results. So I would agree that it is a bug.

Re: How to rotate pdf and undo rotating? Gives unexpected results.

Posted: 2018-09-13T14:44:39-07:00
by jauson

Code: Select all

convert -verbose -density 288 -colorspace sRGB crosses.pdf  -alpha remove out-2-x.pdf
convert -verbose -density 288 -colorspace sRGB out-2-x.pdf  -alpha remove out-2-x-2nd-save.pdf
Another sample of a bad results, can't modify a pdf more then once.

I tried to clean it and recreate the pdf with `mutool clean -ggg` and `pdftk` concat, their results were not able to clean up the bad outputs.

Using, [ghostscript library 9.24] and Version: ImageMagick 6.9.10-11 Q16 x64 2018-08-29