package com.pdflib.cookbook.pdflib.text_output; /* * * 編集可能な透かし(ウォーターマーク)を作成する * * 必要な製品: PDFlib 9.0.6 * 必要なデータ: イメージファイル */ import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class watermark { public static void main(String argv[]) { int image; pdflib p = null; String imagefile = "nesrin.jpg"; /* * インプットファイルが存在する場所を指定する。 */ String searchpath = "../input"; String title = "Create Editable Watermark"; int exitcode = 0; try { p = new pdflib(); /* * errorpolicy に return を設定する。これは、load_font() などで、戻り値を * チェックする必要があることを示している。 * * イメージファイルの検索パスを設定する。 */ p.set_option( "errorpolicy=return SearchPath={{" + searchpath + "}}"); if (p.begin_document("watermark.pdf", "") == -1) throw new Exception("Error: " + p.get_errmsg()); p.set_info("Creator", "PDFlib Cookbook"); p.set_info("Title", title); /* * 透かしを作成する。デフォルトではドキュメント内の全てのページに * 適用する */ p.begin_template_ext(0, 0, "watermark={location=ontop opacity=60%}"); p.fit_textline("Preliminary", 0, 0, "fontsize=12 fontname=Helvetica-Bold encoding=unicode " + "fillcolor=red boxsize={595 842} stamp=ll2ur"); p.end_template_ext(0, 0); /* * ページコンテンツを作成する */ image = p.load_image("auto", imagefile, ""); if (image == -1) throw new Exception("Error: " + p.get_errmsg()); p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); p.fit_textline("The watermark can be edited in Acrobat", 20, 600, "fontname=Helvetica encoding=unicode fontsize=14"); p.fit_image(image, 0.0, 0.0, "boxsize={595 600} fitmethod=meet"); p.close_image(image); p.end_page_ext(""); p.end_document(""); } catch (PDFlibException e) { System.err.println("PDFlib exception occurred in image sample:"); 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); } } }