C#에서 itextsharp로 상대 링크를 만들려고했습니다. 이 예제 (C#으로 번역)를 사용했습니다 : http://itextpdf.com/sandbox/annotations/RemoteGoToPage.itextsharp를 사용하여 pdf 파일에 상대 링크를 만들려고했습니다.
하지만 생성 된 PDF 파일을 열어 링크를 클릭해도 아무런 변화가 없습니다. 그러나 내가 절대 경로로 변경하면. 감사.
내 코드 : 파일 위치에 따라 파일 전에 ./(dot 슬래시와
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). 이 질문은 거의 당신의 복사본입니다 ;-) –