Error returned on return: Unknown PdfException. - - > System.NotSupportedException:Either itext7.bouncy-castle-adapter or itext7. bouncy-castle-fips-adap... On line
Var writer = new PdfWriter(stream);
My code is try to get create a pdf file using itext7 extension. In.net maui for mobile apps.
public static MemoryStream CreatePdf()
{
try
{
using (var stream = new MemoryStream())
{
var writer = new PdfWriter(stream);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
var paragraph = new Paragraph("hello");
document.Add(paragraph);
document.Close();
stream.Position = 0;
return stream;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
The reason it's occurring because from version 8.0, iText7 did several major breaking changes in the way they handle bouncy-castle dependencies. I assumed, your itext7 version is less than 8. So,
For resolving this issue, you need to install another Nuget package:
You can also check-out this answer, if you need more comprehensive solution including images.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With