pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: Problems positioning image when printer resizes document
Date Thu, 10 Mar 2016 21:39:23 GMT

> On 8 Mar 2016, at 10:14, Kevin Ternes <KTernes@thegeneral.com> wrote:
> 
> I am using ZXing to put a data matrix on each page of a workflow of documents that I
am sending to the mailroom like so:
> 
>  Given pdDocument, pdPage, String contents, size, x, y:
> 
>     BitMatrix bitMatrix = new DataMatrixWriter().encode(contents, BarcodeFormat.DATA_MATRIX,
size, size);
>     BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
>     PDImageXObject pdImageXObject = LosslessFactory.createFromImage(pdDocument, bufferedImage);
>     PDPageContentStream pdPageContentStream = new PDPageContentStream(pdDocument, pdPage,
true, false);
>     pdPageContentStream.drawImage(pdImageXObject, x, y, size, size);
>     IOUtils.closeQuietly(pdPageContentStream);
> 
> The data matrix needs to be sized and positioned with some precision on the printed page
to support the mailroom sorting/enveloping process.
> But so far I have trouble with that because:
> #1 - The source documents are of all inconsistent width/height on the page
> #2 - To deal with #1, the mailroom printer drivers all specify a "Fit" option which will
shrink oversized pages and expand undersized pages.
> 
> Can anyone suggest a solution so that I can get the data matrix sized and positioned
correctly regardless of the input size and "fitting"?
> Using PDFBox-2.0.0-RC3.

So what you’re saying is that the mailroom takes your document and resizes it, meaning that
the matrix image you’ve added ends up in the wrong place?

If so, you have a two options:

1)  resize the documents yourself first, so that the mailroom won’t make any changes, that
way you can basically work with the final “fitted” document. PDFormXObject gives you the
ability to embed content from other PDFs, so you could make one for each page, you can set
a custom scaling matrix on the form to rescale the original page.

2) calculate the affine transform required to convert given PDF into a “fitted” document,
then invert the affine transform and use that to scale your overlayed image. You’ll end
up with a strange shaped overlay which when “fitted” will look exactly right.

In either case, you need to know how the mailroom’s “fit” works, so that you can simulate
it.

— John

> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message