Return-Path: X-Original-To: apmail-pdfbox-users-archive@www.apache.org Delivered-To: apmail-pdfbox-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 142AB19337 for ; Thu, 17 Mar 2016 00:34:03 +0000 (UTC) Received: (qmail 51488 invoked by uid 500); 17 Mar 2016 00:34:02 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 51461 invoked by uid 500); 17 Mar 2016 00:34:02 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 51449 invoked by uid 99); 17 Mar 2016 00:34:01 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Mar 2016 00:34:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 7A3E71A04AA for ; Thu, 17 Mar 2016 00:34:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.591 X-Spam-Level: X-Spam-Status: No, score=-0.591 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, T_DKIM_INVALID=0.01] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=neutral reason="invalid (public key: not available)" header.d=jahewson.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 33v5gKfPmElT for ; Thu, 17 Mar 2016 00:33:59 +0000 (UTC) Received: from mail-pf0-f181.google.com (mail-pf0-f181.google.com [209.85.192.181]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 64CEA5FAC6 for ; Thu, 17 Mar 2016 00:33:58 +0000 (UTC) Received: by mail-pf0-f181.google.com with SMTP id n5so95497824pfn.2 for ; Wed, 16 Mar 2016 17:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jahewson.com; s=google; h=mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=i7K5Wgo+UyunO0jIMZKuISG8PgoRzaiHiRHWBQPjKT4=; b=Yak4oc76RDBYXS1j5vVMAa4PRvkUOwMKuUn99/O/lbfeu6ZO2WJBcTKEnNj2Zx9o2i suhsFqJD7jzWgsaRLjnMOPXIhs6dxMBYKs4l9t9TFegJQHKw1zbYSUmq1j0hswkJs3M5 A9H+is5/DpSUtEKfsSZPLEw5YTeo2Q2Q6gRAo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=i7K5Wgo+UyunO0jIMZKuISG8PgoRzaiHiRHWBQPjKT4=; b=OYTcNyAppXBtNyxelBhiVhfbk526QoRJJqsDO3Q/sz3blCtgOwPFoXP8qaFJCaO3I2 g7z0Ha0m/JNhkbiOgKhtym0cMguw8zSGmlwVGUfPZSH0uUwU0luXZSKiq88fq4vNjYSG PnVlsJWuGcacEpSvx6fBOky7gVLA7CNlnuvjMpAUrymb/ekA0DtoyTjXUAfLchQbW5L1 9IUQ9LSIs44JxxEDYHIkdH05GPtwLqZLG+QN+vOs0X2mzkW3jhfD36Fcg9N1xJ+zyO9E zINSco2DcxYPvCD8ILIWzO/rHA1ljd+D51/Z3QX0I3kkxHTwnl2PxyfJ5Vkr3vbhxQWk e1Vg== X-Gm-Message-State: AD7BkJKaI5CBHBPxAHWYM0m+e1a1rxO/cmy12YedX3bFynz1zzeMW3fUOCQSCVR3+xJaXA== X-Received: by 10.66.122.100 with SMTP id lr4mr9994897pab.99.1458174837182; Wed, 16 Mar 2016 17:33:57 -0700 (PDT) Received: from [10.0.1.12] (c-73-202-194-89.hsd1.ca.comcast.net. [73.202.194.89]) by smtp.gmail.com with ESMTPSA id n68sm8349962pfj.46.2016.03.16.17.33.56 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 16 Mar 2016 17:33:56 -0700 (PDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) Subject: Re: Orientation printout - used 2.0.0.RC3 release From: John Hewson In-Reply-To: <56E86CA3.4030700@t-online.de> Date: Wed, 16 Mar 2016 17:33:56 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <223FA9C1-C329-45CD-AB67-1C2078F46562@jahewson.com> References: <34e814cdc7eb2cba9a9c87f942829217@mail.gmail.com> <56E86CA3.4030700@t-online.de> To: users@pdfbox.apache.org X-Mailer: Apple Mail (2.3112) > On 15 Mar 2016, at 13:12, Tilman Hausherr = wrote: >=20 > I recommend that you try with your own version of PDFPageable. I = looked at the code and IMHO the problem is that a rotation is set that = you don't want. See in getPageFormat. I haven't tested it, but I assume = you should delete these lines: >=20 >=20 > if (mediaBox.getWidth() > mediaBox.getHeight()) > { > // rotate > paper =3D new Paper(); > paper.setSize(mediaBox.getHeight(), mediaBox.getWidth()); > paper.setImageableArea(cropBox.getLowerLeftY(), = cropBox.getLowerLeftX(), > cropBox.getHeight(), cropBox.getWidth()); > isLandscape =3D true; > } > else You don=92t want to do that though, because Java doesn=92t handle = landscape sized paper correctly. So it=92s necessary to always print in = portrait, rotating any landscape pages first, and flagging them as being = landscape. =97 John > Here's the full code. If this doesn't get through, download the source = code. >=20 >=20 > public final class PDFPageable extends Book > { > private final PDDocument document; > private final boolean showPageBorder; > private final float dpi; > private final Orientation orientation; >=20 > /** > * Creates a new PDFPageable. > * > * @param document the document to print > */ > public PDFPageable(PDDocument document) > { > this(document, Orientation.AUTO, false, 0); > } >=20 > /** > * Creates a new PDFPageable with the given page orientation. > * > * @param document the document to print > * @param orientation page orientation policy > */ > public PDFPageable(PDDocument document, Orientation orientation) > { > this(document, orientation, false, 0); > } >=20 > /** > * Creates a new PDFPageable with the given page orientation and = with optional page borders > * shown. The image will be rasterized at the given DPI before = being sent to the printer. > * > * @param document the document to print > * @param orientation page orientation policy > * @param showPageBorder true if page borders are to be printed > */ > public PDFPageable(PDDocument document, Orientation orientation, = boolean showPageBorder) > { > this(document, orientation, showPageBorder, 0); > } >=20 > /** > * Creates a new PDFPageable with the given page orientation and = with optional page borders > * shown. The image will be rasterized at the given DPI before = being sent to the printer. > * > * @param document the document to print > * @param orientation page orientation policy > * @param showPageBorder true if page borders are to be printed > * @param dpi if non-zero then the image will be rasterized at the = given DPI > */ > public PDFPageable(PDDocument document, Orientation orientation, = boolean showPageBorder, > float dpi) > { > this.document =3D document; > this.orientation =3D orientation; > this.showPageBorder =3D showPageBorder; > this.dpi =3D dpi; > } >=20 > @Override > public int getNumberOfPages() > { > return document.getNumberOfPages(); > } >=20 > /** > * {@inheritDoc} > * > * Returns the actual physical size of the pages in the PDF file. = May not fit the local printer. > */ > @Override > public PageFormat getPageFormat(int pageIndex) > { > PDPage page =3D document.getPage(pageIndex); > PDRectangle mediaBox =3D PDFPrintable.getRotatedMediaBox(page); > PDRectangle cropBox =3D PDFPrintable.getRotatedCropBox(page); >=20 > // Java does not seem to understand landscape paper sizes, i.e. = where width > height, it > // always crops the imageable area as if the page were in = portrait. I suspect that this is > // a JDK bug but it might be by design, see PDFBOX-2922. > // > // As a workaround, we normalise all Page(s) to be portrait, = then flag them as landscape in > // the PageFormat. > Paper paper; > boolean isLandscape; > if (mediaBox.getWidth() > mediaBox.getHeight()) > { > // rotate > paper =3D new Paper(); > paper.setSize(mediaBox.getHeight(), mediaBox.getWidth()); > paper.setImageableArea(cropBox.getLowerLeftY(), = cropBox.getLowerLeftX(), > cropBox.getHeight(), cropBox.getWidth()); > isLandscape =3D true; > } > else > { > paper =3D new Paper(); > paper.setSize(mediaBox.getWidth(), mediaBox.getHeight()); > paper.setImageableArea(cropBox.getLowerLeftX(), = cropBox.getLowerLeftY(), > cropBox.getWidth(), cropBox.getHeight()); > isLandscape =3D false; > } >=20 > PageFormat format =3D new PageFormat(); > format.setPaper(paper); >=20 > // auto portrait/landscape > if (orientation =3D=3D Orientation.AUTO) > { > if (isLandscape) > { > format.setOrientation(PageFormat.LANDSCAPE); > } > else > { > format.setOrientation(PageFormat.PORTRAIT); > } > } > else if (orientation =3D=3D Orientation.LANDSCAPE) > { > format.setOrientation(PageFormat.LANDSCAPE); > } > else if (orientation =3D=3D Orientation.PORTRAIT) > { > format.setOrientation(PageFormat.PORTRAIT); > } >=20 > return format; > } >=20 > @Override > public Printable getPrintable(int i) > { > if (i >=3D getNumberOfPages()) > { > throw new IndexOutOfBoundsException(i + " >=3D " + = getNumberOfPages()); > } > return new PDFPrintable(document, Scaling.ACTUAL_SIZE, = showPageBorder, dpi); > } > } >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org