You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Marco Di Girolami <md...@noemalife.com> on 2016/03/15 20:01:19 UTC
Orientation printout - used 2.0.0.RC3 release
Hi all,
I have one problem printing a PDF label (1,96x0,97 inches) to a label
printer.
In attachment you can see the input PDF and the some outputs printouts
printed via my java application to PDFCreator (but I have the same results
on the real printer).
You can see that in input I have a PDF document with correctly size and
orientation but in output I could not to obtain the *SAME document*.
In attachment you can see my simple code.
I’ve also tried to:
1) manage orientation on PageFormat object;
2) setting size and imageablearea on Paper object,
3) rotating content using COSBase and COSArray objects
with many results but not the correct one.
Can you help me please??
Thanks very much in advance,
Marco
--
Marco Di Girolami
Team Leader
NoemaLife S.p.A.
Via Gobetti, 52
40129 Bologna - Italy
tel. 39.345.93.45.786 - 39.051.7098.285
mdigirolami@noemalife.com - www.noemalife.com
--
*Confidentiality Notice.** This email is confidential and any attachment is
intended for the named addresses only, or person authorized to receive it
on their behalf. The content should be treated confidentially as it is
protected by laws about data protection, copyright and know-how defense.
The recipient may not disclose this message or any attachment to anyone
else without authorization of the sender. Unauthorized use, copying or
disclosure may be unlawful. If this transmission is received in error
please notify the sender immediately and delete this message from your
email system.*
Re: Orientation printout - used 2.0.0.RC3 release
Posted by John Hewson <jo...@jahewson.com>.
> On 16 Mar 2016, at 17:36, John Hewson <jo...@jahewson.com> wrote:
>
>
>> On 15 Mar 2016, at 12:01, Marco Di Girolami <mdigirolami@noemalife.com <ma...@noemalife.com>> wrote:
>>
>> Hi all,
>> I have one problem printing a PDF label (1,96x0,97 inches) to a label printer.
>>
>> In attachment you can see the input PDF and the some outputs printouts printed via my java application to PDFCreator (but I have the same results on the real printer).
>>
>> You can see that in input I have a PDF document with correctly size and orientation but in output I could not to obtain the SAME document.
>>
>> In attachment you can see my simple code.
>
> Our mailing list removes attachments, can you send the code in an e-mail?
Oh an can you post the PDFs somewhere public? Thanks.
— John
>
>> I’ve also tried to:
>> 1) manage orientation on PageFormat object;
>> 2) setting size and imageablearea on Paper object,
>> 3) rotating content using COSBase and COSArray objects
>> with many results but not the correct one.
>>
>> Can you help me please??
>>
>> Thanks very much in advance,
>> Marco
>>
>> --
>> Marco Di Girolami
>> Team Leader
>> NoemaLife S.p.A.
>> Via Gobetti, 52
>> 40129 Bologna - Italy
>> tel. 39.345.93.45.786 - 39.051.7098.285
>> mdigirolami@noemalife.com <ma...@noemalife.com> - www.noemalife.com <http://www.noemalife.com/>
>>
>>
>> Confidentiality Notice. This email is confidential and any attachment is intended for the named addresses only, or person authorized to receive it on their behalf. The content should be treated confidentially as it is protected by laws about data protection, copyright and know-how defense. The recipient may not disclose this message or any attachment to anyone else without authorization of the sender. Unauthorized use, copying or disclosure may be unlawful. If this transmission is received in error please notify the sender immediately and delete this message from your email system.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org <ma...@pdfbox.apache.org>
>> For additional commands, e-mail: users-help@pdfbox.apache.org <ma...@pdfbox.apache.org>
Re: Orientation printout - used 2.0.0.RC3 release
Posted by John Hewson <jo...@jahewson.com>.
> On 15 Mar 2016, at 12:01, Marco Di Girolami <md...@noemalife.com> wrote:
>
> Hi all,
> I have one problem printing a PDF label (1,96x0,97 inches) to a label printer.
>
> In attachment you can see the input PDF and the some outputs printouts printed via my java application to PDFCreator (but I have the same results on the real printer).
>
> You can see that in input I have a PDF document with correctly size and orientation but in output I could not to obtain the SAME document.
>
> In attachment you can see my simple code.
Our mailing list removes attachments, can you send the code in an e-mail?
> I’ve also tried to:
> 1) manage orientation on PageFormat object;
> 2) setting size and imageablearea on Paper object,
> 3) rotating content using COSBase and COSArray objects
> with many results but not the correct one.
>
> Can you help me please??
>
> Thanks very much in advance,
> Marco
>
> --
> Marco Di Girolami
> Team Leader
> NoemaLife S.p.A.
> Via Gobetti, 52
> 40129 Bologna - Italy
> tel. 39.345.93.45.786 - 39.051.7098.285
> mdigirolami@noemalife.com <ma...@noemalife.com> - www.noemalife.com <http://www.noemalife.com/>
>
>
> Confidentiality Notice. This email is confidential and any attachment is intended for the named addresses only, or person authorized to receive it on their behalf. The content should be treated confidentially as it is protected by laws about data protection, copyright and know-how defense. The recipient may not disclose this message or any attachment to anyone else without authorization of the sender. Unauthorized use, copying or disclosure may be unlawful. If this transmission is received in error please notify the sender immediately and delete this message from your email system.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org <ma...@pdfbox.apache.org>
> For additional commands, e-mail: users-help@pdfbox.apache.org <ma...@pdfbox.apache.org>
Re: Orientation printout - used 2.0.0.RC3 release
Posted by John Hewson <jo...@jahewson.com>.
> On 15 Mar 2016, at 13:12, Tilman Hausherr <TH...@t-online.de> wrote:
>
> 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:
>
>
> if (mediaBox.getWidth() > mediaBox.getHeight())
> {
> // rotate
> paper = new Paper();
> paper.setSize(mediaBox.getHeight(), mediaBox.getWidth());
> paper.setImageableArea(cropBox.getLowerLeftY(), cropBox.getLowerLeftX(),
> cropBox.getHeight(), cropBox.getWidth());
> isLandscape = true;
> }
> else
You don’t want to do that though, because Java doesn’t handle landscape sized paper correctly. So it’s necessary to always print in portrait, rotating any landscape pages first, and flagging them as being landscape.
— John
> Here's the full code. If this doesn't get through, download the source code.
>
>
> public final class PDFPageable extends Book
> {
> private final PDDocument document;
> private final boolean showPageBorder;
> private final float dpi;
> private final Orientation orientation;
>
> /**
> * Creates a new PDFPageable.
> *
> * @param document the document to print
> */
> public PDFPageable(PDDocument document)
> {
> this(document, Orientation.AUTO, false, 0);
> }
>
> /**
> * 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);
> }
>
> /**
> * 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);
> }
>
> /**
> * 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 = document;
> this.orientation = orientation;
> this.showPageBorder = showPageBorder;
> this.dpi = dpi;
> }
>
> @Override
> public int getNumberOfPages()
> {
> return document.getNumberOfPages();
> }
>
> /**
> * {@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 = document.getPage(pageIndex);
> PDRectangle mediaBox = PDFPrintable.getRotatedMediaBox(page);
> PDRectangle cropBox = PDFPrintable.getRotatedCropBox(page);
>
> // 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 = new Paper();
> paper.setSize(mediaBox.getHeight(), mediaBox.getWidth());
> paper.setImageableArea(cropBox.getLowerLeftY(), cropBox.getLowerLeftX(),
> cropBox.getHeight(), cropBox.getWidth());
> isLandscape = true;
> }
> else
> {
> paper = new Paper();
> paper.setSize(mediaBox.getWidth(), mediaBox.getHeight());
> paper.setImageableArea(cropBox.getLowerLeftX(), cropBox.getLowerLeftY(),
> cropBox.getWidth(), cropBox.getHeight());
> isLandscape = false;
> }
>
> PageFormat format = new PageFormat();
> format.setPaper(paper);
>
> // auto portrait/landscape
> if (orientation == Orientation.AUTO)
> {
> if (isLandscape)
> {
> format.setOrientation(PageFormat.LANDSCAPE);
> }
> else
> {
> format.setOrientation(PageFormat.PORTRAIT);
> }
> }
> else if (orientation == Orientation.LANDSCAPE)
> {
> format.setOrientation(PageFormat.LANDSCAPE);
> }
> else if (orientation == Orientation.PORTRAIT)
> {
> format.setOrientation(PageFormat.PORTRAIT);
> }
>
> return format;
> }
>
> @Override
> public Printable getPrintable(int i)
> {
> if (i >= getNumberOfPages())
> {
> throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages());
> }
> return new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder, dpi);
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Orientation printout - used 2.0.0.RC3 release
Posted by Tilman Hausherr <TH...@t-online.de>.
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:
if (mediaBox.getWidth() > mediaBox.getHeight())
{
// rotate
paper = new Paper();
paper.setSize(mediaBox.getHeight(), mediaBox.getWidth());
paper.setImageableArea(cropBox.getLowerLeftY(),
cropBox.getLowerLeftX(),
cropBox.getHeight(), cropBox.getWidth());
isLandscape = true;
}
else
Here's the full code. If this doesn't get through, download the source code.
public final class PDFPageable extends Book
{
private final PDDocument document;
private final boolean showPageBorder;
private final float dpi;
private final Orientation orientation;
/**
* Creates a new PDFPageable.
*
* @param document the document to print
*/
public PDFPageable(PDDocument document)
{
this(document, Orientation.AUTO, false, 0);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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 = document;
this.orientation = orientation;
this.showPageBorder = showPageBorder;
this.dpi = dpi;
}
@Override
public int getNumberOfPages()
{
return document.getNumberOfPages();
}
/**
* {@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 = document.getPage(pageIndex);
PDRectangle mediaBox = PDFPrintable.getRotatedMediaBox(page);
PDRectangle cropBox = PDFPrintable.getRotatedCropBox(page);
// 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 = new Paper();
paper.setSize(mediaBox.getHeight(), mediaBox.getWidth());
paper.setImageableArea(cropBox.getLowerLeftY(),
cropBox.getLowerLeftX(),
cropBox.getHeight(), cropBox.getWidth());
isLandscape = true;
}
else
{
paper = new Paper();
paper.setSize(mediaBox.getWidth(), mediaBox.getHeight());
paper.setImageableArea(cropBox.getLowerLeftX(),
cropBox.getLowerLeftY(),
cropBox.getWidth(), cropBox.getHeight());
isLandscape = false;
}
PageFormat format = new PageFormat();
format.setPaper(paper);
// auto portrait/landscape
if (orientation == Orientation.AUTO)
{
if (isLandscape)
{
format.setOrientation(PageFormat.LANDSCAPE);
}
else
{
format.setOrientation(PageFormat.PORTRAIT);
}
}
else if (orientation == Orientation.LANDSCAPE)
{
format.setOrientation(PageFormat.LANDSCAPE);
}
else if (orientation == Orientation.PORTRAIT)
{
format.setOrientation(PageFormat.PORTRAIT);
}
return format;
}
@Override
public Printable getPrintable(int i)
{
if (i >= getNumberOfPages())
{
throw new IndexOutOfBoundsException(i + " >= " +
getNumberOfPages());
}
return new PDFPrintable(document, Scaling.ACTUAL_SIZE,
showPageBorder, dpi);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org