Hi!
I had a problem. I’m trying to insert image to PDF. That image is tiff stream with CCITT Group 4 compression (monochrome).
But when it’s inserted to PDF - I see that it said that it stored as RGB
Means I expect to see in PDF something like this
/Type/XObject/Subtype/Image/Width 2550/Height 3608/Length 67743/ColorSpace/DeviceGray/BitsPerComponent 1/Filter/CCITTFaxDecode/DecodeParms
But I see
Filter/DCTDecode/Length 563278/Type/XObject/Subtype/Image/Width 2481/Height 3508/ColorSpace/DeviceRGB/BitsPerComponent 8/Name/Im
Any ideas how to insert image objects without extra processing in background?
@vabrutski
Сould you provide the files and code (snippet) with which the problem occurs?
According to the description, it can be assumed that a flag must be set in order to be saved in BW.
Hi Sergey. Thanks.
Which flag do you mean?
My tiff file is in CCITT 4 format (already 1 bit image)
I’m using code from that example Convert various Images formats to PDF in .NET|Aspose.PDF for .NET
public static void TiffToPDF2()
{
// Initalize new Document
Document pdf = new Document();
//Load TIFF image into stream
Bitmap bitmap = new Bitmap(File.OpenRead(_dataDir+"multipage.tif"));
// Convert multi page or multi frame TIFF to PDF
FrameDimension dimension = new FrameDimension(bitmap.FrameDimensionsList[0]);
int frameCount = bitmap.GetFrameCount(dimension);
// Iterate through each frame
for (int frameIdx = 0; frameIdx <= frameCount - 1; frameIdx++)
{
Page page = pdf.Pages.Add();
bitmap.SelectActiveFrame(dimension, frameIdx);
MemoryStream currentImage = new MemoryStream();
bitmap.Save(currentImage, ImageFormat.Tiff);
Aspose.Pdf.Image imageht = new Aspose.Pdf.Image
{
ImageStream = currentImage,
//Apply some other options
//ImageScale = 0.5
};
page.Paragraphs.Add(imageht);
}
// Save output PDF file
pdf.Save(_dataDir + "TifftoPDF.pdf");
}
Ok. I got it. You speaking about IsBlackAndWhite for Image class.
In Documentation it said: “If TIFF image of CCITT subformat is used, this property must be set to true.”
It’s exactly my case.
Interesting that when I set it to true. Process stuck inside PdfDocument.Save(…)
@vabrutski
Is it stuck or does it take a long time?
Perhaps you should wait longer.
I found that it was a bug in my version of Aspose. I need to update and check again.
Thank you for idea with special option. Looks like it’s a right direction
Another related quiestion. Probably you know.
IsBlackWhite is defined in Image class.
Image class I can add to paragraph. And when I do so - it doesn’t tak full widht\heigh of page.
How to do that with Image that I add to Paragrapth to be placed(stretched) full width\height
When I do page.AddImage - it works as expected, but there is no option for IsBaclWhite then
@vabrutski
you need to set FixWidth and FixHeight for the image object.
code snippet
string inFile = GetInputPath("untitled.png");
string outFile = GetOutputPath("test.pdf");
using (var doc = new Aspose.Pdf.Document())
{
var image = new Aspose.Pdf.Image
{
File = inFile,
FixWidth = doc.PageInfo.Width,
FixHeight = doc.PageInfo.Height,
IsBlackWhite = true
};
var page = doc.Pages.Add();
page.Paragraphs.Add(image);
doc.Save(outFile);
}
Thanks. Finally I finf out that I need to do the same for page itsel, not only for image.
@vabrutski
Glad you were able to resolve the issue.