[
https://issues.apache.org/jira/browse/PDFBOX-5179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17332925#comment-17332925
]
Michael Carell commented on PDFBOX-5179:
----------------------------------------
Sorry, I used a modified version of the PrintImageLocation that saves the
images to the file storage.
The original idea was to extract images from an PDF document in the same
orientation, as they will be displayed in an PDFViewer. I tried the command
line tool ExtractImages, but this tools saves images as they are stored within
the PDF. So some of them are rotated. So I followed the code in
PrintImageLocations to find out the applied rotations and then negate them.
Here is the modified code from PrintImageLocations. The code works fine for
most PDF, exept the mentiond Testdocument.pdf.
{color:#0033b3}if
{color}({color:#067d17}"Do"{color}.equals({color:#000000}operation{color})) {
{color:#000000}COSName objectName {color}= ({color:#000000}COSName{color})
operands.get({color:#1750eb}0{color});
{color:#000000}PDXObject xobject {color}=
getResources().getXObject({color:#000000}objectName{color});
{color:#0033b3}if {color}({color:#000000}xobject
{color}{color:#0033b3}instanceof {color}{color:#000000}PDImageXObject{color}) {
{color:#000000}PDImageXObject image {color}=
({color:#000000}PDImageXObject{color}) {color:#000000}xobject{color};
{color:#000000}PDPage page {color}= getCurrentPage();
{color:#0033b3}int {color}{color:#000000}pageRotation {color}=
({color:#0033b3}int{color}) {color:#000000}page{color}.getRotation();
{color:#000000}Matrix ctmNew {color}=
getGraphicsState().getCurrentTransformationMatrix();
{color:#0033b3}int {color}{color:#000000}objectRotation {color}=
({color:#0033b3}int{color})
{color:#000000}Math{color}.round({color:#000000}Math{color}.toDegrees({color:#000000}Math{color}.atan2({color:#000000}ctmNew{color}.getShearY(),
{color:#000000}ctmNew{color}.getScaleY())));
{color:#0033b3}float {color}{color:#000000}imageXScale {color}=
{color:#000000}ctmNew{color}.getScalingFactorX();
{color:#0033b3}float {color}{color:#000000}imageYScale {color}=
{color:#000000}ctmNew{color}.getScalingFactorY();
{color:#0033b3}float {color}{color:#000000}imagePosX {color}=
{color:#000000}ctmNew{color}.getTranslateX();
{color:#0033b3}float {color}{color:#000000}imagePosY {color}=
{color:#000000}ctmNew{color}.getTranslateY();
{color:#0033b3}int {color}{color:#000000}trueRotation {color}=
{color:#000000}objectRotation {color}- {color:#000000}pageRotation{color};
{color:#0033b3}int {color}{color:#000000}imageWidth {color}=
{color:#000000}image{color}.getWidth();
{color:#0033b3}int {color}{color:#000000}imageHeight {color}=
{color:#000000}image{color}.getHeight();
{color:#000000}BufferedImage {color}bImage =
{color:#000000}image{color}.getImage();
bImage = {color:#000000}ImageUtil{color}.rotateImage(bImage, -{color:#1750eb}1
{color}* {color:#000000}trueRotation{color});
} {color:#0033b3}else if {color}({color:#000000}xobject
{color}{color:#0033b3}instanceof {color}{color:#000000}PDFormXObject{color}) {
{color:#000000}PDFormXObject form {color}=
({color:#000000}PDFormXObject{color}) {color:#000000}xobject{color};
showForm({color:#000000}form{color});
}
} {color:#0033b3}else {color}{
{color:#0033b3}super{color}.processOperator(operator, operands);
}
> PDFBox PrintImageLocations: Extracts images in wrong orientation
> ----------------------------------------------------------------
>
> Key: PDFBOX-5179
> URL: https://issues.apache.org/jira/browse/PDFBOX-5179
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.21
> Environment: Windows 10, Tomcat 9, jdk 1.8_0161
> Reporter: Michael Carell
> Priority: Major
> Attachments: 0137d7db-7ca3-4573-a73a-1386699d922c.jpeg,
> Testdokument.pdf, org_0137d7db-7ca3-4573-a73a-1386699d922c.jpeg
>
>
> The PrintImageLocation class writes images in the original and rotated
> format. I used the algorithm in a image processing application. I found some
> PDF documents, where the extracted pictures have a wrong orientation. I have
> build a document to test that case.
> How to reproduce:
> I have constructed a MS Word document, that contains 4 images with different
> rotation levels (0°, 90°, 180°, 270°). I exported the document to PDF format.
> If you call PrintImageLocation with that PDF, the pictures within the
> document, that are rotated are displayed in in the right order and the
> "rotate" images, have the orientation from the document.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]