Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF rotation issue #2348

Closed
michaelrsweet opened this issue Apr 17, 2007 · 10 comments
Closed

PDF rotation issue #2348

michaelrsweet opened this issue Apr 17, 2007 · 10 comments

Comments

@michaelrsweet
Copy link
Collaborator

Version: 1.2.10
CUPS.org User: twaugh.redhat

This PDF file:
https://www.rbgkew.org.uk/visitor/maps/strollingmap.pdf

prints incorrectly. I'm printing it with 'lp strollingmap.pdf'.

I get lots of blank space around the top and the left edge of the resulting landscape page, with cropped right and bottom edges.

It prints fine if I print it from xpdf 3.01 on Fedora Core 6 (xpdf-3.01-28.fc6). The problem seems to boil down to some sort of landscape/portrait issue, but I can't quite pin it down.

Here is another PDF file demonstrating (I think) the same problem:
http://www.rbgkew.org.uk/visitor/dayplanner.pdf

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

For the strollingmap.pdf case, here is a diff between the actual result after pdftops and pstops filters, and a correct-looking result:

--- strollingmap-ps.ps 2007-04-18 11:08:49.000000000 +0100
+++ strollingmap-working-ps.ps 2007-04-18 11:32:03.000000000 +0100
@@ -705,7 +705,7 @@
%%PageOrientation: Landscape
pdfStartPage
180 rotate
--718.5 -719 translate
+-842 -586.304 translate
0 0 842 596 re W
%%EndPageSetup
[] 0 d

The problem in this case seems to be two-fold:
a) tx and ty need to be swapped
b) the code for placing the image in the center of the paper is not comparing like with like.

I managed to get correct output by applying this wrong-looking patch:

--- cups-1.2.10/pdftops/PSOutputDev.cxx.pdftops-landscape 2007-02-05 20:25:50.000000000 +0000
+++ cups-1.2.10/pdftops/PSOutputDev.cxx 2007-04-18 12:13:48.000000000 +0100
@@ -2552,6 +2552,12 @@
imgWidth2 = imgHeight;
imgHeight2 = imgWidth;
}

  • // landscape
  • if (landscape) {
  •  double tmpt = tx;
    
  •  tx = ty;
    
  •  ty = tmpt;
    
  • }
    // shrink or expand
    if (xScale0 > 0 && yScale0 > 0) {
    xScale = xScale0;
    @@ -2587,8 +2593,8 @@
    tx += (imgWidth2 - xScale * (clipURX0 - clipLLX0)) / 2;
    ty += (imgHeight2 - yScale * (clipURY0 - clipLLY0)) / 2;
    } else {
  •   tx += (imgWidth2 - xScale \* width) / 2;
    
  •   ty += (imgHeight2 - yScale \* height) / 2;
    
  •   tx += (imgWidth2 - xScale \* (landscape ? height : width)) / 2;
    
  •   ty += (imgHeight2 - yScale \* (landscape ? width : height)) / 2;
    
    }
    }
    tx += rotate == 0 ? imgLLX + tx0 : imgLLY + ty0;

..however, the dayplanner.pdf case seems to be more complicated even than that. The actual vs expected diff for dayplanner.pdf is:

--- dayplanner-ps.ps 2007-04-18 13:07:12.000000000 +0100
+++ dayplanner-working-ps.ps 2007-04-18 13:06:58.000000000 +0100
@@ -1548,7 +1548,7 @@
%%PageOrientation: Portrait
pdfStartPage
90 rotate
-123.5 -718.5 translate
+0 -842 translate
0 0 595 842 re W
%%EndPageSetup
[] 0 d
(for each page)

The '123.5' comes from the bad re-centre code: it's (842-595)/2, i.e. half A4 height minus A4 width. However, the PSOutputDev.cxx patch above did not fix the processing of dayplanner.pdf, so I'm a bit stumped.

strollingmap.pdf: landscape=true, rotate=180
dayplanner.pdf: landscape=false, rotate=90

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: h.blischke

Looking into the PDFs and into the PS files generated by xpdf's pstops (ver 3.02) reveals the following:

(1) strollingmap:
The PDF defines
/MediaBox [842 595] /Rotate 0
(values rounded) which means a physical landscape page
("A4 transverse") and a portrait orientation, i.e. the
page needs not to be rotated for correct viewing.
The generated PS file contains the correct bounding box and
tells
%%PageOrientation: portrait
which is correct.
But something is weird with this PDF: displaying the PDF and the
generated PS with Ghostscript shows different views; in the
PS file the map displays rotated and scaled down to fit on the
page.
I guess the misbehaviour of this PDF is due to a bug in the
creator application (illustrator 10). Opening the PDF with
Illustrator 11 and saving as PDF seems to be correct.

(2) dayplanner
The PDF contains
/MediaBox [595 842] /Rotate 270
which means a physical portrait media and landscape orientation,
i.e. the page needs to be rotated for correct viewing.
The corresponding PS file contains the correct bounding box and
page size and
%%PageOrientation: landscape
All this seems correct.

In general, there seeme so be some serious misinterpretation on
what to do with pages (media sizes) the width of which is greater
than the heigt.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Reverting part of the patch from STR #2149 seems to fix this issue; the main problem is that we don't want pstops to undo our work of rotating the page...

Please let me know if you run into any problems with the attached patch...

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

The patch doesn't help -- in fact it makes it worse. Now instead of having the placement on the page wrong it is actually rotated wrongly.

I expect this:

+---+
|MAP|
+---+

But I'm getting this

+--+
|MA|
| |
+--+

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

pdftops debug output is:

DEBUG: pdftops - opened PPD file "stylus.ppd"...
DEBUG: pdftops - level = 2, width = 595, length = 842
DEBUG: Page rotate=270, width=842, height=596, imgWidth=595, imgHeight=842

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

The attached patch (apply against the previous patch) seems to correct the cupsRotation value, which was messing up the output from pstops.

Let me know if you still have problems...

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

All working correctly now! Thanks!

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

@michaelrsweet
Copy link
Collaborator Author

"str2348.patch":

Index: PSOutputDev.cxx

--- PSOutputDev.cxx (revision 6458)
+++ PSOutputDev.cxx (working copy)
@@ -2511,17 +2511,20 @@
landscape = gFalse;
} else {
rotate = (360 - state->getRotate()) % 360;
+

  •  fprintf(stderr, "DEBUG: Page rotate=%d, width=%d, height=%d, imgWidth=%d, imgHeight=%d\n",
    
  •          state->getRotate(), width, height, imgWidth, imgHeight);
    
  •  rotate = (360 - state->getRotate()) % 360;
    
    if (rotate == 0 || rotate == 180) {
  • if ((width > height && imgWidth < imgHeight) ||
  •   (height > width && imgHeight < imgWidth)) {
    
  • if (width > height && width > imgWidth) {
    rotate += 90;
    landscape = gTrue;
    } else {
    landscape = gFalse;
    }
    } else { // rotate == 90 || rotate == 270
  • if ((width > height && imgWidth < imgHeight) ||
  •   (height > width && imgHeight < imgWidth)) {
    
  • if (height > width && height > imgWidth) {
    rotate = 270 - rotate;
    landscape = gTrue;
    } else {
    @@ -2529,6 +2532,7 @@
    }
    }
    }

writePSFmt("%%%%PageOrientation: %s\n",
landscape ? "Landscape" : "Portrait");
writePS("pdfStartPage\n");

@michaelrsweet
Copy link
Collaborator Author

"str2348p2.patch":

Index: PSOutputDev.cxx

--- PSOutputDev.cxx (revision 6522)
+++ PSOutputDev.cxx (working copy)
@@ -1159,8 +1159,15 @@
}

// Tell CUPS pstops filter not to do its own rotation...

  • writePSFmt("%%cupsRotation: %d\n", pageRotate);
  • int cups_rotate = 0;
  • int width = (int)ceil(mediaBox->x2 - mediaBox->x1);
  • int height = (int)ceil(mediaBox->y2 - mediaBox->y1);
  • int imgWidth = (int)ceil(cropBox->x2 - cropBox->x1);
  • if (width > height && width > imgWidth) cups_rotate = 90;
  • writePSFmt("%%cupsRotation: %d\n", cups_rotate);

writePSFmt("%%Producer: xpdf/pdftops %s\n", xpdfVersion);
xref->getDocInfo(&info);
if (info.isDict() && info.dictLookup("Creator", &obj1)->isString()) {
@@ -2515,7 +2522,6 @@
fprintf(stderr, "DEBUG: Page rotate=%d, width=%d, height=%d, imgWidth=%d, imgHeight=%d\n",
state->getRotate(), width, height, imgWidth, imgHeight);

  •  rotate = (360 - state->getRotate()) % 360;
    

    if (rotate == 0 || rotate == 180) {
    if (width > height && width > imgWidth) {
    rotate += 90;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant