iText 7 pdfimagexobject

0

I'm trying to iterate through pdf's and replace the images with smaller jpegs using c# and itext 7.

We receive the PDF's so I have zero control on how they are made.

As I iterate through a pages xobjects, when the image is a TIFF, it explodes as I try to get the streams bytes.

if (PdfName.Image.Equals(subtype)) 
{

var pdfImageXObject = new PdfImageXObject(stream);
var fileExtention = pdfImageXObject.IdentifyImageFileExtension();  
var fileType = pdfImageXObject.IdentifyImageType();
byte[] bytes = pdfImageXObject.GetImageBytes();  -- ERROR'S HERE ON TIFF
...

iText.IO.IOException HResult=0x80131500 Message=The color depth 4 is not supported. Source=itext.kernel StackTrace: at iText.Kernel.Pdf.Xobject.ImagePdfBytesInfo.DecodeTiffAndPngBytes(Byte[] imageBytes) at iText.Kernel.Pdf.Xobject.PdfImageXObject.GetImageBytes(Boolean decoded) at iText.Kernel.Pdf.Xobject.PdfImageXObject.GetImageBytes()

Is there any way to get the raw TIFF???

Thanks!

* EDIT * At this point I'm wrapping in a try catch and ignoring the bad TIFF. =( I wish iText 7 would just give the raw byte array which wouldn't throw an exception.

c#
itext
itext7
asked on Stack Overflow May 5, 2020 by William • edited May 13, 2020 by William

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0