PDF文書の作成ant私はテキストの章へのリンクに問題があります。 私はhereからBruno Lowagieのコードを使用しますが、それはJavaであり、いくつかの問題があります。PDFの目次テキストの章へのリンク付き
私はこのようにやっている:
クラスTOCEvents
public class TOCEvents : PdfPageEventHelper
{
//protected System.Collections.Generic.List<TitleTOC> toc = new System.Collections.Generic.List<TitleTOC>();
protected Dictionary<string, int> toc = new Dictionary<string, int>(5);
public override void OnGenericTag(PdfWriter writer, Document document, Rectangle rect, String text)
{
toc.Add(text, writer.PageNumber);
}
public Dictionary<string, int> GetTOC()
{
return toc;
}
}
メイン
for (int i = 0; i < 10; i++)
{
String title = "This is title " + i;
Chunk c = new Chunk(title, f14);
c.SetGenericTag(title);
doc.Add(new Paragraph(c));
for (int j = 0; j < 50; j++)
{
doc.Add(new Paragraph("Line " + j + " of title " + i));
}
}
doc.NewPage();
doc.Add(new Paragraph("Table of Contents", f24));
Chunk dottedLine = new Chunk(new iTextSharp.text.pdf.draw.DottedLineSeparator());
Dictionary<string, int> entries = ev.GetTOC();
Paragraph p;
foreach (KeyValuePair<string, int> entry in entries)
{
Chunk chunk = new Chunk(entry.Key);
chunk.SetAction(PdfAction.GotoLocalPage(entry.Key, false));
p = new Paragraph(chunk);
p.Add(dottedLine);
chunk = new Chunk(entry.Value.ToString());
chunk.SetAction(PdfAction.GotoLocalPage(entry.Key, false));
p.Add(chunk);
doc.Add(p);
}
私が持っている問題このwhith:私がやっている何
foreach (KeyValuePair<string, int> entry in entries)
{
Chunk chunk = new Chunk(entry.Key);
chunk.SetAction(PdfAction.GotoLocalPage(entry.Key, false));
p = new Paragraph(chunk);
p.Add(dottedLine);
chunk = new Chunk(entry.Value.ToString());
chunk.SetAction(PdfAction.GotoLocalPage(entry.Key, false));
p.Add(chunk);
doc.Add(p);
}
違う?私はテキストの章へのリンクを設定することはできません。私は間違って使用していると思いますDictionary<string, int>
。私はどこで間違った?
ありがとうございます。
ありがとうございます!私はそれをしました!私は間違いを理解した。 – Naomiss
私は質問があります。どのようにPDF文書のメニューに目次を追加できますか?ブックマークについては、左の枠内にあるブックマークを検索します。 'Chapter'と' Section'を使うと、自動的に作成されました。私はそれについて新しい質問を作成する必要がありますか? – Naomiss
ブックマークは 'PdfOutline'クラスを使って簡単に作ることができます。すでに名前付きの宛先*を作成しています。これらの名前付き宛先を使用してアウトラインツリーを作成できます。 –