如何创建一个动作以在 iTextSharp 中使用适合页面缩放的页面打开另一个 PDF?

How do I create an Action to open another PDF at page with a zoom of Fit Page in iTextSharp?

如何制作 PdfAction 以在特定页面以缩放级别 Fit Page 打开另一个 PDF? PdfAction 的构造函数之一采用 PDF 路径和目标页码,但默认缩放为 Fit Width。我没有看到任何包含 'desired zoom' 参数的 methods/constructors。我是没看到它,还是有办法在 PdfAction 完成后更改缩放级别?

这是我目前的代码:

var pdfAnnotation = PdfAnnotation.CreateLink(
    pdfStamper.Writer,
    linkOutline,
    PdfAnnotation.HIGHLIGHT_NONE,
    new PdfAction(pdfPath, targetPageNumber));

pdfAnnotation.BorderStyle = new PdfBorderDictionary(0.0F, 0);

pdfStamper.AddAnnotation(pdfAnnotation, sourcePageNumber);

我不确定这是否是我问题的惯用解决方案,但在创建 PdfAction 后,我可以通过替换散列 table 值之一来更新缩放级别:

var action = new PdfAction(pdfPath, targetPageNumber);

action.Remove(PdfName.D);
action.Put(PdfName.D, new PdfLiteral($@"[{targetPageNumber - 1} /Fit]"));


var pdfAnnotation = PdfAnnotation.CreateLink(
    pdfStamper.Writer,
    linkOutline,
    PdfAnnotation.HIGHLIGHT_NONE,
    action);

pdfAnnotation.BorderStyle = new PdfBorderDictionary(0.0F, 0);


pdfStamper.AddAnnotation(pdfAnnotation, sourcePageNumber);