/* * 権限設定: * PDF へのコメントの付加のみが許可されるよう権限設定を変更します。 * マスターパスワードに「PDFlib」を定義し、印刷(noprint nohiresprint)、 * 内容抽出(nocopy noaccessible)、ページ内容やフォームフィールド定義の * 変更(noassemble)を許可しない一方、注釈の作成とフォームフィールドへの * 入力を許可するように権限を設定します。 * * 必要な製品: PDFlib または PDFlib+PDI または PPS 10 * 必要なデータ: 無し */ package com.pdflib.cookbook.pdflib.general; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class permission_settings { public static void main (String argv[]) { /* 必要に応じてファイルの場所を指定する */ String searchpath = "../input"; String outfile = "permission_settings.pdf"; String title = "Permission Settings"; pdflib p = null; String optlist, text; int tf; int exitcode = 0; try { p = new pdflib(); p.set_option("searchpath={" + searchpath + "}"); /* load_font()の戻り値を確認する */ p.set_option("errorpolicy=return"); /* マスターパスワードとして"PDFlib"を定義し、印刷 (noprint nohiresprint)、 * 内容抽出 (nocopy noaccessible)、ページ内容やフォームフィールドの変更 * (noassemble)ができないよう権限を設定する。 * 注釈の作成とフォームフィールドへの入力は許可される。 */ optlist = "masterpassword=PDFlib permissions={noprint nohiresprint " + "nocopy noassemble}"; if (p.begin_document(outfile, optlist) == -1) throw new Exception("Error: " + p.get_errmsg()); p.set_info("Creator", "PDFlib Cookbook"); p.set_info("Title", title); /* ページを始める */ p.begin_page_ext(800, 400, ""); text = "The master password for this document is set to \"PDFlib\". " + "The permissions for this document are set in a way that you " + "can only create annotations. To accomplish this use the " + "following options in the begin_document() call:" + "masterpassword=PDFlibpermissions={noprint " + "nohiresprint nocopy noassemble}"; tf = p.create_textflow(text, "fontname=NotoSerif-Regular fontsize=20 leading=140%"); p.fit_textflow(tf, 50, 50, 750, 350, ""); 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); } } }