Discussion:
[iText-questions] Extracted images are upside-down
John van de Pol
2016-02-02 06:37:30 UTC
Permalink
Hi all,



I searched the iText mailinglist fort his problem.

I found several, but none of the provided solutions work for me.



I am making a program for a friend of mine wich must extract images from a
pdf.

All the images are upside down, they are NOT rotated!!



Here's the pdf:
www.jpproducties.nl/Documents/order 200047.pdf
<http://www.jpproducties.nl/Documents/order%20200047.pdf>



Here's the extracted image from the first page:

www.jpproducties.nl/Documents/test_1_0.png



Here's my codesnippet.

The class has 2 methods.

1 without _outputFilePrefix and _outputFolder, this one is the one i intend
to use.

The other method can be used to write the images to file.

Both methods give the images upside down.



public void RenderImage(ImageRenderInfo renderInfo)

{

try

{

PdfImageObject image = renderInfo.GetImage();

if (image != null)

{

if (_outputFilePrefix.Length == 0 ||
_outputFolder.Length == 0)

{

var drawingImage = image.GetDrawingImage();

_retList.Add(drawingImage);

}

else

{

var imageFileName = String.Format("{0}_{1}_{2}.{3}",
_outputFilePrefix, _currentPage, _imageCount, image.GetFileType());

var imagePath =
System.IO.Path.Combine(_outputFolder, imageFileName);

if (_overwriteExistingFiles ||
!File.Exists(imagePath))

{

var imageRawBytes = image.GetImageAsBytes();

File.WriteAllBytes(imagePath, imageRawBytes);

}

// Subtle: Always increment even if file is not
written. This ensures consistency should only some

// of a PDF file's images actually exist.

_imageCount++;

}

}

}

catch (Exception)

{

}

}



Thank in advance for your help.



Best Regards,

JohnvandePol
mkl
2016-02-02 09:29:17 UTC
Permalink
Post by John van de Pol
I am making a program for a friend of mine wich must extract images from a
pdf.
All the images are upside down, they are NOT rotated!!
The reason simply is that the images ARE upside-down in the page resources
and are then flipped back up by the transformation matrix active when the
image is drawn.

The image data you store are from the page resources, no transformations
applied. If you want to know if some extraordinary transformation is applied
to it afterwards, you also have to check the renderInfo.GetImageCTM - the
current transformation matrix at the time the image is drawn.

E.g. in your case the top image is drawn using the instructions

604.29 0 0 -851.16 0 839 cm
/I0 Do

I.e. it is stretched to 604.29 units horizontally and -851.16 units
vertically, and that negative value for the y coordinate implies mirroring
the image resource upside-down.

To get an image exactly as rendered, you have to apply the equivalent
transformation to the image data you have retrieved using image processing
code.

Regards, Michael



--
View this message in context: http://itext.2136553.n4.nabble.com/Extracted-images-are-upside-down-tp4660992p4660993.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Loading...