| Constructor: |
public PdfAction() {
// constructors
}
|
public PdfAction(URL url) {
this(url.toExternalForm());
}
Constructs a new PdfAction of Subtype URI. Parameters:
url - the Url to go to
|
public PdfAction(String url) {
this(url, false);
}
Constructs a new PdfAction of Subtype URI. Parameters:
url - the url to go to
|
PdfAction(PdfIndirectReference destination) {
put(PdfName.S, PdfName.GOTO);
put(PdfName.D, destination);
}
Constructs a new PdfAction of Subtype GoTo. Parameters:
destination - the destination to go to
|
public PdfAction(int named) {
put(PdfName.S, PdfName.NAMED);
switch (named) {
case FIRSTPAGE:
put(PdfName.N, PdfName.FIRSTPAGE);
break;
case LASTPAGE:
put(PdfName.N, PdfName.LASTPAGE);
break;
case NEXTPAGE:
put(PdfName.N, PdfName.NEXTPAGE);
break;
case PREVPAGE:
put(PdfName.N, PdfName.PREVPAGE);
break;
case PRINTDIALOG:
put(PdfName.S, PdfName.JAVASCRIPT);
put(PdfName.JS, new PdfString("this.print(true);\r"));
break;
default:
throw new RuntimeException("Invalid named action.");
}
}
Implements name actions. The action can be FIRSTPAGE, LASTPAGE,
NEXTPAGE, PREVPAGE and PRINTDIALOG. Parameters:
named - the named action
|
public PdfAction(URL url,
boolean isMap) {
this(url.toExternalForm(), isMap);
}
Construct a new PdfAction of Subtype URI that accepts the x and y coordinate of the position that was clicked. |
public PdfAction(String url,
boolean isMap) {
put(PdfName.S, PdfName.URI);
put(PdfName.URI, new PdfString(url));
if (isMap)
put(PdfName.ISMAP, PdfBoolean.PDFTRUE);
}
Construct a new PdfAction of Subtype URI that accepts the x and y coordinate of the position that was clicked. |
public PdfAction(String filename,
String name) {
put(PdfName.S, PdfName.GOTOR);
put(PdfName.F, new PdfString(filename));
put(PdfName.D, new PdfString(name));
}
Constructs a new PdfAction of Subtype GoToR. Parameters:
filename - the file name to go to
name - the named destination to go to
|
public PdfAction(String filename,
int page) {
put(PdfName.S, PdfName.GOTOR);
put(PdfName.F, new PdfString(filename));
put(PdfName.D, new PdfLiteral("[" + (page - 1) + " /FitH 10000]"));
}
Constructs a new PdfAction of Subtype GoToR. Parameters:
filename - the file name to go to
page - the page destination to go to
|
public PdfAction(String application,
String parameters,
String operation,
String defaultDir) {
put(PdfName.S, PdfName.LAUNCH);
if (parameters == null && operation == null && defaultDir == null)
put(PdfName.F, new PdfString(application));
else {
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.F, new PdfString(application));
if (parameters != null)
dic.put(PdfName.P, new PdfString(parameters));
if (operation != null)
dic.put(PdfName.O, new PdfString(operation));
if (defaultDir != null)
dic.put(PdfName.D, new PdfString(defaultDir));
put(PdfName.WIN, dic);
}
}
Launches an application or a document. Parameters:
application - the application to be launched or the document to be opened or printed.
parameters - (Windows-specific) A parameter string to be passed to the application.
It can be null.
operation - (Windows-specific) the operation to perform: "open" - Open a document,
"print" - Print a document.
It can be null.
defaultDir - (Windows-specific) the default directory in standard DOS syntax.
It can be null.
|
| Method from com.lowagie.text.pdf.PdfAction Detail: |
static PdfArray buildArray(Object[] names) {
PdfArray array = new PdfArray();
for (int k = 0; k < names.length; ++k) {
Object obj = names[k];
if (obj instanceof String)
array.add(new PdfString((String)obj));
else if (obj instanceof PdfAnnotation)
array.add(((PdfAnnotation)obj).getIndirectReference());
else
throw new RuntimeException("The array must contain String or PdfAnnotation.");
}
return array;
}
|
static PdfAction createHide(PdfObject obj,
boolean hide) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.HIDE);
action.put(PdfName.T, obj);
if (!hide)
action.put(PdfName.H, PdfBoolean.PDFFALSE);
return action;
}
A Hide action hides or shows an object. |
public static PdfAction createHide(PdfAnnotation annot,
boolean hide) {
return createHide(annot.getIndirectReference(), hide);
}
A Hide action hides or shows an annotation. |
public static PdfAction createHide(String name,
boolean hide) {
return createHide(new PdfString(name), hide);
}
A Hide action hides or shows an annotation. |
public static PdfAction createHide(Object[] names,
boolean hide) {
return createHide(buildArray(names), hide);
}
A Hide action hides or shows objects. |
public static PdfAction createImportData(String file) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.IMPORTDATA);
action.put(PdfName.F, new PdfString(file));
return action;
}
|
public static PdfAction createLaunch(String application,
String parameters,
String operation,
String defaultDir) {
return new PdfAction(application, parameters, operation, defaultDir);
}
Launches an application or a document. |
public static PdfAction createResetForm(Object[] names,
int flags) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.RESETFORM);
if (names != null)
action.put(PdfName.FIELDS, buildArray(names));
action.put(PdfName.FLAGS, new PdfNumber(flags));
return action;
}
|
public static PdfAction createSubmitForm(String file,
Object[] names,
int flags) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.SUBMITFORM);
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.F, new PdfString(file));
dic.put(PdfName.FS, PdfName.URL);
action.put(PdfName.F, dic);
if (names != null)
action.put(PdfName.FIELDS, buildArray(names));
action.put(PdfName.FLAGS, new PdfNumber(flags));
return action;
}
|
public static PdfAction gotoEmbedded(String filename,
PdfTargetDictionary target,
PdfObject dest,
boolean newWindow) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.GOTOE);
action.put(PdfName.T, target);
action.put(PdfName.D, dest);
action.put(PdfName.NEWWINDOW, new PdfBoolean(newWindow));
if (filename != null) {
action.put(PdfName.F, new PdfString(filename));
}
return action;
}
Creates a GoToE action to an embedded file. |
public static PdfAction gotoEmbedded(String filename,
PdfTargetDictionary target,
String dest,
boolean isName,
boolean newWindow) {
if (isName)
return gotoEmbedded(filename, target, new PdfName(dest), newWindow);
else
return gotoEmbedded(filename, target, new PdfString(dest, null), newWindow);
}
Creates a GoToE action to an embedded file. |
public static PdfAction gotoLocalPage(String dest,
boolean isName) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.GOTO);
if (isName)
action.put(PdfName.D, new PdfName(dest));
else
action.put(PdfName.D, new PdfString(dest, null));
return action;
}
Creates a GoTo action to a named destination. |
public static PdfAction gotoLocalPage(int page,
PdfDestination dest,
PdfWriter writer) {
PdfIndirectReference ref = writer.getPageReference(page);
dest.addPage(ref);
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.GOTO);
action.put(PdfName.D, dest);
return action;
}
Creates a GoTo action to an internal page. |
public static PdfAction gotoRemotePage(String filename,
String dest,
boolean isName,
boolean newWindow) {
PdfAction action = new PdfAction();
action.put(PdfName.F, new PdfString(filename));
action.put(PdfName.S, PdfName.GOTOR);
if (isName)
action.put(PdfName.D, new PdfName(dest));
else
action.put(PdfName.D, new PdfString(dest, null));
if (newWindow)
action.put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
return action;
}
Creates a GoToR action to a named destination. |
public static PdfAction javaScript(String code,
PdfWriter writer) {
return javaScript(code, writer, false);
}
Creates a JavaScript action. If the JavaScript is smaller than
50 characters it will be place as a string, otherwise it will
be placed as a compressed stream. |
public static PdfAction javaScript(String code,
PdfWriter writer,
boolean unicode) {
PdfAction js = new PdfAction();
js.put(PdfName.S, PdfName.JAVASCRIPT);
if (unicode && code.length() < 50) {
js.put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE));
}
else if (!unicode && code.length() < 100) {
js.put(PdfName.JS, new PdfString(code));
}
else {
try {
byte b[] = PdfEncodings.convertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING);
PdfStream stream = new PdfStream(b);
stream.flateCompress(writer.getCompressionLevel());
js.put(PdfName.JS, writer.addToBody(stream).getIndirectReference());
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}
return js;
}
Creates a JavaScript action. If the JavaScript is smaller than
50 characters it will be placed as a string, otherwise it will
be placed as a compressed stream. |
public void next(PdfAction na) {
PdfObject nextAction = get(PdfName.NEXT);
if (nextAction == null)
put(PdfName.NEXT, na);
else if (nextAction.isDictionary()) {
PdfArray array = new PdfArray(nextAction);
array.add(na);
put(PdfName.NEXT, array);
}
else {
((PdfArray)nextAction).add(na);
}
}
|
public static PdfAction rendition(String file,
PdfFileSpecification fs,
String mimeType,
PdfIndirectReference ref) throws IOException {
PdfAction js = new PdfAction();
js.put(PdfName.S, PdfName.RENDITION);
js.put(PdfName.R, new PdfRendition(file, fs, mimeType));
js.put(new PdfName("OP"), new PdfNumber(0));
js.put(new PdfName("AN"), ref);
return js;
}
Creates a Rendition action |
public static PdfAction setOCGstate(ArrayList state,
boolean preserveRB) {
PdfAction action = new PdfAction();
action.put(PdfName.S, PdfName.SETOCGSTATE);
PdfArray a = new PdfArray();
for (int k = 0; k < state.size(); ++k) {
Object o = state.get(k);
if (o == null)
continue;
if (o instanceof PdfIndirectReference)
a.add((PdfIndirectReference)o);
else if (o instanceof PdfLayer)
a.add(((PdfLayer)o).getRef());
else if (o instanceof PdfName)
a.add((PdfName)o);
else if (o instanceof String) {
PdfName name = null;
String s = (String)o;
if (s.equalsIgnoreCase("on"))
name = PdfName.ON;
else if (s.equalsIgnoreCase("off"))
name = PdfName.OFF;
else if (s.equalsIgnoreCase("toggle"))
name = PdfName.TOGGLE;
else
throw new IllegalArgumentException("A string '" + s + " was passed in state. Only 'ON', 'OFF' and 'Toggle' are allowed.");
a.add(name);
}
else
throw new IllegalArgumentException("Invalid type was passed in state: " + o.getClass().getName());
}
action.put(PdfName.STATE, a);
if (!preserveRB)
action.put(PdfName.PRESERVERB, PdfBoolean.PDFFALSE);
return action;
}
A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
groups. |