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, 字体大小, 颜色值, 页数
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;
亲测可用,其中的密钥可以在官网购买或者在网上找一下,

浙公网安备 33010602011771号