itextsharp images are not coming next to one another

為{幸葍}努か 提交于 2019-12-11 13:13:15

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/19700549/itextsharp-images-are-not-coming-next-to-one-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!