我有一个非常高的asp图表(PNG文件),让我们说高度为4000px.当使用iTextSharp生成pdf文件时,它只有一个页面,我只能看到我图表的25-30%.我不想缩放图像以适合一页.我想在多个页面上传播/拆分我的图表,以便查看图表的详细信息.如果我的图表适合四页,PDF也需要有四页.在下面的图像中,您可以看到我的图表,我想要的方式(分布在6页),以及iTextSharp(图表顶部显示在一个页面上)生成的实际效果. 图片
Document pdfDoc = new Document(PageSize.A4.Rotate(), 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
using (MemoryStream stream = new MemoryStream())
{
Chart1.SaveImage(stream, ChartImageFormat.Png);
iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
chartImage.ScalePercent(70f);// This solves the width of the chart
pdfDoc.Add(chartImage);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
Run Code Online (Sandbox Code Playgroud)