pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: Rendering PDImageXObject
Date Fri, 14 Aug 2015 03:59:02 GMT

> On 13 Aug 2015, at 08:15, Kirk, Kenneth <Kkirk@ILSOS.NET> wrote:
> 
> When I create a PDF page and draw the image onto the page without any scaling applied
to the image, it is drawn at the DPI of the tiff, 200 DPI in most instances.  Later when I
retrieve the PDFs and encounter a PDF page has a image drawn on to it I won't know what DPI
was used to drawn the image on the page if it didn’t come from one of my applications. 
When I render the image using defaults it is rendered at 72 DPI which is the PDF default.
 So if the iamge was original drawn at 200 DPI it would look larger than it really is.  No
problem for screen viewing but a big problem for filming where space is at finite.

Ok, to recap: you’re extracting an image which is drawn on a PDF page and you’re wanting
to know the size of the image relative to the page. The embedded image itself is at a high
resolution, so is much bigger than the page if drawn without the appropriate scale.

First of all, if your images are full page sized then you can simply render the page with
PDFBox at your chosen DPI and use the resulting image instead.

Otherwise, you’ll need to obtain the current transform matrix (CTM) which is being used
at the point that the image is drawn. If you look at the ExtractImages example which ships
with PDFBox, then in the drawImages override you can add the following line to fetch this:

Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();

That matrix contains the scaling for the image, as well as any rotation and skew. For x and
y scalling, you want getScalingFactorX() and getScalingFactorY().

Hope that helps,

— John

> -----Original Message-----
> From: John Hewson [mailto:john@jahewson.com] 
> Sent: Wednesday, August 12, 2015 7:24 PM
> To: users@pdfbox.apache.org
> Subject: Re: Rendering PDImageXObject
> 
> Ok, that makes sense. Which part are you having a problem with?
> 
> — John
> 
>> On 12 Aug 2015, at 07:31, Kirk, Kenneth <Kkirk@ILSOS.NET> wrote:
>> 
>> I'm doing both.  I provide a service that takes tiff files from one of the various
processes we use to generate official documents and converts them to PDFs so they can be stored
in a document management system.  Then for archival purposes I have to take selected documents
from the document management system and convert them back to tiff so they will run through
the software/hardware that converts them to microfilm for a disaster recovery policy requirement.
>> 
>> -----Original Message-----
>> From: John Hewson [mailto:john@jahewson.com] 
>> Sent: Tuesday, August 11, 2015 9:11 PM
>> To: users@pdfbox.apache.org
>> Subject: Re: Rendering PDImageXObject
>> 
>> 
>>> On 11 Aug 2015, at 08:19, Kirk, Kenneth <Kkirk@ILSOS.NET> wrote:
>>> 
>>> John
>>> 
>>> How would I know what DPI the image was drawn with?  Some of the PDF pages come
from source outside of my control but I have to extract them just the same.
>> 
>> I’m confused, you said you were converting TIFFs to PDF but now you mention PDF
pages from external sources? Are you reading the PDFs or writing them? Did you mean that the
TFF images come from an external source?
>> 
>> — John
>> 
>>> -----Original Message-----
>>> From: John Hewson [mailto:john@jahewson.com] 
>>> Sent: Monday, August 10, 2015 1:38 PM
>>> To: users@pdfbox.apache.org
>>> Subject: Re: Rendering PDImageXObject
>>> 
>>> 
>>>> On 10 Aug 2015, at 05:58, Kirk, Kenneth <Kkirk@ILSOS.NET> wrote:
>>>> 
>>>> I have a situation that maybe someone has already solved in a more efficient
manner.  When converting a tiff image to PDF I use the drawImage method of the PDPageContentStream.
 The tiff image has a resolution of 200 DPI which is 1700x2200.  When PDFRenderer renders
this image from the resulting PDF page  it does so at the PDF default of 72 DPI which logically
translates to page 23 inches by 30 inches when applied to the original iamge size of 1700x2200.
 Since I don't know after the fact what DPI a image object on PDF page was drawn at I came
up with down scaling the image at PDF creation time to 72 DPI.  I'm sure there must a better
way one of you computer science PHDs have come up with.
>>>> 
>>> 
>>> You can draw the image with a scale of 72 / 200, in other words:
>>> 
>>> double dpi = 200; // you’ll want to fetch this from the tiff content.drawImage(image,
x, y, image.getWidth() * 72 / dpi, image.getHeight() * 72 / dpi;
>>> 
>>> — John
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> ************************************************
>>> Disclaimer - This email and any files transmitted with it are confidential and
contain privileged or copyright information. You must not present this message to another
party without gaining permission from the sender. If you are not the intended recipient you
must not copy, distribute or use this email or the information contained in it for any purpose
other than to notify the Office of the Illinois Secretary of State. 
>>> 
>>> If you have received this message in error, please notify the sender immediately,
and delete this email from your system. Any views expressed in this message are those of the
individual sender, except where the sender specifically states them to be the views of the
Office of the Illinois Secretary of State. 
>>> ************************************************
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> ************************************************
>> Disclaimer - This email and any files transmitted with it are confidential and contain
privileged or copyright information. You must not present this message to another party without
gaining permission from the sender. If you are not the intended recipient you must not copy,
distribute or use this email or the information contained in it for any purpose other than
to notify the Office of the Illinois Secretary of State. 
>> 
>> If you have received this message in error, please notify the sender immediately,
and delete this email from your system. Any views expressed in this message are those of the
individual sender, except where the sender specifically states them to be the views of the
Office of the Illinois Secretary of State. 
>> ************************************************
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ************************************************
> Disclaimer - This email and any files transmitted with it are confidential and contain
privileged or copyright information. You must not present this message to another party without
gaining permission from the sender. If you are not the intended recipient you must not copy,
distribute or use this email or the information contained in it for any purpose other than
to notify the Office of the Illinois Secretary of State. 
> 
> If you have received this message in error, please notify the sender immediately, and
delete this email from your system. Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be the views of the Office of
the Illinois Secretary of State. 
> ************************************************
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message