当前位置: 首页 > news >正文

aspose-pdf 修改pdf文件备忘录

public class PatchedLicense
{public static DateTime NewParseExact(string s, string format, IFormatProvider provider){return new DateTime(2099, 12, 30);}public static void Run(){MethodHookManager.Instance.AddHook(new MethodHook(typeof(DateTime).GetMethod(nameof(DateTime.ParseExact), BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string), typeof(string), typeof(IFormatProvider) }, null),typeof(PatchedLicense).GetMethod(nameof(NewParseExact), BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string), typeof(string), typeof(IFormatProvider) }, null)));MethodHookManager.Instance.StartHook();ActiveAspose();MethodHookManager.Instance.StopHook();}private static void ActiveAspose(){var licenseText = @"<License><Data><LicensedTo>KMD A/S</LicensedTo><EmailTo>iit-software@kmd.dk</EmailTo><LicenseType>Site OEM</LicenseType><LicenseNote>Up To 10 Developers And Unlimited Deployment Locations</LicenseNote><OrderID>220815085749</OrderID><UserID>324045</UserID><OEM>This is a redistributable license</OEM><Products><Product>Aspose.Total for .NET</Product></Products><EditionType>Enterprise</EditionType><SerialNumber>acea5afd-3c7d-4052-8991-f1e8522f63b4</SerialNumber><SubscriptionExpiry>20230818</SubscriptionExpiry><LicenseVersion>3.0</LicenseVersion><LicenseInstructions>https://purchase.aspose.com/policies/use-license</LicenseInstructions></Data><Signature>d6CNxPzdmeo0I8EJmarUMRizSisbxluOwz5BdYKprWEyJbqjvs93//lCgP0tNzxIzvniD9T7PefYeEtlkQoVKV9fo3pdjfh2QrWFxJZuRby9yzfTqK7Ahghj81URDTpneve+RAL3Z63bwkCNH0anWR0Z1I6Bdug5L8QZpduoS5k=</Signature></License>";var stream = new MemoryStream(Encoding.UTF8.GetBytes(licenseText));var license = new Aspose.Pdf.License();license.SetLicense(stream);}
}

  

public class PdfTools
{public static void Resolve(){// 输入与输出路径string inputPath = @"E:\zhaxg.pdf";string outputPath = @"E:\zhaxg_out.pdf";// 打开 PDF 文档using (var document = new Document(inputPath)){// 创建文本吸收器,查找目标文字var oldText = "河北99贸易有限公司";var absorber = new TextFragmentAbsorber(oldText);// 设置搜索选项(不区分大小写、全局搜索)absorber.TextSearchOptions = new TextSearchOptions(true);// 扫描所有页面document.Pages.Accept(absorber);// 获取搜索到的文字片段集合var fragments = absorber.TextFragments;Console.WriteLine($"找到 {fragments.Count} 个匹配项。");// 遍历每个匹配片段并替换foreach (TextFragment fragment in fragments){fragment.Text = "北京99软件技术有限公司";}// 搜索图片var img_absorber = new Aspose.Pdf.ImagePlacementAbsorber();document.Pages.Accept(img_absorber);var image = img_absorber.ImagePlacements.FirstOrDefault(x => x.Image.Height == 250);// 删除原来的二维码document.Pages[1].Resources.Images.Delete(((Aspose.Pdf.Operators.Do)image.Operator).Name);// 生成新的二维码var qrText = "https://www.baidu.com/";var qrGenerator = new QRCodeGenerator();var qrCodeData = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q);// 使用 PngByteQRCode 生成 PNG 字节数组var qrCode = new PngByteQRCode(qrCodeData);var qrBytes = qrCode.GetGraphic(pixelsPerModule: 2,darkColor: System.Drawing.Color.Black,lightColor: System.Drawing.Color.White);File.WriteAllBytes(@"E:\zhaxg.png", qrBytes);using var qrStream = new MemoryStream(qrBytes);document.Pages[1].AddImage(qrStream, image.Rectangle, 250, 250, true);// 保存结果document.Save(outputPath);Console.WriteLine("替换完成,文件已保存到: " + outputPath);}}
}

  

http://www.gsyq.cn/news/42162.html

相关文章:

  • 函数名与函数地址的关系(函数指针)
  • 别再选错!5分钟掌握AI Agent框架选型的方法
  • Linux - 7 磁盘管理篇
  • Markdown之Typora语法
  • markdown入门(复盘)
  • 卡尔算法哈希表
  • Rust 之二 各组件工具的源码、构建、配置、使用 - 教程
  • 新东方听力day2
  • 超级管理员目录索引的Google搜索技巧
  • 无限欢愉 深入推进 我沦陷在那片故地 我渴饮着 你的呼吸 却得不到 你的心
  • 基础架构
  • Word表格1.5倍行距居中问题
  • 详细介绍:后端_Redis 分布式锁实现指南
  • 日总结 23
  • [题解]P10277 [USACO24OPEN] Bessies Interview S
  • UE:论运行时动画录制的关键-正确获取骨骼数据与保存
  • 线性基相关
  • 低代码权限管理安全合规指南:守住数据安全的 “最后一道防线”
  • 2025-11-06
  • 关于waybar状态栏颜文字乱码问题
  • P10277 [USACO24OPEN] Bessies Interview S 题解
  • AI 时代的数据库进化论 —— 从向量到混合检索
  • vue 3.x 前端导出功能
  • 最高法-合同目的的认定
  • 2025年恒温恒湿机标杆厂家最新推荐:中焓环境,档案室恒湿机/精密恒温恒湿机/吊顶恒温恒湿机/档案室恒温恒湿机,定义环境控制精准新标准
  • 酸角糕行业发展趋势解析:2025年十大品牌综合测评与选择指南
  • [题解]P6717 [CCO 2018] Boring Lectures
  • Bigtop 从零开始搭建大数据集群
  • chatgpt-to-md优化并重新复习
  • SaaS版MES系统PC端后台特性清单与设计说明