1

I have 2 asp.net chart control which i want to convert to pdf. I am using iTextSharp to convert the images to pdf.

The issue is with the position of images, i want images to come next to other.

i tried to setpagesize but it didnt worked.

    Document pdfDoc = new Document(PageSize.A4);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

    Chart1.SaveImage(stream, ChartImageFormat.Png);
    iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
    chartImage.ScalePercent(75f);
    pdfDoc.Add(chartImage);
    Chart2.SaveImage(stream, ChartImageFormat.Png);
    iTextSharp.text.Image chartImage1 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
    chartImage1.ScalePercent(75f);
    pdfDoc.Add(chartImage1);
New Coder
  • 501
  • 2
  • 6
  • 23

1 Answers1

2

The best way to position images next to each other, is to add them to a ´PdfPTable´. I've created a small example in Java: ImagesNextToEachOther

As you can see, we wrap images inside a cell, asking the cell to scale the image so that it fits the width of the cell.

You'll have to make small changes to the code, as I've used iText instead of iTextSharp, but the difference should be minimal.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165