没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2019-11-20 10:06:59.180|阅读 445 次
概述:在接下来的系列教程中,将为开发者带来Aspose.PDF for .NET的一系列使用教程,本文将介绍如何修剪页面周围的空白。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Aspose.PDF for .NET是一种高PDF处理和解析API,用于在跨平台应用程序中执行文档管理和操作任务。API可以轻松用于生成、修改、转换、渲染、保护和打印PDF文档,而无需使用Adobe Acrobat。此外,API还提供PDF压缩选项,表格创建和操作,图形和图像功能,广泛的超链接功能,印章和水印任务,扩展的安全控制和自定义字体处理。
在接下来的系列教程中,将为开发者带来Aspose.PDF for .NET的一系列使用教程,例如进行文档间的转换,如何标记PDF文件,如何使用表单和图表等等。
>>Aspose.PDF for .NET更新至最新版v19.11,欢迎下载体验。
购买Aspose文档系列产品领取优惠券专享折上折,满额更有iPhone 11等豪礼相送!更多活动详情可哦~
PDF文件由文本,图像,图形和其他各种对象组成。要删除或修剪PDF页面周围的空白CropBox,请为该特定页面设置。要确定正确的CropBox坐标值,首先需要确定对象在页面上的位置。
图形基元边界检测不是一种可靠的方法。很可能在外观中找不到某些对象,并提供API来获取其矩形。更好,更可靠的方法是将PDF页面呈现为图像,然后确定页边距。以下代码段显示了如何:
// 文档目录的路径 string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); //加载现有的PDF文件 Document doc = new Document(dataDir + "input.pdf"); //使用72 DPI将页面渲染为图像 PngDevice device = new PngDevice(new Resolution(72)); using (MemoryStream imageStr = new MemoryStream()) { device.Process(doc.Pages[1], imageStr); Bitmap bmp = (Bitmap)Bitmap.FromStream(imageStr); System.Drawing.Imaging.BitmapData imageBitmapData = null; // 确定白色区域 try { imageBitmapData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb); Aspose.Pdf.Rectangle prevCropBox = doc.Pages[1].CropBox; int toHeight = bmp.Height; int toWidth = bmp.Width; int? leftNonWhite = null; int? rightNonWhite = null; int? topNonWhite = null; int? bottomNonWhite = null; for (int y = 0; y < toHeight; y++) { byte[] imageRowBytes = new byte[imageBitmapData.Stride]; // 将行数据复制到字节数组 if (IntPtr.Size == 4) System.Runtime.InteropServices.Marshal.Copy(new IntPtr(imageBitmapData.Scan0.ToInt32() + y * imageBitmapData.Stride), imageRowBytes, 0, imageBitmapData.Stride); else System.Runtime.InteropServices.Marshal.Copy(new IntPtr(imageBitmapData.Scan0.ToInt64() + y * imageBitmapData.Stride), imageRowBytes, 0, imageBitmapData.Stride); int? leftNonWhite_row = null; int? rightNonWhite_row = null; for (int x = 0; x < toWidth; x++) { if (imageRowBytes[x * 4] != 255 || imageRowBytes[x * 4 + 1] != 255 || imageRowBytes[x * 4 + 2] != 255) { if (leftNonWhite_row == null) leftNonWhite_row = x; rightNonWhite_row = x; } } if (leftNonWhite_row != null || rightNonWhite_row != null) { if (topNonWhite == null) topNonWhite = y; bottomNonWhite = y; } if (leftNonWhite_row != null && (leftNonWhite == null || leftNonWhite > leftNonWhite_row)) { leftNonWhite = leftNonWhite_row; } if (rightNonWhite_row != null && (rightNonWhite == null || rightNonWhite < rightNonWhite_row)) { rightNonWhite = rightNonWhite_row; } } leftNonWhite = leftNonWhite ?? 0; rightNonWhite = rightNonWhite ?? toWidth; topNonWhite = topNonWhite ?? 0; bottomNonWhite = bottomNonWhite ?? toHeight; //将修正后的裁剪框设置为上一个裁剪框 doc.Pages[1].CropBox = new Aspose.Pdf.Rectangle( leftNonWhite.Value + prevCropBox.LLX, (toHeight + prevCropBox.LLY) - bottomNonWhite.Value, rightNonWhite.Value + doc.Pages[1].CropBox.LLX, (toHeight + prevCropBox.LLY) - topNonWhite.Value ); } finally { if (imageBitmapData != null) bmp.UnlockBits(imageBitmapData); } } dataDir = dataDir + "TrimWhiteSpace_out.pdf"; // 保存更新的文档 doc.Save(dataDir);
还想要更多吗?您可以点击阅读【2019 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),我们很高兴为您提供查询和咨询。
如果您对Aspose有任何需求和疑难,记得扫描下方二维码告诉我们哦~
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@atlvshi.cn
锁定 Excel 中的单元格对于数据完整性至关重要。在这篇教程中,我们将探讨如何使用 C# 锁定 Excel 中的单元格。
VMProtect 是一款强大的代码保护工具,支持虚拟化、混淆和加密等多种保护技术。本文将详细介绍如何将 VMProtect 集成到 Visual Studio,并提供实用技巧。
在 Word 文档中,图片和形状可以添加超链接,用于跳转到外部网站、文件,或文档中的特定位置。这篇文章将介绍如何使用 Spire.Doc for .NET 在 C# 中以编程方式修改 Word 文档中图片和形状的超链接。
本文将演示如何使用DevExpress WPF Grid控件实现列绑定到数字源字段,欢迎下载最新版组件体验!
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@atlvshi.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢