新增修改docx页码接口`UpdateDocxPageNumpages`,以及保存修改docx文件接口`SaveDocxFile`

This commit is contained in:
csh 2024-11-20 17:08:13 +08:00
parent 8ab1670eea
commit 0437961953
2 changed files with 60 additions and 13 deletions

View File

@ -14,13 +14,17 @@ public
function GetNextPage(page: TSPage): TSPage;
function GetCurrentXmlFile(): string;
function AddTSPage(flag: boolean): TSPage;
function AdjustPageNumber(page: TSPage; num: integer);
function LinkToToc(anchor: string; page: TSPage; left: real; top: real);
function AddToc(anchor: string; toc: TSToc);
function SetHeaderAndFooter();
function ProcessNumpages();
function CalculateTextCoordinates(): array of real;
function GetSymbol(symbol: string);
function AddDocxPage(pg: TSPage; r: R);
function UpdateDocxPageNumpages();
function SaveDocxFile();overload;
function SaveDocxFile(alias: string; file: string);overload;
property Font read ReadFont;
function ReadFont();
@ -60,6 +64,9 @@ private
even_and_odd_flag_: boolean;
xml_file_: string;
symbol_: tableArray;
docx_page_arr_: tableArray;
update_docx_pages_: boolean;
end;
type Point = class
@ -94,6 +101,9 @@ begin
settings := docx_components_ware_.Settings;
settings.XmlChildEvenAndOddHeaders.Deserialize();
even_and_odd_flag_ := settings.EvenAndOddHeaders ? true : false;
docx_page_arr_ := array();
update_docx_pages_ := false;
end;
function TSDocxToPdf.Destroy();
@ -380,12 +390,6 @@ begin
end
end;
function TSDocxToPdf.AdjustPageNumber(page: TSPage; num: integer);
begin
for i:=page.Index to length(page_array_)-1 do
page_array_[i].Number := num++;
end;
function TSDocxToPdf.GetNextPage(page: TSPage);
begin
return page_array_[page.Index + 1];
@ -455,6 +459,13 @@ begin
for _,toc in arr do
toc.LinkAnnot(dst);
toc.AddPageNumber(page);
if update_docx_pages_ then
begin
r := docx_page_arr_[anchor];
r.T.Text := page.Number;
r.Serialize();
end
end;
function TSDocxToPdf.GetSymbol(symbol: string);
@ -462,3 +473,24 @@ begin
// println("symbol = {}, symbol_ = {}", symbol, symbol_);
return symbol_[symbol];
end;
function TSDocxToPdf.AddDocxPage(anchor: string; r: R);
begin
docx_page_arr_[anchor] := r;
end;
function TSDocxToPdf.UpdateDocxPageNumpages();
begin
update_docx_pages_ := true;
end;
function TSDocxToPdf.SaveDocxFile();overload;
begin
return docx_components_ware_.Save();
end;
function TSDocxToPdf.SaveDocxFile(alias: string; file: string);overload;
begin
return docx_components_ware_.SaveAs(alias, file);
end;

View File

@ -316,15 +316,30 @@ function TSPdfParagraphRange.HyperlinkToTextRange(hyperlink: Hyperlink; ppr: PPr
begin
i := length(range_array_);
rs := hyperlink.Rs();
char_type := false;
separate := false;
for _,r in rs do
begin
if r.FldChar.FldCharType = "begin" then break;
if r.FldChar.FldCharType = "begin" then char_type := true;
// TODOofficexml项目是否应该保留赋值接口如何统一
if ifnil(r.XmlChildRPr) then r.XmlChildRPr := new RPr();
// r.RPr := new RPr();
{self.}SetRPr(r.RPr, ppr_unit_decorator_);
r.RPr.Color.Val := nil;
{self.}RToTextRange(r, hyperlink.Anchor);
if char_type then
begin
if r.FldChar.FldCharType = "separate" then
begin
separate := true;
continue;
end
if r.FldChar.FldCharType = "end" then
separate := char_type := false;
if separate then
docx_to_pdf_.AddDocxPage(hyperlink.Anchor, r);
end
else begin
if ifnil(r.XmlChildRPr) then r.XmlChildRPr := new RPr();
{self.}SetRPr(r.RPr, ppr_unit_decorator_);
r.RPr.Color.Val := nil;
{self.}RToTextRange(r, hyperlink.Anchor);
end
end
arr := array();
while i < length(range_array_) do