delphi使用Foxit Quick PDF Library精确编写PDF
官方帮助文档:https://www.debenu.com/docs/pdf_library_reference/FunctionGroups.php
前面有提到使用Quick PDF Library简单读写PDF文件:https://www.cnblogs.com/ClaireWu/p/12468255.html
但是写入pdf,只是简单的写入到了pdf,这里详细讲一下更加准确详细的编写pdf步骤,可以根据坐标,pdf页数,并且设置写入字体的颜色,大小,编辑pdf
安装步骤这里就不多讲了,具体可以看一下上面的链接
不多说,这里直接贴代码:
参数:fileName, text: string; const iXPos, iYPos, iTextSize, iColor, iPage: Integer
代表:pdf文件路径, 文本内容, X, Y, 字体大小, 颜色值, 页数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | function xxx . WritePdfXY( const fileName, text: string ; const iXPos, iYPos, iTextSize, iColor, iPage: Integer ): string ; function GetColorRGB( const iColor: Integer ; var iR, iG, iB: Integer ): Boolean ; var iMod: Integer ; begin Result := True ; if (iColor <= 16777215 ) and (iColor >= 0 ) then begin iR := iColor div ( 256 * 256 ); iMod := iColor mod ( 256 * 256 ); iG := iMod div 256 ; iB := iMod mod 256 ; end else Result := False ; end ; var wPdf : TDebenuPDFLibraryDLL1111; num, wStatus, iRed, iGreen, iBlue: Integer ; sFile, sKey : string ; begin Result := '' ; if Trim(fileName) = '' then begin Result := '路径不能为空' ; Exit; end ; if not FileExists(Trim(fileName)) then begin Result := '文件不存在。' ; Exit; end ; try Result := InitPdfFoxitSDK; if Result <> '' then Exit; sFile := GetAppLibraryPath() + 'DebenuPDFLibraryDLL1111.dll' ; wPdf := TDebenuPDFLibraryDLL1111 . Create(sFile); //库 try sKey := '密钥' ; wStatus := wPdf . UnlockKey(sKey); //密钥 if wStatus = 1 then begin iRed := 0 ; iGreen:= 0 ; iBlue := 0 ; wPdf . LoadFromFile(Trim(fileName), '' ); if iPage > wPdf . PageCount then begin Result := '页数溢出。' ; Exit; end ; wPdf . SelectPage(iPage); //选区页 num := wPdf . AddTrueTypeSubsettedFont( 'FangSong' ,text, 0 ); wPdf . SelectFont(num); wPdf . SetTextSize(iTextSize); GetColorRGB(iColor,iRed, iGreen, iBlue); wPdf . SetTextColor(iRed, iGreen, iBlue); wPdf . SetMeasurementUnits( 1 ); // 画上字体 wPdf . DrawWrappedText(iXPos, iYPos, 500 , text); wPdf . SaveToFile(fileName); end else begin Result := '库不能加载或者密钥错误' ; end ; finally wPdf . Free; end ; except on e:Exception do Result := e . Message; end ; end ; |
亲测可用,其中的密钥可以在官网购买或者在网上找一下,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?