0
我試圖用c#中的itextsharp在pdf文件中創建相對鏈接。我已經使用這個例子(翻譯成C#):http://itextpdf.com/sandbox/annotations/RemoteGoToPage。itext action中的相對路徑
但是,當我打開生成的PDF並單擊鏈接沒有任何反應。但是,如果我更改爲絕對路徑的鏈接。謝謝。
我的代碼:
class Program
{
public const string DEST = "abc2.pdf";
public const string SRC = "xyz2.pdf";
static void Main(string[] args)
{
Program app = new Program();
app.createPdf(DEST);
app.createPdf2(SRC);
}
public void createPdf(string dest)
{
Document document1 = new Document();
PdfWriter.GetInstance(document1, new FileStream(dest, FileMode.Create));
document1.Open();
document1.Add(new Paragraph("Page 1"));
document1.NewPage();
document1.Add(new Paragraph("Page 2"));
document1.NewPage();
document1.Add(new Paragraph("Page 3"));
document1.NewPage();
document1.Add(new Paragraph("Page 4"));
document1.NewPage();
document1.Add(new Paragraph("Page 5"));
document1.NewPage();
document1.Add(new Paragraph("Page 6"));
document1.NewPage();
document1.Add(new Paragraph("Page 7"));
document1.Close();
}
public void createPdf2(string src)
{
Document document2 = new Document();
PdfWriter.GetInstance(document2, new FileStream(src, FileMode.Create));
document2.Open();
Chunk chunk = new Chunk("Link");
var link = "abc2.pdf"; //this don't work
//var link = "c:/temp/abc2.pdf"; //this work
chunk.SetAction(new PdfAction(link, 6));
document2.Add(chunk);
document2.Close();
}
}
請看看我對以下問題的回答:[使用相對路徑進行PDF生成時使用iText的錨定方法](http:// stack overflow.com/questions/27063677/use-of-relative-path-for-anchor-method-using-itext-for-pdf-generation)。這個問題幾乎是你的重複;-) – 2015-02-06 08:22:59