pdfua/list_pdfua1
Demonstrate PDF/UA list tagging.
Download Java Code Switch to PHP Code Show Output
/*
* Demonstrate list tagging
*
* required software: PDFlib/PDFlib+PDI/PPS 10
* required data: font
*/
package com.pdflib.cookbook.pdflib.pdfua;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class list_pdfua1 {
public static void main(String argv[]) {
pdflib p = null;
String title = "list_pdfua1";
int exitcode = 0;
try {
int font;
int id_list, id_listitem;
double x1 = 50, x2 = 65, y = 700, leading = 36;
/* This is where the data files are. Adjust as necessary. */
String searchpath = "../input";
p = new pdflib();
p.set_option("errorpolicy=exception searchpath={" + searchpath
+ "}");
if (p.begin_document(title + ".pdf",
"pdfua=PDF/UA-1 lang=en tag={tagname=Document}") == -1)
throw new Exception("Error: " + p.get_errmsg());
p.set_info("Creator", "PDFlib Cookbook");
p.set_info("Title", title);
/* Automatically create spaces between chunks of text */
p.set_option("autospace=true");
p.set_option("charref=true");
p.begin_page_ext(0, 0, "width=a4.width height=a4.height");
font = p.load_font("NotoSerif-Regular", "unicode", "");
p.setfont(font, 16);
p.create_bookmark("Tagged list demo", "");
p.fit_textline("Tagged list demo", x1, 750,
"tag={tagname=H1} fontsize=24");
id_list = p.begin_item("L", "ListNumbering=Disc");
/* Create both Caption and P elements at once */
p.fit_textline("The following kinds of fruit are available:", x1,
y, "tag={tagname=Caption tag={tagname=P}}");
y -= leading;
id_listitem = p.begin_item("LI", "");
p.fit_textline("•", x1, y, "tag={tagname=Lbl}");
p.fit_textline("Apples", x2, y, "tag={tagname=LBody}");
y -= leading;
p.end_item(id_listitem);
id_listitem = p.begin_item("LI", "");
p.fit_textline("•", x1, y, "tag={tagname=Lbl}");
p.fit_textline("Oranges", x2, y, "tag={tagname=LBody}");
y -= leading;
p.end_item(id_listitem);
id_listitem = p.begin_item("LI", "");
p.fit_textline("•", x1, y, "tag={tagname=Lbl}");
p.fit_textline("Bananas", x2, y, "tag={tagname=LBody}");
y -= leading;
p.end_item(id_listitem);
p.end_item(id_list);
p.end_page_ext("");
p.end_document("");
}
catch (PDFlibException e) {
System.err.println("PDFlib exception occurred:");
System.err.println("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.get_errmsg());
exitcode = 1;
}
catch (Exception e) {
System.err.println(e);
exitcode = 1;
}
finally {
if (p != null) {
p.delete();
}
System.exit(exitcode);
}
}
}