Compare commits
2 Commits
011774cfc1
...
f72b734cc4
| Author | SHA1 | Date |
|---|---|---|
|
|
f72b734cc4 | |
|
|
e3ffbae915 |
23
README.md
23
README.md
|
|
@ -2,6 +2,29 @@
|
||||||
|
|
||||||
文件转 Pdf 工具
|
文件转 Pdf 工具
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
|
||||||
|
```pascal
|
||||||
|
alias := "";
|
||||||
|
doc := "D:\\temp\\wordtopdf\\3M.docx";
|
||||||
|
output := "D:\\temp\\1.pdf";
|
||||||
|
|
||||||
|
docx_to_pdf := new TSDocxToPdf(alias, doc);
|
||||||
|
docx_to_pdf.Font.SetSubstitutionRules("仿宋", "宋体");
|
||||||
|
docx_to_pdf.Transform();
|
||||||
|
err := docx_to_pdf.SaveToFile(alias, output);
|
||||||
|
echo "SaveToFile::\t", "err := ", format("%x", err), "\toutput_file := ", output, "\n";
|
||||||
|
```
|
||||||
|
|
||||||
|
TSDocxToPdf中的[Font](./ware/TSFontWare.tsf)属性是设置转PDF时的一些字体配置,包含以下函数:
|
||||||
|
|
||||||
|
- `SetDefaultSz(value: real);`:设置默认字体大小,Docx转Pdf会遇到获取默认字体大小失败情况,此时可通过此方法设置字体大小。不设置情况下默认是10.5磅
|
||||||
|
|
||||||
|
- `SetSubstitutionRules(source: string; target: string);`:字体替换规则,遇到不支持的字体,需要设置替换的目标字体。未设置情况下会默认替换为宋体
|
||||||
|
|
||||||
|
- `UseExternalFont()`:使用外部字体,需要部署在fonts文件夹。暂不支持
|
||||||
|
当前默认使用的是Pdf内置的字体,仅支持宋体和黑体
|
||||||
|
|
||||||
## 部署
|
## 部署
|
||||||
|
|
||||||
将此文件夹部署到 tsl 安装目录下`funcext`即可
|
将此文件夹部署到 tsl 安装目录下`funcext`即可
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,8 @@ begin
|
||||||
elements := sect_ware.Elements();
|
elements := sect_ware.Elements();
|
||||||
for _,element in elements do
|
for _,element in elements do
|
||||||
begin
|
begin
|
||||||
|
println("_ = {}", _);
|
||||||
|
if _ = 266 then return;
|
||||||
if element.LocalName = "p" then self.TransformParagraph(sect_ware, element);
|
if element.LocalName = "p" then self.TransformParagraph(sect_ware, element);
|
||||||
else if element.LocalName = "tbl" then self.TransformTable(sect_ware, element);
|
else if element.LocalName = "tbl" then self.TransformTable(sect_ware, element);
|
||||||
end
|
end
|
||||||
|
|
@ -126,7 +128,9 @@ end;
|
||||||
function TSDocxToPdf.InitCachePath(file: string);
|
function TSDocxToPdf.InitCachePath(file: string);
|
||||||
begin
|
begin
|
||||||
path := format("%s_%s", extractFileName(file), formatDatetime("YYYYMMDDHHNNSSZZZ", now()));
|
path := format("%s_%s", extractFileName(file), formatDatetime("YYYYMMDDHHNNSSZZZ", now()));
|
||||||
cache_path_ := format("%s/funcext/PdfConverter/.cache/%s/", extractFileDir(sysExecName()), path);
|
cache_dir := format("%s/funcext/PdfConverter/.cache", extractFileDir(sysExecName()));
|
||||||
|
createDir("", cache_dir);
|
||||||
|
cache_path_ := format("%s/%s/", cache_dir, path);
|
||||||
createDir("", cache_path_);
|
createDir("", cache_path_);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue