0

I am trying to save jpeg files to a PDF file.

The commented code works, but the images are unscaled. I would like to use a different way of saving, but it results in a blank PDF file with a message. ERROR: Infinite table loop.

My code:

using (var img = webp.Decode(array))
{
  img.Save(streamJpeg, ImageFormat.Jpeg);
  streamJpeg.Position = 0;
  iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(streamJpeg);
    
 //if (pdfImage.Height > pdfImage.Width)
 //{
 //    //Maximum height is 800 pixels.
 //    float percentage = 0.0f;
 //    percentage = 700 / pdfImage.Height;
 //    pdfImage.ScalePercent(percentage * 100);
 //}
 //else
 //{
 //    //Maximum width is 600 pixels.
 //    float percentage = 0.0f;
 //    percentage = 540 / pdfImage.Width;
 //    pdfImage.ScalePercent(percentage * 100);
 //}
                
 PdfPTable table = new PdfPTable(1);
 table.AddCell(new PdfPCell(pdfImage));
 doc.Add(table);   
 //doc.Add(pdfImage);   
 //doc.NewPage();
}

Thanks, regards.

fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
  • The following may be helpful: https://stackoverflow.com/questions/72663379/creating-a-blank-pdf-and-uploading-an-image-to-each-page/72664601#72664601 and https://stackoverflow.com/questions/73136184/itextsharp-add-checkbox-inside-table-cell-with-text/73159051#73159051 – Tu deschizi eu inchid Jan 02 '23 at 15:55

0 Answers0