Skip to content

Commit baec3a7

Browse files
committed
PDFBOX-6048: calculate overlay position to lower left of the media box instead of from (0,0)
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1927640 13f79535-47bb-0310-9956-ffa450edef68
1 parent ca06bc8 commit baec3a7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.List;
3232
import java.util.Map;
3333
import java.util.Set;
34+
import org.apache.logging.log4j.LogManager;
35+
import org.apache.logging.log4j.Logger;
3436

3537
import org.apache.pdfbox.Loader;
3638
import org.apache.pdfbox.cos.COSArray;
@@ -54,6 +56,8 @@
5456
*/
5557
public class Overlay implements Closeable
5658
{
59+
private static final Logger LOG = LogManager.getLogger(Overlay.class);
60+
5761
/**
5862
* Possible location of the overlaid pages: foreground or background.
5963
*/
@@ -565,8 +569,9 @@ private COSStream createOverlayStream(PDPage page, LayoutPage layoutPage, COSNam
565569

566570
/**
567571
* Calculate the transform to be used when positioning the overlay. The default implementation
568-
* centers on the destination. Override this method to do your own, e.g. move to a corner, or
569-
* rotate.
572+
* centers on the destination, and this is calculated from the lower left of the media box of
573+
* the destination (this has been changed from 3.0 and 2.0, see PDFBOX-6048 for details).
574+
* Override this method to do your own, e.g. move to a corner, rotate, or zoom.
570575
*
571576
* @param page The page that will get the overlay.
572577
* @param overlayMediaBox The overlay media box.
@@ -576,8 +581,9 @@ protected AffineTransform calculateAffineTransform(PDPage page, PDRectangle over
576581
{
577582
AffineTransform at = new AffineTransform();
578583
PDRectangle pageMediaBox = page.getMediaBox();
579-
float hShift = (pageMediaBox.getWidth() - overlayMediaBox.getWidth()) / 2.0f;
580-
float vShift = (pageMediaBox.getHeight() - overlayMediaBox.getHeight()) / 2.0f;
584+
float hShift = pageMediaBox.getLowerLeftX() + (pageMediaBox.getWidth() - overlayMediaBox.getWidth()) / 2.0f;
585+
float vShift = pageMediaBox.getLowerLeftY() + (pageMediaBox.getHeight() - overlayMediaBox.getHeight()) / 2.0f;
586+
LOG.debug("Overlay position: ({},{})", hShift, vShift);
581587
at.translate(hShift, vShift);
582588
return at;
583589
}

0 commit comments

Comments
 (0)