Hi,
This is happening for the another document for the same code, attached is the overall code which we are using for Grayscale conversion and compression which will be called sequentially.
Grayscale_Compression_Code_Snippet.docx (21.5 KB)
For earlier shared document we are not getting this issue for the same code attached above.
@Aswin0892
Please attach the document with which this situation occurs.
Hi @sergei.shibanov,
Attached is the sample document in which we are getting blackout issue when we are using the Grayscale & Compression code.
ct18665164758-20240707111257824-274-50.pdf (95.6 KB)
@Aswin0892
I tried to reproduce the problem using the following code.
using (var doc = new Aspose.Pdf.Document(dataDir + "ct18665164758-20240707111257824-274-50.pdf"))
{
var strategy = new Aspose.Pdf.RgbToDeviceGrayConversionStrategy();
for (int idxPage = 1; idxPage <= doc.Pages.Count; idxPage++)
{
// Get instance of particular page inside PDF
Page page = doc.Pages[idxPage];
// Convert the RGB colorspace image to GrayScale colorspace
strategy.Convert(page);
}
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
optimizationOptions.ImageCompressionOptions.MaxResolution = 200;
doc.OptimizeResources(optimizationOptions);
doc.Save(dataDir + "black-out.pdf");
}
In my environment, a valid document is obtained (for the library version 24.06).
black-out.pdf (66.8 KB)
Maybe this code has differences from the one you use.
By the way I wanted to note that when you call Dispose inside using, you end up calling Dispose twice on the same object, and this is incorrect.
1.png (45.3 KB)
@sergei.shibanov,
Try doing the optimization again for the “black-out.pdf” document using the compression code, there only the pages are getting blackout.
Note: This was not happening with version 24.2.0 with the same code.
using (var doc = new Aspose.Pdf.Document(dataDir + "ct18665164758-20240707111257824-274-50.pdf"))
{
var strategy = new Aspose.Pdf.RgbToDeviceGrayConversionStrategy();
for (int idxPage = 1; idxPage <= doc.Pages.Count; idxPage++)
{
// Get instance of particular page inside PDF
Page page = doc.Pages[idxPage];
// Convert the RGB colorspace image to GrayScale colorspace
strategy.Convert(page);
}
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
optimizationOptions.ImageCompressionOptions.MaxResolution = 200;
doc.OptimizeResources(optimizationOptions);
doc.Save(dataDir + "black-out.pdf");
var optimizationOptions1 = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions1.RemoveUnusedObjects = true;
optimizationOptions1.RemoveUnusedStreams = true;
optimizationOptions1.AllowReusePageContent = true;
optimizationOptions1.LinkDuplcateStreams = true;
optimizationOptions1.UnembedFonts = true;
optimizationOptions1.ImageCompressionOptions.CompressImages = true;
optimizationOptions1.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions1.ImageCompressionOptions.ResizeImages = true;
optimizationOptions1.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
optimizationOptions1.ImageCompressionOptions.MaxResolution = 200;
doc.OptimizeResources(optimizationOptions1);
doc.Save(dataDir + "black-out1.pdf");
}
image.png (33.0 KB)
image.jpg (82.1 KB)
@Aswin0892
Thanks for the tip, when adding another call to
doc.OptimizeResources(optimizationOptions);
the result is really invalid.
(and conversion to gray does not affect the reproduction of the problem).
I’ll create a task for the development team.
1 Like
@Aswin0892
I did it simpler - I called doc.OptimizeResources twice.
But I think the result is the same.
using (var doc = new Aspose.Pdf.Document(dataDir + "ct18665164758-20240707111257824-274-50.pdf"))
{
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
optimizationOptions.ImageCompressionOptions.MaxResolution = 200;
doc.OptimizeResources(optimizationOptions);
doc.OptimizeResources(optimizationOptions); // call twice
doc.Save(dataDir + "black-out.pdf");
}
black-out.pdf (64.5 KB)
1 Like
@Aswin0892
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-57627
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.
The issues you have found earlier (filed as PDFNET-57627) have been fixed in Aspose.PDF for .NET 24.9.
Hi @sergei.shibanov ,
We have updated to the latest Aspose version 24.9.0, but still we are getting the black out issue for the files.
@Aswin0892
This is for one of the cases for which the tasks were created or for some other?
If for another, please provide the code snippet and document used.
Hi @sergei.shibanov ,
This is happening with the same code snippet which I have shared previously.
@Aswin0892
There were two tasks created in this thread, which one are you talking about?
56561.png (12.5 KB)
57627.png (22.4 KB)
Hi @sergei.shibanov,
Still some of the files getting blacked out during compression which is in thread 57627 and other during grayscale conversion which is in thread 56561 (now majorly getting in this thread). Unfortunately, we cannot share the document for testing since it is a Production data.
Is there any way we can get the source code so that we can customize the logic accordingly for our requirement?
@Aswin0892
No in any way.
Maybe try to delete (change) sensitive data so that the problem remains and can be reproduced.