镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Conversion]: Word转PDF,页脚显示的页码不正确 #158

Open

Description

@luxianai

MiniPdf implementation

.NET (C#)

Source document type

DOCX

Authoring application

Microsoft Office

Authoring application version

No response

MiniPdf version

0.42.0

Environment

MiniPdf library

Runtime or host details

.Net8

Operating system

window

Minimal test example

static void Main(string[] args)
{
// 定义输入和输出路径
string inputPath = "doc\input.docx";
string outputPath = "doc\output.pdf";

// 确保输出目录存在
string outputDirectory = Path.GetDirectoryName(outputPath);
if (!string.IsNullOrEmpty(outputDirectory) && !Directory.Exists(outputDirectory))
{
    Directory.CreateDirectory(outputDirectory);
}

// 执行转换
MiniPdf.ConvertToPdf(inputPath, outputPath);

Console.WriteLine($"PDF 已生成: {Path.GetFullPath(outputPath)}");
Console.WriteLine("转换完成!");

}

Input and output files

word文件:
input.docx
输出结果:
output.pdf

Additional context


Activity

  1. jeff377 commented on Sep 11, 2026

    @jeff377
    Contributor

    在 macOS 上用附件的 input.docx 重現了,提供結果與原因分析,供維護者判斷。

    測試環境:main @ 54f06487、macOS arm64、.NET SDK 9.0.317,以 CLI 轉檔。

    症狀

    頁尾沒有顯示頁碼,而是印出內部的佔位字串。附件的 output.pdf(0.42.0)與目前 main 轉出的結果相同,兩頁都是:

    Document no: 104-04
    Page {PAGE} of
    {NUMPAGES}
    

    觸發條件:頁碼欄位位於頁首/頁尾的表格內

    input.docx 的頁尾(footer1.xml)是一個三欄表格,PAGE 與 NUMPAGES 欄位在右欄。

    另以最小文件對照(兩頁本文,只改變頁碼欄位的位置):

    頁碼欄位位置 轉出結果
    頁尾段落 Page 1 of 2、Page 2 of 2
    頁尾表格儲存格 兩頁皆為 Page {PAGE} of {NUMPAGES}
    頁首表格儲存格 兩頁皆為 Page {PAGE} of {NUMPAGES}

    原因

    DocxReader 把 PAGE/NUMPAGES 欄位讀成佔位字串,繪製時才替換成數字。RenderHeaderFooterElementsOnPage 的兩個分支處理方式不同:

    • 段落分支在 DocxToPdfConverter.cs#L3598-L3600 呼叫 ResolvePagePlaceholders。
    • 表格分支在 #L3628 呼叫 RenderHeaderFooterTable(page, options, table, y),沒有傳入 pageIndex、totalPages、sectionPageNum;該方法組出儲存格文字(#L3745)後也沒有替換。

    另外,#L3763 的 WordWrap 量測的是未替換的字串,所以在 1134 dxa 的窄欄裡被折成兩行。修正時,替換可能需要放在換行量測之前。

    備註

    • 預期輸出 Page 1 of 2 是依 Word 欄位語意推定,沒有用 Word 實際轉出來對照。
    • 沒有檢查列高計算(CalculateRowHeight、CalculateCellContentHeight)是否也使用未替換的字串。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions