[英]How to create PDF file links with relative file path and PDFsharp?
My App creates a Content.pdf file that links to Server.pdf and Client.pdf. 我的应用程序创建一个Content.pdf文件,该文件链接到Server.pdf和Client.pdf。 This is the folder structure:
这是文件夹结构:
Furthermore, the folders and files get burned on a CD/DVD or get backed up on a network drive - that causes me to use relative file paths. 此外,文件夹和文件会被刻录在CD / DVD上,或者会在网络驱动器上备份-这导致我使用相对文件路径。 I use following code to create the Content.pdf:
我使用以下代码创建Content.pdf:
relative WebLink: 相对WebLink:
var relativeFileLinkPath = "./" + Directory.GetParent(doc.Uri.LocalPath).Name + "/"+ doc.OutputFileName;
page.AddWebLink(pdfrect, relativeFileLinkPath);
relative FileLink: 相对FileLink:
var relativeFileLinkPath = "./" + Directory.GetParent(doc.Uri.LocalPath).Name + "/"+ doc.OutputFileName;
page.AddFileLink(pdfrect, relativeFileLinkPath);
Both work fine on local drive, but my issues are: 两者都可以在本地驱动器上正常工作,但是我的问题是:
Questions: 问题:
How can I modify the FileLinks to get opened in a new (PDF reader) instance/window? 如何修改FileLink以在新的(PDF阅读器)实例/窗口中打开?
What's the right syntax for relative PDF web links? 相对PDF网站链接的正确语法是什么?
AddFileLink
is the correct method for files sitting side by side in a folder. 对于在文件夹中并排放置的文件,
AddFileLink
是正确的方法。
To control whether a new window will be opened, a small modification of PDFsharp's PdfLinkAnnotation class will be needed. 若要控制是否打开新窗口,将需要对PDFsharp的PdfLinkAnnotation类进行少量修改。 PDF supports a
NewWindow
attribute which PDFsharp cannot currently set. PDF支持PDFsharp当前无法设置的
NewWindow
属性。
Get the source for PDFsharp, locate "<</Type/Action/S/Launch/F<</Type/Filespec/F{0}>> >>"
in PdfLinkAnnotation.cs and replace it with "<</Type/Action/S/Launch/NewWindow true/F<</Type/Filespec/F{0}>> >>"
. 获取PDFsharp的源,在PdfLinkAnnotation.cs中找到
"<</Type/Action/S/Launch/F<</Type/Filespec/F{0}>> >>"
,并将其替换为"<</Type/Action/S/Launch/NewWindow true/F<</Type/Filespec/F{0}>> >>"
。
Disclaimer: I did not test the proposed change - I hope it is syntactically correct and I hope it does what you want. 免责声明:我没有测试建议的更改-我希望它在语法上是正确的,并且希望它可以完成您想要的操作。
Disclaimer 2: This change is needed for PDFsharp 1.50 beta 3. Later versions may have support for that flag. 免责声明2:PDFsharp 1.50 beta 3需要进行此更改。更高版本可能支持该标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.