How to convert image size to A4 format with iTextSharp

1

Please, I am generating several images in a single PDF and it is running correctly.  What I can not do is leave the A4 size images as they get very big, 80% of the standard size. How can I decrease to fit the A4? the code is below. Thankful

iTextSharp.text.Document Doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 80, 80, 80, 80);
            //Salve o documento
            string PDFOutput = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "C:\Users\Usuario\Desktop\imagensParaPDF\Output.pdf");
            PdfWriter writer = PdfWriter.GetInstance(Doc, new FileStream(PDFOutput, FileMode.Create, FileAccess.Write, FileShare.Read));
    
asked by anonymous 10.02.2016 / 12:19

1 answer

2

Use ScaleToFit .

In my example I put an image in the format Bitmap ( imagemConvertida ), set the size I wanted with ScaleToFit and left it justified with Element.ALIGN_JUSTIFIED .

Example:

iTextSharp.text.Image imagem = iTextSharp.text.Image.GetInstance(imagemConvertida, System.Drawing.Imaging.ImageFormat.Png);
imagem.ScaleToFit(600f, 300f);
imagem.Alignment = Element.ALIGN_JUSTIFIED;
document.Add(imagem);
    
09.09.2016 / 17:11