Hi,
I got the same problem. Some documents are after converting into PDF/a 2B much bigger (I have one that is 19 kb and after converting 117 MB)
I try the posted code, but I run into two problems:
- When I set SubsetFonts = true in OptimizationOptions, then the pdf is after OptimizeResouces not an PDF/a. The PDFFormat-property display PDF 1.7, without SubsetFonts it works
- For some pdf’s I got an exception while saving: “cannot access a closed stream”
2017-Scrum-Guide-German.pdf (907.9 KB)
We are using Aspose.PDF 21.3
//var convetDoc = new Document(...);
var options = new PdfFormatConversionOptions(PdfFormat.PDF_A_2B);
options.ConvertSoftMaskAction = ConvertSoftMaskAction.ConvertToStencilMask;
options.ExcludeFontsStrategy = PdfFormatConversionOptions.RemoveFontsStrategy.SubsetFonts | PdfFormatConversionOptions.RemoveFontsStrategy.RemoveDuplicatedFonts;
options.ErrorAction = ConvertErrorAction.None;
options.OptimizeFileSize = true;
byte[] pdfDoc;
convertDoc.Flatten();
using (var memoryStream = new MemoryStream())
{
options.LogStream = memoryStream;
convertDoc.Validate(options);
}
using (var memoryStream = new MemoryStream())
{
options.LogStream = memoryStream;
convertDoc.Convert(options);
}
using (var strmOut = new MemoryStream())
{
convertDoc.OptimizeResources(
new Aspose.Pdf.Optimization.OptimizationOptions
{
//SubsetFonts = true,
RemoveUnusedStreams = true,
RemoveUnusedObjects = true,
});
convertDoc.Save(strmOut);
pdfDoc = strmOut.ToArray();
}