本文整理汇总了Java中com.lowagie.text.pdf.PdfAction类的典型用法代码示例。如果您正苦于以下问题:Java PdfAction类的具体用法?Java PdfAction怎么用?Java PdfAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfAction类属于com.lowagie.text.pdf包,在下文中一共展示了PdfAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with a javascript action.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("JavaScript");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "JavaScriptAction.pdf"));
// step 3: we add Javascript as Metadata and we open the document
document.open();
// step 4: we add some content
Paragraph p = new Paragraph(new Chunk("Click to say Hello").setAction(PdfAction.javaScript(
"app.alert('Hello');\r", writer)));
document.add(p);
} catch (Exception de) {
de.printStackTrace();
}
// step 5: we close the document
document.close();
}
示例2: convertAnnotation
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
public static PdfAnnotation convertAnnotation(PdfWriter writer, Annotation annot, Rectangle defaultRect) throws IOException {
switch(annot.annotationType()) {
case Annotation.URL_NET:
return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((URL) annot.attributes().get(Annotation.URL)));
case Annotation.URL_AS_STRING:
return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE)));
case Annotation.FILE_DEST:
return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE), (String) annot.attributes().get(Annotation.DESTINATION)));
case Annotation.SCREEN:
boolean sparams[] = (boolean[])annot.attributes().get(Annotation.PARAMETERS);
String fname = (String) annot.attributes().get(Annotation.FILE);
String mimetype = (String) annot.attributes().get(Annotation.MIMETYPE);
PdfFileSpecification fs;
if (sparams[0])
fs = PdfFileSpecification.fileEmbedded(writer, fname, fname, null);
else
fs = PdfFileSpecification.fileExtern(writer, fname);
PdfAnnotation ann = PdfAnnotation.createScreen(writer, new Rectangle(annot.llx(), annot.lly(), annot.urx(), annot.ury()),
fname, fs, mimetype, sparams[1]);
return ann;
case Annotation.FILE_PAGE:
return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE), ((Integer) annot.attributes().get(Annotation.PAGE)).intValue()));
case Annotation.NAMED_DEST:
return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction(((Integer) annot.attributes().get(Annotation.NAMED)).intValue()));
case Annotation.LAUNCH:
return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.APPLICATION),(String) annot.attributes().get(Annotation.PARAMETERS),(String) annot.attributes().get(Annotation.OPERATION),(String) annot.attributes().get(Annotation.DEFAULTDIR)));
default:
return new PdfAnnotation(writer, defaultRect.getLeft(), defaultRect.getBottom(), defaultRect.getRight(), defaultRect.getTop(), new PdfString(annot.title(), PdfObject.TEXT_UNICODE), new PdfString(annot.content(), PdfObject.TEXT_UNICODE));
}
}
示例3: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Demonstrates the use of layers.
*
* @param args
* no arguments needed
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("optionalcontent.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeUseOC);
// step 3: opening the document
document.open();
// step 4: content
PdfContentByte cb = writer.getDirectContent();
Phrase explanation = new Phrase(
"Automatic layers, form fields, images, templates and actions",
new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
650, 0);
PdfLayer l1 = new PdfLayer("Layer 1", writer);
PdfLayer l2 = new PdfLayer("Layer 2", writer);
PdfLayer l3 = new PdfLayer("Layer 3", writer);
PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
PdfLayerMembership m1 = new PdfLayerMembership(writer);
m1.addMember(l2);
m1.addMember(l3);
Phrase p1 = new Phrase("Text in layer 1");
Phrase p2 = new Phrase("Text in layer 2 or layer 3");
Phrase p3 = new Phrase("Text in layer 3");
cb.beginLayer(l1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
cb.endLayer();
cb.beginLayer(m1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
cb.endLayer();
cb.beginLayer(l3);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
cb.endLayer();
TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
"field1");
ff.setBorderColor(Color.blue);
ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
ff.setText("I'm a form field");
PdfFormField form = ff.getTextField();
form.setLayer(l4);
writer.addAnnotation(form);
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
+ "pngnow.png");
img.setLayer(l4);
img.setAbsolutePosition(200, 550);
cb.addImage(img);
PdfTemplate tp = cb.createTemplate(100, 20);
Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
Font.NORMAL, Color.magenta));
ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
tp.setLayer(l4);
tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
cb.addTemplate(tp, 200, 500);
ArrayList<Object> state = new ArrayList<Object>();
state.add("toggle");
state.add(l1);
state.add(l2);
state.add(l3);
state.add(l4);
PdfAction action = PdfAction.setOCGstate(state, true);
Chunk ck = new Chunk("Click here to toggle the layers", new Font(
Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
Color.blue).setAction(action);
ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
250, 400, 0);
cb.sanityCheck();
// step 5: closing the document
document.close();
}
示例4: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with Named Actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NamedActions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
Paragraph p = new Paragraph(new Chunk("Click to print").setAction(new PdfAction(PdfAction.PRINTDIALOG)));
PdfPTable table = new PdfPTable(4);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(new Phrase(new Chunk("First Page").setAction(new PdfAction(PdfAction.FIRSTPAGE))));
table.addCell(new Phrase(new Chunk("Prev Page").setAction(new PdfAction(PdfAction.PREVPAGE))));
table.addCell(new Phrase(new Chunk("Next Page").setAction(new PdfAction(PdfAction.NEXTPAGE))));
table.addCell(new Phrase(new Chunk("Last Page").setAction(new PdfAction(PdfAction.LASTPAGE))));
for (int k = 1; k <= 10; ++k) {
document.add(new Paragraph("This is page " + k));
document.add(Chunk.NEWLINE);
document.add(table);
document.add(p);
document.newPage();
}
// step 5: we close the document
document.close();
}
示例5: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with Named Actions.
*
* @param args The file to open
*/
public void main(String... args) throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OpenApplication.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
String application = args[0];
Paragraph p = new Paragraph(new Chunk("Click to open " + application).setAction(
new PdfAction(application, null, null, null)));
document.add(p);
// step 5: we close the document
document.close();
}
示例6: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with some goto actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
Document remote = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Actions.pdf"));
PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
// step 3:
document.open();
remote.open();
// step 4: we add some content
PdfAction action = PdfAction.gotoLocalPage(2, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer);
writer.setOpenAction(action);
document.add(new Paragraph("Page 1"));
document.newPage();
document.add(new Paragraph("Page 2"));
document.add(new Chunk("goto page 1").setAction(PdfAction.gotoLocalPage(1, new PdfDestination(
PdfDestination.FITH, 500), writer)));
document.add(Chunk.NEWLINE);
document.add(new Chunk("goto another document").setAction(PdfAction.gotoRemotePage("remote.pdf", "test", false,
true)));
remote.add(new Paragraph("Some remote document"));
remote.newPage();
Paragraph p = new Paragraph("This paragraph contains a ");
p.add(new Chunk("local destination").setLocalDestination("test"));
remote.add(p);
// step 5: we close the document
document.close();
remote.close();
}
示例7: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with chained Actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ChainedActions.pdf"));
// step 3: we add Javascript as Metadata and we open the document
document.open();
// step 4: we add some content
PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
action.next(new PdfAction("http://www.lowagie.com/iText/"));
Paragraph p = new Paragraph(new Chunk("Click to go to Bruno's site").setAction(action));
document.add(p);
// step 5: we close the document
document.close();
}
示例8: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with Named Actions.
*
* @param args
* the system root (for instance "C:\windows\")
*/
public static void main(String[] args) {
System.out.println("Open Application");
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "OpenApplication.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
String application = args[0] + "notepad.exe";
Paragraph p = new Paragraph(new Chunk("Click to open " + application).setAction(new PdfAction(application,
null, null, null)));
document.add(p);
} catch (Exception de) {
de.printStackTrace();
}
// step 5: we close the document
document.close();
}
示例9: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with some goto actions.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Actions");
// step 1: creation of a document-object
Document document = new Document();
Document remote = new Document();
try {
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "Actions.pdf"));
PdfWriter.getInstance(remote, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "remote.pdf"));
// step 3:
document.open();
remote.open();
// step 4: we add some content
PdfAction action = PdfAction.gotoLocalPage(2, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer);
writer.setOpenAction(action);
document.add(new Paragraph("Page 1"));
document.newPage();
document.add(new Paragraph("Page 2"));
document.add(new Chunk("goto page 1").setAction(PdfAction.gotoLocalPage(1, new PdfDestination(
PdfDestination.FITH, 500), writer)));
document.add(Chunk.NEWLINE);
document.add(new Chunk("goto another document").setAction(PdfAction.gotoRemotePage("remote.pdf", "test",
false, true)));
remote.add(new Paragraph("Some remote document"));
remote.newPage();
Paragraph p = new Paragraph("This paragraph contains a ");
p.add(new Chunk("local destination").setLocalDestination("test"));
remote.add(p);
} catch (Exception de) {
de.printStackTrace();
}
// step 5: we close the document
document.close();
remote.close();
}
示例10: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with Named Actions.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Named Actions");
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "NamedActions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
Paragraph p = new Paragraph(new Chunk("Click to print").setAction(new PdfAction(PdfAction.PRINTDIALOG)));
PdfPTable table = new PdfPTable(4);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(new Phrase(new Chunk("First Page").setAction(new PdfAction(PdfAction.FIRSTPAGE))));
table.addCell(new Phrase(new Chunk("Prev Page").setAction(new PdfAction(PdfAction.PREVPAGE))));
table.addCell(new Phrase(new Chunk("Next Page").setAction(new PdfAction(PdfAction.NEXTPAGE))));
table.addCell(new Phrase(new Chunk("Last Page").setAction(new PdfAction(PdfAction.LASTPAGE))));
for (int k = 1; k <= 10; ++k) {
document.add(new Paragraph("This is page " + k));
document.add(Chunk.NEWLINE);
document.add(table);
document.add(p);
document.newPage();
}
} catch (Exception de) {
de.printStackTrace();
}
// step 5: we close the document
document.close();
}
示例11: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with chained Actions.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Chained actions");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "ChainedActions.pdf"));
// step 3: we add Javascript as Metadata and we open the document
document.open();
// step 4: we add some content
PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
action.next(new PdfAction("http://www.lowagie.com/iText/"));
Paragraph p = new Paragraph(new Chunk("Click to go to Bruno's site").setAction(action));
document.add(p);
} catch (Exception de) {
de.printStackTrace();
}
// step 5: we close the document
document.close();
}
示例12: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with a javascript action.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("JavaScriptAction.pdf"));
// step 3: we add Javascript as Metadata and we open the document
document.open();
// step 4: we add some content
Paragraph p = new Paragraph(new Chunk("Click to say Hello").setAction(PdfAction.javaScript(
"app.alert('Hello');\r", writer)));
document.add(p);
// step 5: we close the document
document.close();
}
示例13: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates a document with some PdfAnnotations.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Annotations.pdf"));
// step 3:
writer.setPdfVersion(PdfWriter.VERSION_1_5);
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
// page 1
PdfFileSpecification fs = PdfFileSpecification.fileExtern(writer, PdfTestBase.RESOURCES_DIR + "cards.mpg");
writer.addAnnotation(PdfAnnotation.createScreen(writer, new Rectangle(200f, 700f, 300f, 800f), "cards.mpg", fs,
"video/mpeg", true));
PdfAnnotation a = new PdfAnnotation(writer, 200f, 550f, 300f, 650f, PdfAction.javaScript(
"app.alert('Hello');\r", writer));
document.add(new Chunk("click to trigger javascript").setAnnotation(a).setLocalDestination("top"));
writer.addAnnotation(a);
writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f),
"This is some text", "some text".getBytes(), null, "some.txt"));
writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(200f, 400f, 300f, 500f), "Help",
"This Help annotation was made with 'createText'", false, "Help"));
writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(200f, 250f, 300f, 350f), "Help",
"This Comment annotation was made with 'createText'", true, "Comment"));
cb.rectangle(200, 700, 100, 100);
cb.rectangle(200, 550, 100, 100);
cb.rectangle(200, 400, 100, 100);
cb.rectangle(200, 250, 100, 100);
cb.stroke();
document.newPage();
// page 2
writer.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle(200f, 700f, 300f, 800f),
PdfAnnotation.HIGHLIGHT_TOGGLE, PdfAction.javaScript("app.alert('Hello');\r", writer)));
writer.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle(200f, 550f, 300f, 650f),
PdfAnnotation.HIGHLIGHT_OUTLINE, "top"));
writer.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle(200f, 400f, 300f, 500f),
PdfAnnotation.HIGHLIGHT_PUSH, 1, new PdfDestination(PdfDestination.FIT)));
writer.addAnnotation(PdfAnnotation.createSquareCircle(writer, new Rectangle(200f, 250f, 300f, 350f),
"This Comment annotation was made with 'createSquareCircle'", false));
document.newPage();
// page 3
PdfContentByte pcb = new PdfContentByte(writer);
pcb.setColorFill(new Color(0xFF, 0x00, 0x00));
writer.addAnnotation(PdfAnnotation.createFreeText(writer, new Rectangle(200f, 700f, 300f, 800f),
"This is some free text, blah blah blah", pcb));
writer.addAnnotation(PdfAnnotation.createLine(writer, new Rectangle(200f, 550f, 300f, 650f), "this is a line",
200, 550, 300, 650));
writer.addAnnotation(PdfAnnotation.createStamp(writer, new Rectangle(200f, 400f, 300f, 500f),
"This is a stamp", "Stamp"));
writer.addAnnotation(PdfAnnotation.createPopup(writer, new Rectangle(200f, 250f, 300f, 350f),
"Hello, I'm a popup!", true));
cb.rectangle(200, 700, 100, 100);
cb.rectangle(200, 550, 100, 100);
cb.rectangle(200, 250, 100, 100);
cb.stroke();
// step 5: we close the document
document.close();
}
示例14: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Creates documents with some simple annotations.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document1 = new Document(PageSize.A4, 10, 10, 10, 10);
Document document2 = new Document(PageSize.A4, 10, 10, 10, 10);
// step 2:
PdfWriter writer1 = PdfWriter.getInstance(document1, PdfTestBase.getOutputStream("SimpleAnnotations1.pdf"));
PdfWriter writer2 = PdfWriter.getInstance(document2, PdfTestBase.getOutputStream("SimpleAnnotations2.pdf"));
// step 3:
writer2.setPdfVersion(PdfWriter.VERSION_1_5);
document1.open();
document2.open();
// step 4:
document1.add(new Paragraph("Each square on this page represents an annotation."));
// document1
PdfContentByte cb1 = writer1.getDirectContent();
Annotation a1 = new Annotation("authors",
"Maybe it's because I wanted to be an author myself that I wrote iText.", 250f, 700f, 350f, 800f);
document1.add(a1);
Annotation a2 = new Annotation(250f, 550f, 350f, 650f, new URL("http://www.lowagie.com/iText/"));
document1.add(a2);
Annotation a3 = new Annotation(250f, 400f, 350f, 500f, "http://www.lowagie.com/iText");
document1.add(a3);
Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.gif");
image.setAnnotation(a3);
document1.add(image);
Annotation a4 = new Annotation(250f, 250f, 350f, 350f, PdfAction.LASTPAGE);
document1.add(a4);
// draw rectangles to show where the annotations were added
cb1.rectangle(250, 700, 100, 100);
cb1.rectangle(250, 550, 100, 100);
cb1.rectangle(250, 400, 100, 100);
cb1.rectangle(250, 250, 100, 100);
cb1.stroke();
// more content
document1.newPage();
for (int i = 0; i < 5; i++) {
document1.add(new Paragraph("blahblahblah"));
}
document1.add(new Annotation("blahblah", "Adding an annotation without specifying coordinates"));
for (int i = 0; i < 3; i++) {
document1.add(new Paragraph("blahblahblah"));
}
document1.newPage();
document1.add(new Chunk("marked chunk").setLocalDestination("mark"));
File videoFile = new File(PdfTestBase.RESOURCES_DIR + "cards.mpg");
File license = new File("LICENSE");
// document2
document2.add(new Paragraph("Each square on this page represents an annotation."));
PdfContentByte cb2 = writer2.getDirectContent();
Annotation a5 = new Annotation(100f, 700f, 200f, 800f, videoFile.getAbsolutePath(), "video/mpeg", true);
document2.add(a5);
Annotation a6 = new Annotation(100f, 550f, 200f, 650f, "SimpleAnnotations1.pdf", "mark");
document2.add(a6);
Annotation a7 = new Annotation(100f, 400f, 200f, 500f, "SimpleAnnotations1.pdf", 2);
document2.add(a7);
Annotation a8 = new Annotation(100f, 250f, 200f, 350f, license.getAbsolutePath(), null, null, null);
document2.add(a8);
// draw rectangles to show where the annotations were added
cb2.rectangle(100, 700, 100, 100);
cb2.rectangle(100, 550, 100, 100);
cb2.rectangle(100, 400, 100, 100);
cb2.rectangle(100, 250, 100, 100);
cb2.stroke();
// step 5: we close the document
document1.close();
document2.close();
}
示例15: main
import com.lowagie.text.pdf.PdfAction; //导入依赖的package包/类
/**
* Demonstrates some PageLabel functionality.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
Document remote = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OutlineActions.pdf"));
PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
// step 3:
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
document.open();
remote.open();
// step 4:
// we add some content
document.add(new Paragraph("Outline action example"));
// we add the outline
PdfContentByte cb = writer.getDirectContent();
PdfOutline root = cb.getRootOutline();
PdfOutline links = new PdfOutline(root, new PdfAction("http://www.lowagie.com/iText/links.html"),
"Useful links");
links.setColor(new Color(0x00, 0x80, 0x80));
links.setStyle(Font.BOLD);
new PdfOutline(links, new PdfAction("http://www.lowagie.com/iText"), "Bruno's iText site");
new PdfOutline(links, new PdfAction("http://itextpdf.sourceforge.net/"), "Paulo's iText site");
new PdfOutline(links, new PdfAction("http://sourceforge.net/projects/itext/"), "iText @ SourceForge");
PdfOutline other = new PdfOutline(root, new PdfDestination(PdfDestination.FIT), "other actions", false);
other.setStyle(Font.ITALIC);
new PdfOutline(other, new PdfAction("remote.pdf", 1), "Go to yhe first page of a remote file");
new PdfOutline(other, new PdfAction("remote.pdf", "test"), "Go to a local destination in a remote file");
new PdfOutline(other, PdfAction.javaScript("app.alert('Hello');\r", writer), "Say Hello");
remote.add(new Paragraph("Some remote document"));
remote.newPage();
Paragraph p = new Paragraph("This paragraph contains a ");
p.add(new Chunk("local destination").setLocalDestination("test"));
remote.add(p);
// step 5: we close the document
document.close();
remote.close();
}