itextsharp图像不会彼此相邻 [英] itextsharp images are not coming next to one another

查看:136
本文介绍了itextsharp图像不会彼此相邻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个asp.net图表控件,我想转换为pdf。我正在使用iTextSharp将图像转换为pdf。

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.

我试图setpagesize但它没有用。

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


推荐答案

将图像定位在彼此旁边的最佳方式,是将它们添加到'PDfPTable'。我在Java中创建了一个小例子: ImagesNextToEachOther

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.

你我必须对代码做一些小改动,因为我使用的是iText而不是iTextSharp,但差别应该是最小的。

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

这篇关于itextsharp图像不会彼此相邻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆