Colored Pdf is given as input for converting it to Tiff. The generated Tiff is colored in windows OS(used Spring Project in eclipse). But the same code when deployed in AWS ECS (linux environment), it is not working as expected. The generated Tiff is black and white. MSfonts is also installed in the container.
Following is the code used for Pdf to tiff conversion:
bais = new ByteArrayInputStream(FileUtils.readFileToByteArray(inputPdf));
pdfDocument = new Document(bais);
int numOfPages = pdfDocument.getPages().size();
resolution = new com.aspose.pdf.devices.Resolution(125);
com.aspose.pdf.devices.TiffSettings tiffSettings = new com.aspose.pdf.devices.TiffSettings();
tiffSettings.setCompression(CompressionType.RLE);
tiffSettings.setDepth(ColorDepth.Default);
tiffSettings.setSkipBlankPages(false);
// tiffSettings.setBrightness(0.9F);
// tiffSettings.Brightness = .9F;
tiffDevice = new com.aspose.pdf.devices.TiffDevice(resolution, tiffSettings);
baos = new ByteArrayOutputStream();
tiffDevice.process(pdfDocument, baos);
tifBytes = baos.toByteArray();
Input PDF sample:
inputPdf_7001120210323200020001.pdf (718.3 KB)
Output Generated:
Unable to attach directly the tiff generated. Please unzip to get the tiff.
Merged7001120210323200020001.zip (8.5 MB)
Merged7001120210323200020001.tiff.zip (5.8 MB)
Thanks in advance for valuable response.
Looking forward for a solution as soon as possible.
@AyshwaryaA
We have tested the scenario in our environment using Aspose.PDF for Java 21.5 and did not notice any issue. The output TIFF was not black and white. For your kind reference, a screenshot of the output TIFF is attached as well.
tiffoutput.jpg (92.9 KB)
Could you please try using the latest version of the API and let us know in case you still face any issue.
Hi Team,
I had updated the Aspose Pdf v to 21.5 and deployed in linux environment. Reprocessed the same pdf. Still the output tiff generated in linux environment is black and white. I haven’t made changes in code.
Please give suggestions to resolve it. MSfonts, truetype are already installed. Using Docker deployment is done. Linux distro is amazonlinux docker based.
JDK1.8 is being used.
Docker file :
FROM amazonlinux:2 as fontsbase
RUN yum update -y -q
&& yum install -y wget tar unzip gzip java-1.8.0-openjdk.x86_64 -q
RUN cd /tmp
&& mkdir -p /usr/share/fonts/msfonts
&& mkdir -p /usr/share/fonts/truetype/win7/
&& wget -q https://www.itzgeek.com/msttcore-fonts-2.0-3.noarch.rpm
&& rpm -Uvh msttcore-fonts-2.0-3.noarch.rpm
COPY msfonts.zip /usr/share/fonts/msfonts
WORKDIR /usr/share/fonts/msfonts/
RUN unzip /usr/share/fonts/msfonts/msfonts.zip
RUN cp /usr/share/fonts/msfonts/Fonts/*.tt? /usr/share/fonts/truetype/win7/
&& fc-cache -f -v
Is there anything to be installed additionally in linux environment.
Also if possible please share the code snippet used in your environment.
Attaching the putput tiff for your kind reference.
OutputTiff:
Please unzip to get the tiff
output.zip (4.4 MB)
Thanks in advance for valuable comments.
@AyshwaryaA
You may further try installing the libgdiplus package in the Linux environment. Also, please check the below code snippet that we used to test the scenario at our end:
System.out.println("Convert pdf to tiff...");
int compressingType = CompressionType.RLE; // Default to Color
int colorDepth = com.aspose.pdf.devices.ColorDepth.Default;
OutputStream imageStream = null;
Document pdfDocument = null;
try {
pdfDocument = new Document(dataDir + "inputPdf_7001120210323200020001.pdf");
imageStream = new FileOutputStream(dataDir + "sample.pdf.tiff");
com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(125); // abstract resolution that seems to correlate to dots per inch (DPI)
com.aspose.pdf.devices.TiffSettings tiffSettings = new com.aspose.pdf.devices.TiffSettings();
tiffSettings.setCompression(compressingType);
tiffSettings.setDepth(colorDepth);
tiffSettings.setSkipBlankPages(false);
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
tiffDevice.process(pdfDocument, imageStream);
pdfDocument.close();
} finally {
if (pdfDocument != null) {
pdfDocument.close();
}
if (imageStream != null) {
imageStream.close();
}
}
System.out.println("Converting pdf to tiff done");
Please let us know in issue still persists after installing the suggested package so that we may proceed further to assist you.