pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stahle, Patrick" <patrick.sta...@te.com>
Subject RE: drawing images with rotation PDFBox 2.0
Date Fri, 04 Mar 2016 20:04:06 GMT
I tried the following but the image now no longer draws...
	AffineTransform at = new AffineTransform(rect.getWidth(), 0, 0, rect.getHeight(), rect.getLowerLeftX(),
rect.getLowerLeftY());
	PDPageContentStream canvas = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND,
true, true);
	at.rotate(Math.toRadians(90));
	canvas.saveGraphicsState();
	canvas.transform(new Matrix(at));
	canvas.drawImage(ximage, rect.getLowerLeftX(), rect.getLowerLeftY());
	canvas.restoreGraphicsState();
	canvas.close();

Did I misunderstand something?

As for the imaging squishing I am seeing. It looks to me like the rectangle size / position
of the image non rotated stays exactly the same but the contents are rotated and squished.
I can send you a couple pdfs showing what I mean (direct email?). And maybe that is how it
is supposed to work, but I would of expected the image to look exactly the same just rotated.
In case of 90 degrees, like the example above, I would of expect simply the width to become
the height and the height to become the width.

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Friday, March 04, 2016 2:44 PM
To: users@pdfbox.apache.org
Subject: Re: drawing images with rotation PDFBox 2.0

Am 04.03.2016 um 20:35 schrieb Stahle, Patrick:
> Hi,
>
> I am struggling with rotating an image. For instance I have the following code:
> AffineTransform at = new AffineTransform(rect.getWidth(), 0, 0, 
> rect.getHeight(), rect.getLowerLeftX(), rect.getLowerLeftY()); PDPageContentStream canvas
= new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, true);
>                  at.rotate(Math.toRadians(90));
>                  canvas.drawXObject(ximage, at);
>                  canvas.close();
>
> It seems to work, but not the way I would've expected it to. It rotates the image but
keeps the original boxed rectangle size which in this case squishing the image. Is this expected
behavior, and if so is there way for an image to rotate and keep the sizing? I kind of hoped
it work the same way as rotating text...

Sorry I don't understand you... why should it not keep the size?

>
> Also on a PDFBox 2.0 note, the "PDPageContentStream  -> drawXObject' is deprecated
and the source says to use drawImage instead. However I was not able to find a drawImage method
that takes AffineTransform. What is the recommended way to do this in 2.0 going forward?

         saveGraphicsState();
         transform(new Matrix(transform));  <== do the rotation only

          drawImage()     <=== here just set the position

         restoreGraphicsState();



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