Aspose.pdf 将原有页面缩小到A4纸大小,缩小后内容只显示原有的4分之一,感谢技术大哥查看。
源文件:pdflj.pdf (7.8 MB)
错误截图:
QQ截图20190907170112.jpg (25.5 KB)
将页面缩放到A4纸大小了,但是里面的内容没有缩放到A4纸大小,如何让页面里面的内容自动适应修改过的页面大小。
/* //指定用于调整大小的参数
PdfFileEditor.ContentsResizeParameters parameters = new
PdfFileEditor.ContentsResizeParameters(
PdfFileEditor.ContentsResizeValue.Percents(1), //leftmargin左边缘
null, //contentswidth 目录宽度
PdfFileEditor.ContentsResizeValue.Percents(-170),//rightmargin 右边缘
PdfFileEditor.ContentsResizeValue.Percents(-170),//topmargin 顶边距
//PdfFileEditor.ContentsResizeValue.Percents(900),
null, // contentHeight 高度
PdfFileEditor.ContentsResizeValue.Percents(0));// Bottom margin 底边距
//调整页面内容的大小
fileEditor.ResizeContents(pdfDocument6, pages, parameters);*/
复制以下代码便可使用:
Aspose.Pdf.Document pdfDocument6 = new Aspose.Pdf.Document(pdflj);
for (int i = 1; i <= pdfDocument6.Pages.Count; i++)
{
Aspose.Pdf.Page page = pdfDocument6.Pages[i];
page.SetPageSize(Aspose.Pdf.PageSize.A4.Width, Aspose.Pdf.PageSize.A4.Height);
//获取PDF第一页的矩形区域
Aspose.Pdf.Rectangle rect = pdfDocument6.Pages[i].Rect;
// 实例化PdfPageEditor实例
PdfPageEditor ppe = new PdfPageEditor();
// 绑定源PDF
ppe.BindPdf(pdflj);
// 更新页面大小
ppe.PageSize= PageSize.A4;
// 设置缩放系数
//ppe.Zoom = (float)(rect.Width / rect.Height);
ppe.Zoom = 1.5f;
}
pdfDocument6.Save("cc.pdf");