如果您的應用程序是一個Web應用程序,並且您不想在pdf文檔中創建索引,這將有所幫助。
最簡單的方法是利用錨點和鏈接。
閱讀這些請: link anchor
然後看到完整的代碼示例波紋管。您可以將其全部複製到test.html文件中,然後在瀏覽器中打開它以查看它的行爲。
<body>
<script type="text/javascript">
document.write("\<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'>\<\/script>");
</script>
<style>
section{font-size:100px;}
</style>
First things first, your data setup seems odd. If you can change that string's setup, try going the JSON way. For example:
<script>
var jsonString = '{ "section1":2, "section2":3, "section3":1, "section4":4 }';
var objectFromJson = jQuery.parseJSON(jsonString);
var ul = $('<ul>');
for (var prop in objectFromJson)
{
var li = $("<li>");
var divTitle = $("<div>");
divTitle.addClass("title");
var titleLink = $("<a>");
titleLink.text(prop);
titleLink.attr("href","#" + prop + "/" + objectFromJson[prop])
divTitle.append(titleLink)
li.append(divTitle);
ul.append(li);
}
$("body").append(ul);
</script>
If that is not possible, let's continue on what you have
<script>
var str = "section1;section2;section3;section4|2 3 1 4"
var options = str.split('|');
var sections = options[0];
var numbers = options[1];
var section_titles = sections.split(';');
var numbersArr = numbers.split(' ');
var ul = $('<ul>');
for (var a=0; a < section_titles.length; a++)
{
if(numbersArr.length > a)
{
var li = $("<li>");
var divTitle = $("<div>");
var titleLink = $("<a>");
titleLink.text(section_titles[a]);
titleLink.attr("href","#" + section_titles[a] + "/" + numbersArr[a])
divTitle.addClass("title");
divTitle.append(titleLink)
li.append(divTitle);
ul.append(li);
}
}
$("body").append(ul);
</script>
<section>
<a name="section1/2">section1</a><br/><br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at tristique est. Curabitur rhoncus consequat sagittis. Proin pharetra elit nec turpis rutrum a lobortis nisi ornare. Nulla nec nisl diam, vel semper orci. Phasellus iaculis nibh a velit pulvinar sagittis eu ut massa. Cras vestibulum, urna sed ultrices consequat, purus leo venenatis lorem, a bibendum nibh eros ut leo. Curabitur viverra urna id ante mattis ultrices. Nulla et velit enim, vel condimentum magna. Vestibulum ullamcorper consectetur porta. Maecenas eget dui nec turpis condimentum aliquet in in risus.
</section>
<section>
<a name="section2/3">section2</a><br/><br/>
Ut ac blandit nisi. Phasellus fringilla, est vel hendrerit mollis, dui sem sagittis justo, eget fermentum odio ipsum at sem. Sed tempor, nibh eu vulputate vehicula, lectus neque eleifend erat, at tincidunt orci dui a tellus. Vestibulum viverra urna in tellus vestibulum semper. Etiam volutpat sodales rutrum. Morbi elementum, lacus ut fermentum malesuada, ipsum sem viverra arcu, ut consequat libero dui et arcu. Cras ut libero nulla, nec rhoncus erat. Integer id enim id nulla sagittis congue. Integer mollis tempor viverra. Ut non nisi sem, et semper lacus. Vivamus turpis mi, hendrerit non pellentesque a, iaculis id nibh. Pellentesque nec arcu magna, at posuere eros. Duis eu quam at nulla porttitor aliquet. Vestibulum cursus mattis purus, a sodales mi rhoncus vitae. Phasellus quis urna nec orci rhoncus consequat.
</section>
<section>
<a name="section3/1">section3</a><br/><br/>
Donec pellentesque congue sollicitudin. Fusce aliquam, velit et cursus iaculis, nisl massa vulputate magna, vitae imperdiet felis tortor sit amet purus. Vivamus aliquet laoreet ligula quis aliquet. Vivamus fringilla purus ut lorem faucibus viverra. Sed accumsan tincidunt tempus. Donec id velit in dolor luctus gravida. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean sit amet nulla augue. Proin vel tincidunt est. Curabitur imperdiet elementum suscipit. Praesent dignissim magna eget sapien pretium vestibulum id at arcu. Integer egestas purus non.
</section>
<section>
<a name="section4/4">section4</a><br/><br/>
Donec pellentesque congue sollicitudin. Fusce aliquam, velit et cursus iaculis, nisl massa vulputate magna, vitae imperdiet felis tortor sit amet purus. Vivamus aliquet laoreet ligula quis aliquet. Vivamus fringilla purus ut lorem faucibus viverra. Sed accumsan tincidunt tempus. Donec id velit in dolor luctus gravida. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean sit amet nulla augue. Proin vel tincidunt est. Curabitur imperdiet elementum suscipit. Praesent dignissim magna eget sapien pretium vestibulum id at arcu. Integer egestas purus non.
</section>
</body>
我重讀了幾遍似乎無法理解你下一步想做什麼的問題。另外,我認爲'a
elclanrs
對不起,我基本上有一個應用程序,它將pdf文檔合併並柵格化爲一個文件。但是我想使用應用程序用來創建合併單個文件的目錄的文件,它使用這些文件來創建。我知道文檔標題和每個頁面的計數,但無法找到將它們列爲內容列表的方式,因此用戶可以單擊標題並轉到文檔中的該頁面。這是否更有意義? – jlukin