John van de Pol
2016-02-02 06:37:30 UTC
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
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