/*
* 複数色でグラデーションを表示するサンプルプログラムです。
*
* 必要な製品:PDFlib/PDFlib+PDI/PPS
*
* 2018 Copyright (c) infoTek K.K. all rights reserved.
* 当ソースコードにより生じたすべての不利益について、当社は責任を負いません。
*
*/
import com.pdflib.PDFlibException;
import com.pdflib.pdflib;
public class many_colors_gradient {
public static void main(String argv[]) {
String outfile = "many_colors_gradient.pdf";
String title = "Many Color Gradient";
pdflib p = null;
int font, sh, pattern1, pattern2, pattern3;
int fontsize = 36;
try {
p = new pdflib();
p.set_option("errorpolicy=return");
if (p.begin_document(outfile, "") == -1)
throw new Exception("Error: " + p.get_errmsg());
p.set_info("Creator", "infoTek K.K.");
p.set_info("Title", title);
/* ページを開始する */
p.begin_page_ext(595, 842, "");
//--- パターン1 :左下から右上方向のグラデーション(4色)
/* パターン定義を開始する */
pattern1 = p.begin_pattern_ext(360, 360, "transform={rotate=45 translate={-80 0}}");
/* 開始色"緑" */
p.setcolor("fill", "rgb", 0.0, 1.0, 0.0, 0.0);
/* 終了色"水色" */
sh = p.shading("axial", 0, 0, 120, 0, 0.0, 1.0, 1.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"水色" */
p.setcolor("fill", "rgb", 0.0, 1.0, 1.0, 0.0);
/* 終了色"青" */
sh = p.shading("axial", 120, 0, 240, 0, 0.0, 0.0, 1.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"青" */
p.setcolor("fill", "rgb", 0.0, 0.0, 1.0, 0.0);
/* 終了色"黒" */
sh = p.shading("axial", 240, 0, 360, 0, 0.0, 0.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* パターン定義を終了する */
p.end_pattern();
//--- パターン2 : 下から上方向のグラデーション(4色)
/* パターン定義を開始する */
pattern2 = p.begin_pattern_ext(160, 160, "transform={rotate=90 translate={40 0}}");
/* 開始色"白" */
p.setcolor("fill", "rgb", 1.0, 1.0, 1.0, 0.0);
/* 終了色"赤" */
sh = p.shading("axial", 0, 0, 50, 0, 1.0, 0.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"赤" */
p.setcolor("fill", "rgb", 1.0, 0.0, 0.0, 0.0);
/* 終了色"黄" */
sh = p.shading("axial", 50, 0, 80, 0, 1.0, 1.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"黄" */
p.setcolor("fill", "rgb", 1.0, 1.0, 0.0, 0.0);
/* 終了色"緑" */
sh = p.shading("axial", 80, 0, 160, 0, 0.0, 1.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* パターン定義を終了する */
p.end_pattern();
//---パターン3 : 左から右方向のグラデーション(7色)
/* パターン定義を開始する */
pattern3 = p.begin_pattern_ext(595, 150, "");
/* 開始色"白" */
p.setcolor("fill", "rgb", 1.0, 1.0, 1.0, 0.0);
/* 終了色"赤" */
sh = p.shading("axial", 0, 0, 100, 0, 1.0, 0.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"赤" */
p.setcolor("fill", "rgb", 1.0, 0.0, 0.0, 0.0);
/* 終了色"黄" */
sh = p.shading("axial", 100, 0, 200, 0, 1.0, 1.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"黄" */
p.setcolor("fill", "rgb", 1.0, 1.0, 0.0, 0.0);
/* 終了色"緑" */
sh = p.shading("axial", 200, 0, 300, 0, 0.0, 1.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"緑" */
p.setcolor("fill", "rgb", 0.0, 1.0, 0.0, 0.0);
/* 終了色"水色" */
sh = p.shading("axial", 300, 0, 400, 0, 0.0, 1.0, 1.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"水色" */
p.setcolor("fill", "rgb", 0.0, 1.0, 1.0, 0.0);
/* 終了色"青" */
sh = p.shading("axial", 400, 0, 500, 0, 0.0, 0.0, 1.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* 開始色"青" */
p.setcolor("fill", "rgb", 0.0, 0.0, 1.0, 0.0);
/* 終了色"黒" */
sh = p.shading("axial", 500, 0, 600, 0, 0.0, 0.0, 0.0, 0.0, "");
/* 塗りつぶす */
p.shfill(sh);
/* パターン定義を終了する */
p.end_pattern();
//--- 矩形を描く
/* 使用するグラデーションパターンを設定 */
p.setcolor("fill", "pattern", pattern1, 0, 0, 0);
p.rect(200, 200, 250, 250);
p.fill();
//---円を描く
/* 使用するグラデーションパターンを設定 */
p.setcolor("fill", "pattern", pattern2, 0, 0, 0);
p.circle(400, 600, 80);
p.fill();
//---テキストを出力する
/* フォントをロードする */
font = p.load_font("Helvetica-Bold", "unicode", "");
if (font == -1)
throw new Exception("Error: " + p.get_errmsg());
p.setfont(font, fontsize);
/* 使用するグラデーションパターンを設定 */
p.setcolor("fill", "pattern", pattern3, 0, 0, 0);
p.fit_textline("Hello World!", 50, 100, "");
p.fit_textline("(says PDFlib GmbH)", 200, 100 - fontsize, "");
//--- 線を描く
/* 使用するグラデーションパターンを設定 */
p.setcolor("stroke", "pattern", pattern3, 0, 0, 0);
p.moveto(30,40);
p.lineto(550,40);
p.stroke();
/* ページ終了する */
p.end_page_ext("");
/* ドキュメントを終了する */
p.end_document("");
}
catch (PDFlibException e) {
System.err.print("PDFlib exception occurred:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname()
+ ": " + e.get_errmsg() + "\n");
}
catch (Exception e) {
System.err.println(e.getMessage());
}
finally {
if (p != null) {
p.delete();
}
}
}
}