We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to Generate a Grayscale TIFF image from color PDF (using Aspose.PDF)

Hi


I am converting a PDF document to TIFF image and while converting I want TIFF image to be a grayscale (or black & white). My PDF document has colors and TIFF is also coming with colors. How can I get a TIFF which is GrayScale? Below is my code. inputStream is a PDF document.

MemoryStream outputStream = null;
//Open document
Document pdfDocument = new Document(inputStream);

//Create Resolution object
Resolution resolution = new Resolution(300);
//Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.LZW;
tiffSettings.Depth = ColorDepth.Format4bpp;
tiffSettings.Shape = ShapeType.Portait;
tiffSettings.SkipBlankPages = false;
//Create TIFF device
TiffDevice tiffDevice = new TiffDevice(PageSize.PageLetter, resolution, tiffSettings);

outputStream = new MemoryStream();

tiffDevice.Process(pdfDocument, 1, pdfDocument.Pages.Count, outputStream);


Any help is greatly appreciated.
Thanks
Piyush

Hi Piyush,


Thanks for contacting support.

In order to accomplish your requirement, please try using Format1bpp value from ColorDepth class. In case you encounter any issue, please share the resource file so that we can test the scenario at our end.

Hey,

I do this:


==========================================
Resolution resolution = new Resolution(200);

TiffSettings tiffSettings = new TiffSettings();
tiffSettings.setCompression(CompressionType.LZW);
tiffSettings.setDepth(ColorDepth.Format1bpp);
tiffSettings.setSkipBlankPages(false);


Document document = new Document(file.getAbsolutePath());

TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);

for (int i=0; i<document.getPages().size(); i++) {
fileName++;

tiffDevice.process(document, i+1, i+1, fileName + “.tif”);
}
==========================================

The created TIFF is an “Indexed color (2 colors)” and not a simple “Grayscale”, is there a way to do this?

thx
Michael

Hi Michael,


Thanks for sharing the details.

I am afraid the current release of Aspose.Pdf for .NET does not support the feature to convert PDF from RGB colorspace to GrayScale colorspace. For the sake of implementation, we already have logged this requirement as PDFNEWNET-16222 in our issue tracking
system. The development team will further look into the details of this requirement and will keep you
updated on the status of correction. Please be patient and spare us little
time. We are sorry for this inconvenience.

<o:p></o:p>

Hi Michael,


Can you please share the source PDF and resultant TIFF so that we can further investigate the issue reported earlier.

do you still need examples for this issue?

Hi Michael,


The reasons we requested the resource files (input PDF and output TIFF) so that we have a better understand of your requirement. These artifacts will really help us during the implementation of this feature.

The issues you have found earlier (filed as PDFNEWNET-16222) have been fixed in Aspose.Pdf for .NET 10.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(2)

Hi,

did you resolve the issue also on Java Plattform. I’m using Aspose Pdf 11.1.0 for JAVA and I think I still can’t create an grayscale image.

thx
Michael

Hi Michael,


We have not yet tested the scenario using Aspose.Pdf for Java but we are working on testing it and will share our findings, shortly.

michael.burger@siag.it:
Hi,

did you resolve the issue also on Java Plattform. I’m using Aspose Pdf 11.1.0 for JAVA and I think I still can’t create an grayscale image.
Hi Michael,

I have further tested the scenario and have observed that the class RgbToDeviceGrayConversionStrategy (which is used to convert RGB colorspace PDF to GrayScale) is currently not implemented in Aspose.Pdf for Java. However for the sake of correction, I have logged this problem as PDFNEWJAVA-35448 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as PDFNEWJAVA-35448) have been fixed in Aspose.Pdf for Java 11.2.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi,
can you post a simple snipped to create Grayscale TIFF image from a color PDF using the RgbToDeviceGrayConversionStrategy class?

thx
Marco

Hi Piyush,


Please try using following code snippet.

[Java]

Document document = new Document(“c:/pdftest/New+folder1.pdf”);<o:p></o:p>

com.aspose.pdf.RgbToDeviceGrayConversionStrategy strategy = new com.aspose.pdf.RgbToDeviceGrayConversionStrategy();

for (int idxPage = 1; idxPage <= document.getPages().size(); idxPage++)

{

Page page = document.getPages().get_Item(idxPage);

strategy.convert(page);

}

document.save("c:/pdftest/GrayScale_output.pdf");

Hi,
I need to create a tiff grayscale image, and not a new pdf document.
I try with the following code,

==========================================
Resolution resolution = new Resolution(200);
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.setCompression(CompressionType.LZW);
tiffSettings.setDepth(ColorDepth.Format1bpp);
tiffSettings.setSkipBlankPages(false);
RgbToDeviceGrayConversionStrategy strategy = new RgbToDeviceGrayConversionStrategy();
Document document = new Document("c:/pdftest/New+folder1.pdf");
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);

for (int i=0; i<document.getPages().size(); i++) {
fileName++;
strategy.convert(document.getPages().get_Item(i+1));
tiffDevice.process(document, i+1, i+1, fileName + ".tif");
}
==========================================

but the result is a tiff with a color table

Band 1 Block=1653x39 Type=Byte, ColorInterp=Palette
Image Structure Metadata:
NBITS=1
Color Table (RGB with 2 entries)
0: 255,255,255,255
1: 0,0,0,255

thx
Marco

Hi Piyush,


Thanks for sharing the details and my apologies for the confusion. Yes in order to convert PDF pages to TIFF image, you need to use TiffDevice class. However during my testing with latest release of Aspose.Pdf for Java 11.2.0 in Eclipse Mars project with JDK 1.8.0_74, I am unable to notice any issue and as per my observations, the resultant pages are gray-scale. Can you please share your input PDF files which you are using, so that we can test the scenario in our environment. We are sorry for this inconvenience.

[Java]

Resolution resolution = new
Resolution(200);<o:p></o:p>

TiffSettings tiffSettings = new TiffSettings();

tiffSettings.setCompression(CompressionType.LZW);

tiffSettings.setDepth(ColorDepth.Format1bpp);

tiffSettings.setSkipBlankPages(false);

RgbToDeviceGrayConversionStrategy strategy = new RgbToDeviceGrayConversionStrategy();

Document document = new Document("c:/pdftest/M2.PDF");

TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);

int fileName=0;

for (int i=0; i<document.getPages().size(); i++) {

fileName++;

strategy.convert(document.getPages().get_Item(i+1));

tiffDevice.process(document, i+1, i+1,"c:/pdftest/M2_" +fileName + ".tif");

}

Hi,
in attachment a simple pdf file. The tiff seams to be a grayscale tiff, but if you user a gdal library (http://www.gdal.org/) to read the meta info the result is a RGB color table.

Thanks,
Marco

Hi Marco,


Thanks for sharing the details.

I have logged this problem as PDFNEWJAVA-35555 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.