//入力PDFの取得は「PDFを開く」を参照
//ページコンテナ・ページ・ページコンテント取得は「ページコンテントを操作する」を参照
PtlParamWriteString stringParam = new PtlParamWriteString(); //文字描画用パラメータ
PtlRect outputRect = new PtlRect(left, bottom, right, top);
content.writeString(outputRect, align, textToAdd, stringParam);
// 出力PDFの保存は「PDFの保存」を参照
PtlParamWriteStringは上記以外に様々なパラメータを指定可能
PtlParamFont font = new PtlParamFont(); //フォント指定用クラス。詳細は「テキストのフォントを指定」を参照
PtlColorRGB outlineColor = new PtlColorRGB(red, green, blue);
PtlColorRGB textColor = new PtlColorRGB(red, green, blue);
stringParam.setFont(font); //フォントを設定。
stringParam.setOpacity(opacity); //不透明度を設定。
stringParam.setOutlineColor(outlineColor); //文字の縁取り色を設定。
stringParam.setTextColor(textColor); //文字色を設定。
//入力PDFの取得は「PDFを開く」を参照
//ページコンテナ・ページ・ページコンテント取得は「ページコンテントを操作する」を参照
//テキスト挿入用パラメータstringParam 取得は「ページ上にテキストを追加」を参照
PtlParamFont font = new PtlParamFont(); //フォント指定用クラス。
font.setName(fontFamily); //フォントファミリー名
font.setSize(fontSize); //フォントのサイズ(ポイント)
font.setEmbed(true); //フォント埋め込みの可否
font.setItalic(false); //イタリックか否か
//テキストの挿入は「ページ上にテキストを追加」を参照
// 出力PDFの保存は「PDFの保存」を参照
//入力PDFの取得は「PDFを開く」を参照
//ページコンテナ・ページ・ページコンテント取得は「ページコンテントを操作する」を参照
PtlRect outputRect = new PtlRect(left, bottom, right, top);
//テキストボックスの描画用パラメータ
PtlTextBox paramTextBox = content.drawTextBox(outputRect, align, width, height);
//挿入するテキスト用パラメータ
PtlParamWriteStringTextBox textParam = new PtlParamWriteStringTextBox();
paramTextBox.writeString(textToAdd, textParam); //テキストボックスへの文字列の追加
paramTextBox.terminate(); //テキストボックスのコンテントへの描画処理
// 出力PDFの保存は「PDFの保存」を参照
PtlTextBoxは上記以外に様々なパラメータを指定可能
PtlColorRGB backColor = new PtlColorRGB(red, green, blue);
PtlColorRGB outlineColor = new PtlColorRGB(red, green, blue);
textBox.fitToBBox(true); //テキストボックスのサイズを文字列のBBoxに合わせるかの設定
textBox.setBackColor(backColor); //矩形の背景色の指定
textBox.setOutlineColor(outlineColor); //矩形の縁取りの色の指定
textBox.setOpacity(opacity); //テキストボックスの不透明度
PtlParamWriteStringTextBoxもまた上記以外に様々なパラメータを指定可能
PtlParamFont font = new PtlParamFont(); //フォント指定用クラス。詳細は「テキストのフォントを指定」を参照
PtlColorRGB outlineColor = new PtlColorRGB(red, green, blue);
PtlColorRGB textColor = new PtlColorRGB(red, green, blue);
textParam.setFont(font); //パラメータにフォントを設定
textParam.setOutlineColor(outlineColor); //文字の背景色の指定
textParam.setTextColor(textColor); //文字の色指定
textParam.setOpacity(opacity); //文字の透明度の指定
textParam.setFormat(format); //文字描画の体裁
textParam.setStrikeOut(true); //打消し線の有無
textParam.setUnderline(true); //下線の有無
//入力PDFの取得は「PDFを開く」を参照
//ページコンテナ・ページ・ページコンテント取得は「ページコンテントを操作する」を参照
PtlParamInput insertImage = new PtlParamInput(imagePath); //画像のパス指定用パラメータ
PtlParamDrawImage paramDrawImage = new PtlParamDrawImage(); //出力画像描画パラメータ
PtlRect outputRect = new PtlRect(left, bottom, right, top);
paramDrawImage.setImageStream(insertImage);
content.drawImage(outputRect, PtlContent.ALIGN.ALIGN_CENTER, paramDrawImage);
// 出力PDFの保存は「PDFの保存」を参照
PtlParamDrawImageは上記以外に以下のように様々なパラメータを指定可能
paramDrawImage.setAngle(angle); //角度指定(任意の数値)
paramDrawImage.setDPI(dpi); //描画時のDPIを指定
paramDrawImage.setUseOriginalDPI(false);//画像が元々持つDPIを使うか否かの設定
paramDrawImage.setImagePageNumber(imagePageNumber); //マルチTiffだった場合のページ番号を指定
paramDrawImage.setOpacity(opacity); //透明度を指定
//描画画像にかけるソフトマスクとして画像fileSoftMaskを指定
paramDrawImage.setMaskImageStream(fileSoftMask, PtlParamDrawImage.MASK_TYPE.MASK_SOFT);
//入力PDFの取得は「PDFを開く」を参照
//ページコンテナ・ページ・ページコンテント取得は「ページコンテントを操作する」を参照
PtlParamInput insertPdf = new PtlParamInput(insertPdfPath); //挿入するPDF指定用クラス
PtlPDFDocument docToInsert = new PtlPDFDocument(); //挿入PDF用クラス
docToInsert.load(insertPdf);
PtlPages pagesToInsert = docToInsert.getPages(); //挿入するPDFのページコンテナ
PtlPage pageToInsert = pagesToInsert.get(insertPageNum); //挿入するPDFのページ
PtlParamDrawForm formInsert = new PtlParamDrawForm(); //挿入するページ描画用パラメータ
formInsert.setPage(pageToInsert);
// 出力PDFの保存は「PDFの保存」を参照
PtlParamDrawFormは以下のパラメータを指定可能
formInsert.setAngle(float angle); //任意の傾きを設定。
formInsert.setOpacity(float opacity) //不透明度を設定
//入力PDFの取得は「PDFを開く」を参照
//ページコンテナ・ページ・ページコンテント取得は「ページコンテントを操作する」を参照
PtlPoint startPoint = new PtlPoint(startX, startY);
PtlPoint endPoint = new PtlPoint(endX, endY);
PtlParamDrawShape paramDrawShape = new PtlParamDrawShape();
PtlColorDeviceRGB colorRGB = new PtlColorDeviceRGB(colorR, colorG, colorB);
paramDrawShape.setLineColor(colorRGB);
paramDrawShape.setOpacity(opacity);
content.drawLine(startPoint, endPoint, paramDrawShape);
// 出力PDFの保存は「PDFの保存」を参照
上記はページ上に線を描画した例
PtlParamDrawShapeは以下のパラメータを指定可能
PtlColorDeviceRGB colorFill = new PtlColorDeviceRGB(red, green, blue);
PtlColorDeviceRGB colorStroke = new PtlColorDeviceRGB(red, green, blue);
paramDrawShape.setFillColor(colorFill); //塗りつぶし色を設定。
paramDrawShape.setLineColor(colorStroke); //線の色を設定。
paramDrawShape.setLineStyle(lineStyle); //線スタイルを設定。
paramDrawShape.setLineWidth(lineWidth); //線幅を設定。
paramDrawShape.setOpacity(float opacity); //不透明度を設定。
また、PtlParamDrawShapeを用いて以下の図形も描画可能
PtlPoint center = new PtlPoint(startX, startY); //円の中心
content.drawCircle(center, radius, paramDrawShape); //円を描画
PtlRect rect = new PtlRect(left, bottom, right, top); //矩形の描画範囲
content.drawRect(PtlRect rectMM, PtlParamDrawShape paramDrawShape); //矩形を描画
PtlRect roundRect = new PtlRect(left, bottom, right, top); //丸角矩形の描画範囲
content.drawRoundRect(roundRect, widthRound, heightRound, paramDrawShape); //丸角矩形を描画
『PDF Tool API』の解説本『PDF CookBook』では、以下のようなプログラム例を提示しています。
・ページ上にテキストを追加
『PDF CookBook(第1巻)2.1.1 本文テキストの追加』
https://www.antenna.co.jp/ptl/cookbook/vol1/i02-0003.html
・ページ上に画像を描画
『PDF CookBook(第1巻)2.2.1 ページ上に画像を描画』
https://www.antenna.co.jp/ptl/cookbook/vol1/i03-0002.html
・画像描画の際に角度を指定する
『PDF CookBook(第5巻)5.1.1 画像を任意の角度で描画する』
https://www.antenna.co.jp/ptl/cookbook/vol5/i03-0032.html
・別PDFのページを貼り付け
『PDF CookBook(第1巻)2.3.1 PDFのページを貼り付け』
https://www.antenna.co.jp/ptl/cookbook/vol1/i05-0002.html
・ページ上に図形を描画
『PDF CookBook(第1巻)2.4.1 パスで直線の描画』
https://www.antenna.co.jp/ptl/cookbook/vol1/i05-0007.html