0

I am trying to convert the multipage tiff image into pdf. This error is happening when I am trying to call the method bitmap.SelectActiveFrames. Below is the code

`using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(_pdfFinalLocation)))
{
    Document document = new Document(pdfDocument);
    Bitmap _bitMap = new Bitmap(srcImageFile);
    int _totalpage = _bitMap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
    _bitMap.Dispose();
    _bitMap = null;
    for (int i = 0; i < _totalpage; i++)
    {
       using(Bitmap _bitMapTemp = new Bitmap(srcImageFile))
       {
                       
          _bitMapTemp.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, i);
          using (var MemoryStream = new MemoryStream())
          {
              _bitMapTemp.Save(MemoryStream, System.Drawing.Imaging.ImageFormat.Tiff);
              imageData = ImageDataFactory.Create(MemoryStream.ToArray());
              iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData);
              document.Add(image);
          }

         _bitMapTemp.Dispose();
        }
      }                
                if (!pdfDocument.IsCloseWriter())
                    pdfDocument.Close();
}`

I would highly appreciate it if anyone would help me in solving the issue.

0 Answers0