1

When trying to write a pdf file, I get the exception when creating the Pdfwriter. Inner exception states:

Either itext7.bouncy-castle-adapter or itext7.bouncy-castle-fips-adapter dependency must be added in order to use BouncyCastleFactoryCreator.

Stack Trace: at iText.Kernel.Pdf.SmartModePdfObjectsSerializer..ctor() at iText.Kernel.Pdf.PdfWriter..ctor(Stream os, WriterProperties properties) at AWAData.frmWiringDiagram.WritePdfFile() in D:\GitRepo\PinMap\PinMap\frmWiringDiagram.cs:line 323

None of the examples that I have seen for iText7 does not show any code for BouncyCastleFactoryCreator.

Here is a piece of code section where the exception occurs with the PdfWriter in the using statement.

LicenseKey.LoadLicenseFile(new FileInfo("iTextKey.json"));
               
using (PdfWriter writer = new PdfWriter(pdfFile))
{
    using (PdfDocument pdfDocument = new PdfDocument(writer.SetSmartMode(true)))
    {
        iText.Layout.Document d = new iText.Layout.Document(pdfDocument,
            itext.Kernel.Geom.PageSize.LETTER);
        Paragraph newline = new Paragraph(new Text("\n"));
        d.Add(newline);
        for (int i = 0; i < tstHeader.Lines.Count(); i++)
        {
            if (tstHeader.Lines.GetValue(0).ToString().Length > 0)
            {
                ndx = i;
            }
        }
    }
}

I am using Visual Studio 2022 in C# to write the code.

Thanks for your time and consideration.

Ivan Gechev
  • 706
  • 3
  • 9
  • 21
Jet
  • 11
  • 2
  • What version are you using? Try using [iText7 version 7.2.5](https://www.nuget.org/packages/itext7/7.2.5). – Tu deschizi eu inchid Jun 08 '23 at 17:19
  • The following may be of interest:https://stackoverflow.com/a/76392303/10024425 and https://stackoverflow.com/a/75633930/10024425 – Tu deschizi eu inchid Jun 08 '23 at 17:21
  • 1
    Have you tried simply doing as the exception says, adding one of the two mentioned modules to your project? – mkl Jun 09 '23 at 12:00
  • When adding iText7 to project, it came with the itext.bouncy-castle-connector. – Jet Jun 09 '23 at 16:47
  • Tu deschizi eu inchid the iText version is 8.0.0.0 – Jet Jun 09 '23 at 16:48
  • *"When adding iText7 to project, it came with the itext.bouncy-castle-connector"* - yes, and that connector needs to connect with one of the two currently available adapters. Thus, add one of those adapter modules to your project, too. – mkl Jun 11 '23 at 07:44
  • Added itext7.bouncy-castle-adapter and just like magic, it worked! Thanks for the direction to add it! Appreciate it. – Jet Jun 14 '23 at 20:54

1 Answers1

0

You need Install iText version 7.x.x

Sen MS
  • 1
  • If you read the June comments to the question, you'd have seen that it is _not_ necessary to downgrade to v7. – mkl Jul 17 '23 at 14:05
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 20 '23 at 06:56