Skip to main content
Solved

Need help to resolve "Could not load file or assembly itextsharp" dll error

  • Sep 30, 2024 3:52 PM UTC
  • 4 replies
  • 526 views
  • Translate All

Forum|alt.badge.img

Hello,

we are receiving a pdf of 2 pages from external application, so we would like to import only first page of it, so we are trying to use itext sharp to achieve this. we added reference using Nuget manger, we are getting below error when we trying to process it.
 

Could not load file or assembly 'itextsharp, Version=5.5.13.4, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies. The system cannot find the file specified.


Please have a look at below code.

using (MemoryStream memoryStream = new MemoryStream(data))
{
    PdfReader reader = new PdfReader(memoryStream);

    using (MemoryStream outputStream = new MemoryStream())
    {
        Document document = new Document(reader.GetPageSizeWithRotation(1));
        PdfCopy writer = new PdfCopy(document, outputStream);

        document.Open();
        PdfImportedPage page = writer.GetImportedPage(reader, 1);
        writer.AddPage(page);
        document.Close();
        
        PX.SM.FileInfo info = new PX.SM.FileInfo("file.pdf", (string)null, outputStream.ToArray());
        instance.SaveFile(info, FileExistsAction.CreateVersion);
        PXNoteAttribute.SetFileNotes(Graph.Document.Cache, Graph.Document.Current, info.UID.Value);    
    }
}

Best answer by hdussa

Hello @ckwiat46 ,

 

Try installing the BouncyCastle v 2.4.0 or greater dll and check if it works.

View original

4 replies

hdussa
Jr Varsity I
Forum|alt.badge.img+2
  • Jr Varsity I
  • Sep 30, 2024 6:05 PM UTC

Hello @ckwiat46 ,

 

See if the dependent DLL BouncyCastle.Cryptography available in the BIN directory.
 

 

Translate

Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • Oct 1, 2024 3:08 PM UTC

Hello @hdussa, we don’t have BouncyCastle.Cryptography dll in BIN folder.

Translate

hdussa
Jr Varsity I
Forum|alt.badge.img+2
  • Jr Varsity I
  • Answer
  • Oct 1, 2024 7:30 PM UTC

Hello @ckwiat46 ,

 

Try installing the BouncyCastle v 2.4.0 or greater dll and check if it works.

Translate

hdussa
Jr Varsity I
Forum|alt.badge.img+2
  • Jr Varsity I
  • Oct 9, 2024 5:46 PM UTC

@ckwiat46 , hope it worked after installing the mentioned dependencies.

Translate