You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2019/07/14 11:04:00 UTC
[jira] [Comment Edited] (PDFBOX-4596) Overlays with /Rotate value
appear rotated in result file
[ https://issues.apache.org/jira/browse/PDFBOX-4596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16884640#comment-16884640 ]
Tilman Hausherr edited comment on PDFBOX-4596 at 7/14/19 11:03 AM:
-------------------------------------------------------------------
Code to create the test files I just attached:
{code:java}
public class CreateRotated
{
public static void main(String[] args) throws IOException
{
try (PDDocument doc = new PDDocument())
{
PDPage page = new PDPage(new PDRectangle(200, 400));
doc.addPage(page);
page.setRotation(270); // ****** change here ******
try (PDPageContentStream cs = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND, false))
{
cs.setLineWidth(2);
cs.addRect(0, 0, page.getMediaBox().getWidth(), page.getMediaBox().getHeight());
cs.moveTo(0, 0);
cs.lineTo(page.getMediaBox().getWidth(), page.getMediaBox().getHeight());
cs.moveTo(0, page.getMediaBox().getHeight());
cs.lineTo(page.getMediaBox().getWidth(), 0);
cs.stroke();
String text = "Page rotation: " + page.getRotation();
PDFont font = PDType1Font.HELVETICA_BOLD;
int fontSize = 14;
cs.beginText();
float halfWidth = font.getStringWidth(text) / 1000 * fontSize / 2;
switch (page.getRotation())
{
case 90:
cs.setTextMatrix(Matrix.getRotateInstance(Math.toRadians(90),
page.getMediaBox().getWidth() / 2,
page.getMediaBox().getHeight() / 2 - halfWidth));
break;
case 180:
cs.setTextMatrix(Matrix.getRotateInstance(Math.toRadians(180),
page.getMediaBox().getWidth() / 2 + halfWidth,
page.getMediaBox().getHeight() / 2));
break;
case 270:
cs.setTextMatrix(Matrix.getRotateInstance(Math.toRadians(270),
page.getMediaBox().getWidth() / 2,
page.getMediaBox().getHeight() / 2 + halfWidth));
break;
default:
cs.setTextMatrix(Matrix.getTranslateInstance(
page.getMediaBox().getWidth() / 2 - halfWidth,
page.getMediaBox().getHeight() / 2));
break;
}
cs.setFont(font, fontSize);
cs.showText(text);
cs.endText();
}
doc.save(new File("rot" + page.getRotation() + ".pdf"));
}
}
}
{code}
was (Author: tilman):
Code to create the test files:
{code:java}
public class CreateRotated
{
public static void main(String[] args) throws IOException
{
try (PDDocument doc = new PDDocument())
{
PDPage page = new PDPage(new PDRectangle(200, 400));
doc.addPage(page);
page.setRotation(270); // ****** change here ******
try (PDPageContentStream cs = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND, false))
{
cs.setLineWidth(2);
cs.addRect(0, 0, page.getMediaBox().getWidth(), page.getMediaBox().getHeight());
cs.moveTo(0, 0);
cs.lineTo(page.getMediaBox().getWidth(), page.getMediaBox().getHeight());
cs.moveTo(0, page.getMediaBox().getHeight());
cs.lineTo(page.getMediaBox().getWidth(), 0);
cs.stroke();
String text = "Page rotation: " + page.getRotation();
PDFont font = PDType1Font.HELVETICA_BOLD;
int fontSize = 14;
cs.beginText();
float halfWidth = font.getStringWidth(text) / 1000 * fontSize / 2;
switch (page.getRotation())
{
case 90:
cs.setTextMatrix(Matrix.getRotateInstance(Math.toRadians(90),
page.getMediaBox().getWidth() / 2,
page.getMediaBox().getHeight() / 2 - halfWidth));
break;
case 180:
cs.setTextMatrix(Matrix.getRotateInstance(Math.toRadians(180),
page.getMediaBox().getWidth() / 2 + halfWidth,
page.getMediaBox().getHeight() / 2));
break;
case 270:
cs.setTextMatrix(Matrix.getRotateInstance(Math.toRadians(270),
page.getMediaBox().getWidth() / 2,
page.getMediaBox().getHeight() / 2 + halfWidth));
break;
default:
cs.setTextMatrix(Matrix.getTranslateInstance(
page.getMediaBox().getWidth() / 2 - halfWidth,
page.getMediaBox().getHeight() / 2));
break;
}
cs.setFont(font, fontSize);
cs.showText(text);
cs.endText();
}
doc.save(new File("rot" + page.getRotation() + ".pdf"));
}
}
}
{code}
> Overlays with /Rotate value appear rotated in result file
> ---------------------------------------------------------
>
> Key: PDFBOX-4596
> URL: https://issues.apache.org/jira/browse/PDFBOX-4596
> Project: PDFBox
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.0.16
> Reporter: Tilman Hausherr
> Priority: Major
> Attachments: background.pdf, overlay.pdf, rot0.pdf, rot180.pdf, rot270.pdf, rot90.pdf
>
>
> As reported by Thomas Möller on the users mailing list:
> I try to overlay one pdf with another with pdfbox-app-2.0.16.
> In the output pdf the overlay is rotated by 90 degrees although both input pdfs are displayed in correct orientation in Acrobat Reader.
> When using PDFDebugger on the overlay pdf it shows rotate: 90
> So it seems that it was rotated before and the rotation is ignored by OverlayPDF.
> The example files:
> https://moellersoft.de/downloads/overlay.pdf
> https://moellersoft.de/downloads/background.pdf
> The result:
> https://moellersoft.de/downloads/pdfbox_wrong_result.pdf
> How it should look:
> https://moellersoft.de/downloads/result_made_w_acrobat.pdf
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org