When I try to convert a multi-page PDF document to Tiff, the first page always looks fine. However, all the middle pages and sometimes the last page come out all black. The document I’m using does have a mix of Portrait and Landscape pages – which do appear to be recognized, but are all black.
Here is the code snippet I am using:
public byte[] PdfToTiff(byte[] pdf)
{
try
{
using var originalMemoryStream = new MemoryStream(pdf);
using var originalPdf = new PdfDocument(originalMemoryStream);
var resolution = new Resolution(150);
var tiffSettings = new TiffSettings
{
Compression = CompressionType.LZW,
Depth = ColorDepth.Format8bpp,
Shape = ShapeType.None,
SkipBlankPages = true,
};
var tiffDevice = new TiffDevice(resolution, tiffSettings);
using var tiffMemoryStream = new MemoryStream();
tiffDevice.Process(originalPdf, tiffMemoryStream);
return tiffMemoryStream.ToArray();
}
catch (Exception e)
{
throw new Exception("Pdf.ConvertToTiff Error.", e);
}
}
@kuenne
What version of the library are you using, what OS?
In my envirinment In Windows with the library version 24.10, the attached file is converted correctly.
I listed the library version at the start of the post. Is there some other version you need? If so, could you let me know where to find it?
This has been reproduced by multiple people/machines. I should mention, that it is ‘intermittent’, in that it sometimes works. So, you may need to run it a few times to see the failure; For me, it fails 90% of the time.
I should also mention that if I change the compression, I can get the black pages to instead appear transparent.
Windows spec:
Edition: Windows 10 Enterprise
Version: 22H2
OS build: 19045.5011
Experience: Windows Feature Experience Pack 1000.19060.1000.0
@kuenne
I tried to reproduce the error using the following code fragment (ran it several times and checked all created documents) - but did not get any incorrect documents.
try
{
using var originalPdf = new Document(dataDir + "MultipageSample.pdf");
var resolution = new Resolution(150);
var tiffSettings = new TiffSettings
{
Compression = CompressionType.LZW,
Depth = ColorDepth.Format8bpp,
Shape = ShapeType.None,
SkipBlankPages = true,
};
var tiffDevice = new TiffDevice(resolution, tiffSettings);
for (short i = 0; i < 15; i++)
{
using var tiffMemoryStream = new MemoryStream();
tiffDevice.Process(originalPdf, tiffMemoryStream);
File.WriteAllBytes(dataDir + $"conv_to_tif_{i}.tif", tiffMemoryStream.ToArray());
}
}
catch (Exception e)
{
throw new Exception("Pdf.ConvertToTiff Error.", e);
}
Possible reasons:
slightly modified code compared to yours (the one you provided was not quite complete) - please check if the provided code works in your environment?
using multithreaded processing for one document - or do you also perform the conversion sequentially?
checked in the .Net 6 project, which one do you use?
I’m on a “net8.0” project running on a x64 Windows environment.
I ran the exact code you provided in my environment (no memory streams), and am still getting the black frames in the tiff.
RE: multithreaded - I have a unit test that I am running on its own (not in a batch with other tests). So, No, there is no multiple thread issue happening.
@kuenne
Thank you for writing to us and providing full information. I have reproduced the error and will create a task for the development team.
As a workaround, I can recommend using the Aspose.Pdf library for working in Windows - this effect is not observed with it.
@kuenne
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-58620
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.