Java Tutorial/PDF/Print
Версия от 17:44, 31 мая 2010; (обсуждение)
warn you before printing the document
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
document.add(new Paragraph("test."));
PdfAction copyrightNotice = PdfAction.javaScript(
"app.alert("Warning: this document is protected by copyright.");\r", writer);
writer.setAdditionalAction(PdfWriter.WILL_PRINT, copyrightNotice);
document.close();
}
}