/* * 非表示テキスト : * イメージの上部に非表示テキストを出力する * * イメージを配置して、textrendering パラメータを「3」に設定して上部に * 非表示キストを作成します。 * * 必要な製品 : PDFlib/PDFlib+PDI/PPS 9 * 必要なデータ : 画像ファイル */ package com.pdflib.cookbook.pdflib.text_output; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class invisible_text { public static void main(String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "invisible_text.pdf"; String title = "Invisible Text"; pdflib p = null; String imagefile = "multi_page.tif"; int font, image; int exitcode = 0; try { p = new pdflib(); p.set_option("searchpath={" + searchpath + "}"); /* load_font() 等でエラーが起きた場合、-1を返す */ p.set_option("errorpolicy=return"); if (p.begin_document(outfile, "") == -1) throw new Exception("Error: " + p.get_errmsg()); p.set_info("Creator", "PDFlib Cookbook"); p.set_info("Title", title); font = p.load_font("Helvetica", "unicode", ""); if (font == -1) throw new Exception("Error: " + p.get_errmsg()); /* 画像をロードする */ image = p.load_image("auto", imagefile, "page=1"); if (image == -1) throw new Exception("Error: " + p.get_errmsg()); /* 出力文書を開く */ p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* 画像を配置する */ p.fit_image(image, 0, 0, "boxsize={595 842} fitmethod=meet"); p.close_image(image); /* カレントグラフィックステータスを保存する */ p.save(); /* テキストの表現モードを非表示に設定する */ p.set_text_option("textrendering=3"); /* * テキストの表現モードを上記の通り「非表示」に設定して、テキストを出力する。 * (表現モードはイメージの上、または、イメージの下に出力されるテキストに * 適用することができる。) * 以下のテキストは、OCRによってページから検索されるテキストに似ている。 */ p.setfont(font, 21); p.fit_textline("PDFlib GmbH M\u00fcnchen, Germany", 130, 750, ""); p.fit_textline("www.pdflib.com", 215, 710, ""); p.setfont(font, 28); p.fit_textline("Tutorial for", 120, 480, ""); p.fit_textline("PDFlib, PDI, and PPS", 120, 445, ""); p.setfont(font, 21); p.fit_textline("General Edition for", 195, 125, ""); p.fit_textline("Cobol, C, C++, Java, Perl", 165, 95, ""); p.fit_textline("PHP, Phyton, RPG, Ruby, and Tcl", 140, 70, ""); /* 保存したグラフィックステータスに復帰する */ p.restore(); 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); } } }