Converting pdf to PDF/2A file with options don’t work
public byte[] CreateOutput(byte[] content)
{
using var stream = new MemoryStream();
var inputStream = () => GetFileStream(content);
using var converter = new Converter(inputStream);
var options = new PdfConvertOptions()
{
PageSize = PageSize.A4,
PdfOptions = new PdfOptions
{
PdfFormat = PdfFormats.PdfA_2A,
DocumentInfo = new PdfDocumentInfo
{
Producer = Producer,
Title = Title,
}
}
};
converter.Convert(() => stream, options);
return stream.ToArray();
}
when the input byte array is pdf file with more than one page throwing exception
Message “Cannot access a closed Stream.”
if the PdfOptions is PdfFormats.PdfA_2A
Converting pdf to PDF/2A file with options don’t work
public byte[] CreateOutput(byte[] content)
{
using var stream = new MemoryStream();
var inputStream = () => GetFileStream(content);
using var converter = new Converter(inputStream);
var options = new PdfConvertOptions()
{
PageSize = PageSize.A4,
PdfOptions = new PdfOptions
{
PdfFormat = PdfFormats.PdfA_2A,
DocumentInfo = new PdfDocumentInfo
{
Producer = Producer,
Title = Title,
}
}
};
converter.Convert(() => stream, options);
return stream.ToArray();
}
when the input byte array is pdf file with more than one page throwing exception
Message “Cannot access a closed Stream.”
if the PdfOptions is PdfFormat is PdfFormats.PdfA_2A
Can you please provide information about both the .NET version and the API version you are using? We haven’t been able to replicate this problem with the most recent API version. Are you encountering this issue with a particular PDF file?
I use .NET 6 and the Library version GroupDocs.Conversion 23.8.0
The issue is with those files that contains image in it.
It’s possible that the stream is being closed prematurely when GroupDocs.Conversion attempts to write data. This issue might arise due to the using
keyword, which disposes of the stream
when it goes out of scope. To investigate this further, you can try enclosing the code block in curly braces like this:
{
using (var stream = new MemoryStream())
{
// Define a function to obtain the input stream
var inputStream = () => GetFileStream(content);
// Create a Converter instance with the input stream
using var converter = new Converter(inputStream);
// Specify conversion options
var options = new PdfConvertOptions()
{
PageSize = PageSize.A4,
PdfOptions = new PdfOptions
{
PdfFormat = PdfFormats.PdfA_2A,
DocumentInfo = new PdfDocumentInfo
{
Producer = Producer,
Title = Title,
}
}
};
// Perform the conversion and write to the stream
converter.Convert(() => stream, options);
// Return the converted data as a byte array
return stream.ToArray();
}
}
By enclosing the code within curly braces, you ensure that the stream
remains in scope until the entire block is executed, which should help prevent premature closure and allow the conversion process to complete successfully.
Let us know if issue persists.
GroupDocs.Conversion.Exceptions.GroupDocsConversionException: Cannot access a closed Stream.
Same error.
With one file it work. With outers getting also this message
“GroupDocs.Conversion.Exceptions.GroupDocsConversionException: Object reference not set to an instance of an object”
Please share the sample application and the problematic file. Also share your development environment details.
@Andranik
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): CONVERSIONNET-6303
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.
I have changed the library version to 23.3.0 it’s work fine.
What I need. Are there any way to change the pdf file Conformance
Standard: PDF/A-2A
ISO Name: ISO 19005-2
and to
Standard: PDF/UA-1
ISO Name: ISO 14289-1
same time.
public byte[] CreateOutput(byte[] fileContent) { using (var stream = new MemoryStream()) { using var converter = new Converter(() => new MemoryStream(fileContent)); var options = new PdfConvertOptions() { PdfOptions = new PdfOptions { PdfFormat = PdfFormats.PdfA_2U, DocumentInfo = new PdfDocumentInfo { Author = default, Producer = Producer, Title = Title, CreationDate = default, CreationTimeZone = default, Creator = default, Keywords = default, ModDate = default, Subject = default } } }; converter.Convert(() => stream, options); return stream.ToArray(); } } )
with this method I can change the Conformance Standard to PDF/A-2A.
Are there way to change to PDF/A-2A and PDF/UA-1 in same file at same time without creating new PDF file.
Screenshot 2023-09-20 140646.png (1.5 КБ)
CONVERSIONNET-6303 is expected to be fixed in API version 23.9.
However, we’ll investigate this scenario as well.
Are there any other Lib that support this feature?
You might find it helpful to delve into the following documentation articles from Aspose.PDF (our sister company):
These resources can provide valuable insights for your needs. You can raise your concerns or get more details/information regarding Aspose.PDF at the free support forum.
The issues you have found earlier (filed as CONVERSIONNET-6303) have been fixed in this update. This message was posted using Bugs notification tool by nikola.yankov