我有一个非常高的 asp 图表(PNG 文件),假设高度为 4000 像素。当使用 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();
}