/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:スタンプ注釈の作成 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace AppendAnnotStamp { class Program { static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("usage: AppendAnnotStamp.exe in-pdf-file out-pdf-file スタンプ種類 [in-xxx-file]\n"); Console.WriteLine("スタンプ種類\n0 : 標準 1 : 標準2 2 : カスタム(PDF) 3 : カスタム(Image) 4 : カスタム(日付印)\n"); return; } String stampKind = args[2]; switch (stampKind) { case "0": case "1": case "2": case "3": case "4": break; default: Console.WriteLine("usage: AppendAnnotStamp.exe in-pdf-file out-pdf-file スタンプ種類 [in-xxx-file]\n"); Console.WriteLine("スタンプ種類\n0 : 標準 1 : 標準2 2 : カスタム(PDF) 3 : カスタム(Image) 4 : カスタム(日付印)\n"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) using (PtlParamOutput outputFile = new PtlParamOutput(args[1])) using (PtlPDFDocument doc = new PtlPDFDocument()) { // PDFファイルをロードします。 doc.load(inputFile); // ページコンテナの取得 using (PtlPages pages = doc.getPages()) { // ページコンテナが空かどうか if (pages.isEmpty()) { Console.WriteLine("ページコンテナが空"); return; } // 1ページ目の取得 using (PtlPage page = pages.get(0)) { // 注釈コンテナの取得 using (PtlAnnots annots = page.getAnnots()) { switch (stampKind) { case "0": // 標準 addPreDefinedStampAnnot(annots); break; case "1": // 標準2 addPreDefinedStampAnnot2(annots); break; case "2": // 読み込んだPDFを外観とするスタンプ if (args.Length < 4) { Console.WriteLine("usage: java AppendAnnotStamp in-pdf-file out-pdf-file スタンプ種類 in-pdf-file"); return; } addCustomStampAnnotFromPdf(annots, args[3]); break; case "3": // 読み込んだ画像を外観とするスタンプ if (args.Length < 4) { Console.WriteLine("usage: java AppendAnnotStamp in-pdf-file out-pdf-file スタンプ種類 in-image-file"); return; } addCustomStampAnnotFromImage(annots, args[3]); break; case "4": // 日付印を外観として描画 addCustomStampAnnotFromDrawContent(annots); break; } } } } // 別のファイルに保存します。 doc.save(outputFile); } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } static void addPreDefinedStampAnnot(PtlAnnots annots) { using (PtlAnnotStamp stampAnnot1 = new PtlAnnotStamp()) { stampAnnot1.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_APPROVED); using (PtlRect rectSize = stampAnnot1.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 270.0f, 10.0f + rectSize.getRight(), 270.0f + rectSize.getTop())) { stampAnnot1.setRect(rectAnnot); } stampAnnot1.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot1); } using (PtlAnnotStamp stampAnnot2 = new PtlAnnotStamp()) { stampAnnot2.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_AS_IS); using (PtlRect rectSize = stampAnnot2.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 250.0f, 10.0f + rectSize.getRight(), 250.0f + rectSize.getTop())) { stampAnnot2.setRect(rectAnnot); } stampAnnot2.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot2); } using (PtlAnnotStamp stampAnnot3 = new PtlAnnotStamp()) { stampAnnot3.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_CONFIDENTIAL); using (PtlRect rectSize = stampAnnot3.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 230.0f, 10.0f + rectSize.getRight(), 230.0f + rectSize.getTop())) { stampAnnot3.setRect(rectAnnot); } stampAnnot3.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot3); } using (PtlAnnotStamp stampAnnot4 = new PtlAnnotStamp()) { stampAnnot4.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_DEPARTMENTAL); using (PtlRect rectSize = stampAnnot4.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 210.0f, 10.0f + rectSize.getRight(), 210.0f + rectSize.getTop())) { stampAnnot4.setRect(rectAnnot); } stampAnnot4.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot4); } using (PtlAnnotStamp stampAnnot5 = new PtlAnnotStamp()) { stampAnnot5.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_DRAFT); using (PtlRect rectSize = stampAnnot5.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 190.0f, 10.0f + rectSize.getRight(), 190.0f + rectSize.getTop())) { stampAnnot5.setRect(rectAnnot); } stampAnnot5.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot5); } using (PtlAnnotStamp stampAnnot6 = new PtlAnnotStamp()) { stampAnnot6.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_EXPERIMENTAL); using (PtlRect rectSize = stampAnnot6.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 170.0f, 10.0f + rectSize.getRight(), 170.0f + rectSize.getTop())) { stampAnnot6.setRect(rectAnnot); } stampAnnot6.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot6); } using (PtlAnnotStamp stampAnnot7 = new PtlAnnotStamp()) { stampAnnot7.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_EXPIRED); using (PtlRect rectSize = stampAnnot7.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 150.0f, 10.0f + rectSize.getRight(), 150.0f + rectSize.getTop())) { stampAnnot7.setRect(rectAnnot); } stampAnnot7.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot7); } using (PtlAnnotStamp stampAnnot8 = new PtlAnnotStamp()) { stampAnnot8.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_FINAL); using (PtlRect rectSize = stampAnnot8.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 130.0f, 10.0f + rectSize.getRight(), 130.0f + rectSize.getTop())) { stampAnnot8.setRect(rectAnnot); } stampAnnot8.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot8); } using (PtlAnnotStamp stampAnnot9 = new PtlAnnotStamp()) { stampAnnot9.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_FOR_COMMENT); using (PtlRect rectSize = stampAnnot9.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 110.0f, 10.0f + rectSize.getRight(), 110.0f + rectSize.getTop())) { stampAnnot9.setRect(rectAnnot); } stampAnnot9.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot9); } using (PtlAnnotStamp stampAnnot10 = new PtlAnnotStamp()) { stampAnnot10.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_FOR_PUBLIC_RELEASE); using (PtlRect rectSize = stampAnnot10.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 90.0f, 10.0f + rectSize.getRight(), 90.0f + rectSize.getTop())) { stampAnnot10.setRect(rectAnnot); } stampAnnot10.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot10); } using (PtlAnnotStamp stampAnnot11 = new PtlAnnotStamp()) { stampAnnot11.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_NOT_APPROVED); using (PtlRect rectSize = stampAnnot11.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 70.0f, 10.0f + rectSize.getRight(), 70.0f + rectSize.getTop())) { stampAnnot11.setRect(rectAnnot); } stampAnnot11.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot11); } using (PtlAnnotStamp stampAnnot12 = new PtlAnnotStamp()) { stampAnnot12.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_NOT_FOR_PUBLIC_RELEASE); using (PtlRect rectSize = stampAnnot12.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 50.0f, 10.0f + rectSize.getRight(), 50.0f + rectSize.getTop())) { stampAnnot12.setRect(rectAnnot); } stampAnnot12.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot12); } using (PtlAnnotStamp stampAnnot13 = new PtlAnnotStamp()) { stampAnnot13.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SOLD); using (PtlRect rectSize = stampAnnot13.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 30.0f, 10.0f + rectSize.getRight(), 30.0f + rectSize.getTop())) { stampAnnot13.setRect(rectAnnot); } stampAnnot13.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot13); } using (PtlAnnotStamp stampAnnot14 = new PtlAnnotStamp()) { stampAnnot14.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_TOP_SECRET); using (PtlRect rectSize = stampAnnot14.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 10.0f, 10.0f + rectSize.getRight(), 10.0f + rectSize.getTop())) { stampAnnot14.setRect(rectAnnot); } stampAnnot14.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot14); } } static void addPreDefinedStampAnnot2(PtlAnnots annots) { using (PtlAnnotStamp stampAnnot1 = new PtlAnnotStamp()) { stampAnnot1.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_APPROVED); using (PtlRect rectSize = stampAnnot1.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 270.0f, 10.0f + rectSize.getRight(), 270.0f + rectSize.getTop())) { stampAnnot1.setRect(rectAnnot); } stampAnnot1.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot1); } using (PtlAnnotStamp stampAnnot2 = new PtlAnnotStamp()) { stampAnnot2.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_COMPLETED); using (PtlRect rectSize = stampAnnot2.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 250.0f, 10.0f + rectSize.getRight(), 250.0f + rectSize.getTop())) { stampAnnot2.setRect(rectAnnot); } stampAnnot2.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot2); } using (PtlAnnotStamp stampAnnot3 = new PtlAnnotStamp()) { stampAnnot3.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_CONFIDENTIAL); using (PtlRect rectSize = stampAnnot3.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 230.0f, 10.0f + rectSize.getRight(), 230.0f + rectSize.getTop())) { stampAnnot3.setRect(rectAnnot); } stampAnnot3.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot3); } using (PtlAnnotStamp stampAnnot4 = new PtlAnnotStamp()) { stampAnnot4.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_DRAFT); using (PtlRect rectSize = stampAnnot4.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 210.0f, 10.0f + rectSize.getRight(), 210.0f + rectSize.getTop())) { stampAnnot4.setRect(rectAnnot); } stampAnnot4.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot4); } using (PtlAnnotStamp stampAnnot5 = new PtlAnnotStamp()) { stampAnnot5.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_FINAL); using (PtlRect rectSize = stampAnnot5.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 190.0f, 10.0f + rectSize.getRight(), 190.0f + rectSize.getTop())) { stampAnnot5.setRect(rectAnnot); } stampAnnot5.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot5); } using (PtlAnnotStamp stampAnnot6 = new PtlAnnotStamp()) { stampAnnot6.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_FOR_COMMENT); using (PtlRect rectSize = stampAnnot6.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 170.0f, 10.0f + rectSize.getRight(), 170.0f + rectSize.getTop())) { stampAnnot6.setRect(rectAnnot); } stampAnnot6.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot6); } using (PtlAnnotStamp stampAnnot7 = new PtlAnnotStamp()) { stampAnnot7.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_FOR_PUBLIC_RELEASE); using (PtlRect rectSize = stampAnnot7.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 150.0f, 10.0f + rectSize.getRight(), 150.0f + rectSize.getTop())) { stampAnnot7.setRect(rectAnnot); } stampAnnot7.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot7); } using (PtlAnnotStamp stampAnnot8 = new PtlAnnotStamp()) { stampAnnot8.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_INFORMATIONONLY); using (PtlRect rectSize = stampAnnot8.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 130.0f, 10.0f + rectSize.getRight(), 130.0f + rectSize.getTop())) { stampAnnot8.setRect(rectAnnot); } stampAnnot8.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot8); } using (PtlAnnotStamp stampAnnot9 = new PtlAnnotStamp()) { stampAnnot9.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_NOT_APPROVED); using (PtlRect rectSize = stampAnnot9.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 110.0f, 10.0f + rectSize.getRight(), 110.0f + rectSize.getTop())) { stampAnnot9.setRect(rectAnnot); } stampAnnot9.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot9); } using (PtlAnnotStamp stampAnnot10 = new PtlAnnotStamp()) { stampAnnot10.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_NOT_FOR_PUBLIC_RELEASE); using (PtlRect rectSize = stampAnnot10.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 90.0f, 10.0f + rectSize.getRight(), 90.0f + rectSize.getTop())) { stampAnnot10.setRect(rectAnnot); } stampAnnot10.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot10); } using (PtlAnnotStamp stampAnnot11 = new PtlAnnotStamp()) { stampAnnot11.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_PRELIMINARYRESULTS); using (PtlRect rectSize = stampAnnot11.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 70.0f, 10.0f + rectSize.getRight(), 70.0f + rectSize.getTop())) { stampAnnot11.setRect(rectAnnot); } stampAnnot11.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot11); } using (PtlAnnotStamp stampAnnot12 = new PtlAnnotStamp()) { stampAnnot12.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_SB_VOID); using (PtlRect rectSize = stampAnnot12.getRect()) using (PtlRect rectAnnot = new PtlRect(10.0f, 50.0f, 10.0f + rectSize.getRight(), 50.0f + rectSize.getTop())) { stampAnnot12.setRect(rectAnnot); } stampAnnot12.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); annots.append(stampAnnot12); } } static void addCustomStampAnnotFromPdf(PtlAnnots annots, String pathPdf) { using (PtlAnnotStamp stampAnnot = new PtlAnnotStamp()) using (PtlPDFDocument doc_custom = new PtlPDFDocument()) using (PtlParamInput inputCustom = new PtlParamInput(pathPdf)) // PDFファイル { stampAnnot.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_CUSTOM); stampAnnot.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); // スタンプにするPDFファイルをロードします。 doc_custom.load(inputCustom); using (PtlPages pagesCustomStamp = doc_custom.getPages()) { // ページコンテナが空かどうか if (pagesCustomStamp.isEmpty()) { Console.WriteLine("ページコンテナが空\n"); return; } // 追加された画像ページを取得する using (PtlPage pageCustomStamp = pagesCustomStamp.get(0)) { // 画像ページを注釈に追加する stampAnnot.setPage(pageCustomStamp); using (PtlSize size = pageCustomStamp.getSize()) using (PtlRect rect = new PtlRect(10.0f, 100.0f, 10.0f + size.getWidth(), 100.0f + size.getHeight())) { stampAnnot.setRect(rect); } } } stampAnnot.setIconName("MyIcon"); annots.append(stampAnnot); } } static void addCustomStampAnnotFromImage(PtlAnnots annots, String pathImage) { using (PtlAnnotStamp stampAnnot = new PtlAnnotStamp()) { stampAnnot.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_CUSTOM); stampAnnot.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); using (PtlParamDrawImage paramDrawImage = new PtlParamDrawImage()) // 画像描画パラメータ using (PtlParamInput inputCustom = new PtlParamInput(pathImage)) // 画像ファイル using (PtlParamImagePage paramImagePage = new PtlParamImagePage()) // 画像ページパラメータ { // 画像描画パラメータに画像ファイルを設定 paramDrawImage.setImageStream(inputCustom); // 画像ページパラメータに画像描画パラメータを設定 paramImagePage.setImage(paramDrawImage); // 画像ページのサイズを画像サイズにあわせる paramImagePage.setPaperType(PtlParamImagePage.PAPER_TYPE.PAPER_IMAGE_SIZE); // 画像ページパラメータから作成したページ using (PtlPage pageCustomStamp = new PtlPage(paramImagePage)) { // 画像ページを注釈に追加する stampAnnot.setPage(pageCustomStamp); using (PtlSize size = pageCustomStamp.getSize()) using (PtlRect rect = new PtlRect(10.0f, 100.0f, 10.0f + size.getWidth(), 100.0f + size.getHeight())) { stampAnnot.setRect(rect); } } } stampAnnot.setIconName("MyIcon"); annots.append(stampAnnot); } } static void addCustomStampAnnotFromDrawContent(PtlAnnots annots) { float sizeStamp = 30.0f; using (PtlAnnotStamp stampAnnot = new PtlAnnotStamp()) using (PtlRect rect = new PtlRect(10.0f, 100.0f, 10.0f + sizeStamp, 100.0f + sizeStamp)) using (PtlPDFDocument doc_custom = new PtlPDFDocument()) { stampAnnot.setRect(rect); stampAnnot.setIconType(PtlAnnotStamp.ICON_TYPE.ICON_CUSTOM); stampAnnot.setAnnotFlags(PtlAnnot.ANNOT_FLAGS.FLAG_PRINT); using (PtlPage pageCustomStamp = new PtlPage()) // 日付印を描画する仮のページ using (PtlRect rectMedia = new PtlRect(0.0f, 0.0f, sizeStamp, sizeStamp)) using (PtlContent content = pageCustomStamp.getContent()) // 日付印を描画するコンテント { // ページサイズ pageCustomStamp.setMediaBox(rectMedia); // コンテントに日付印を描画 drawDateStamp(content, sizeStamp, "2014/09/8", "鈴木"); // 画像ページを注釈に追加する stampAnnot.setPage(pageCustomStamp); } stampAnnot.setIconName("MyIcon"); annots.append(stampAnnot); } } static void drawDateStamp(PtlContent content, float sizeStamp, String textDate, String textName) { using (PtlParamDrawShape paramDrawShape = new PtlParamDrawShape()) // スタンプの円/線を描画するパラメーター using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f)) // スタンプの色 using (PtlColorNone colorNone = new PtlColorNone()) using (PtlRect rectStamp = new PtlRect(0.0f, 0.0f, sizeStamp, sizeStamp)) { // スタンプの円/線を描画するパラメーター paramDrawShape.setLineStyle(PtlParamDrawShape.LINE_STYLE.LINE_STYLE_SOLID); paramDrawShape.setLineWidth(PtlParamDrawShape.LINE_WIDTH.LINE_WIDTH_THIN); paramDrawShape.setLineColor(color); paramDrawShape.setFillColor(colorNone); // スタンプの円を描画 content.drawCircle(rectStamp, paramDrawShape); // 円の中心から15度で線と円が交わるとする double rad = 15.0f * Math.PI / 180.0f; // 円の半径 float r = sizeStamp / 2; // 円の中心から交点へのx方向の長さ float xx = r * (float)Math.Cos(rad); // 円の中心から交点へのy方向の長さ float yy = r * (float)Math.Sin(rad); // 上線左端のx座標 float from_x = r - xx; // 上線左端のy座標 float to_x = r + xx; // 下線左端のx座標 float upper_y = r + yy; // 下線左端のy座標 float lower_y = r - yy; using (PtlPoint posFrom1 = new PtlPoint(from_x, upper_y)) using (PtlPoint posTo1 = new PtlPoint(to_x, upper_y)) using (PtlPoint posFrom2 = new PtlPoint(from_x, lower_y)) using (PtlPoint posTo2 = new PtlPoint(to_x, lower_y)) { // 円の中に上線を描画 content.drawLine(posFrom1, posTo1, paramDrawShape); // 円の中に下線を描画 content.drawLine(posFrom2, posTo2, paramDrawShape); } // 日付のフォントサイズ float fontSizeDate = sizeStamp / 2.15f; // yyyy/mm/dd を想定 using (PtlParamWriteString paramWriteStringDate = new PtlParamWriteString()) using (PtlRect rectDate = new PtlRect(from_x, lower_y, to_x, upper_y)) using (PtlParamFont font = new PtlParamFont("MS-Gothic", fontSizeDate, PtlParamFont.WEIGHT.WEIGHT_NORMAL, false, true)) { paramWriteStringDate.setFont(font); paramWriteStringDate.setTextColor(color); paramWriteStringDate.setOutlineColor(color); // 日付を描画 content.writeString(rectDate, PtlContent.ALIGN.ALIGN_CENTER, textDate, paramWriteStringDate); } // 下線から名前を描画する矩形までのマージン float margin =sizeStamp / 40.0f; // 名前のフォントサイズ float fontSizeName = sizeStamp / 1.5f; using (PtlParamWriteString paramWriteStringName = new PtlParamWriteString()) using (PtlRect rectName = new PtlRect(from_x, lower_y - (upper_y - lower_y) - margin, to_x, lower_y - margin)) using (PtlParamFont font = new PtlParamFont("MS-Mincho", fontSizeName, PtlParamFont.WEIGHT.WEIGHT_NORMAL, false, true)) { // 名前を書く矩形の高さ float heightNameBase = upper_y - lower_y; float heightName = fontSizeName * 25.4f / 72.0f; while (heightName > heightNameBase) { fontSizeName -= 0.5f; heightName = fontSizeName * 25.4f / 72.0f; } // 線の幅 float widthLine = 0.5f; // 線幅を減じた円の半径 float rr = r - widthLine; // 名前の高さのラジアン float d = (float)Math.Asin(((heightName + yy + margin) / rr)); // 名前をおさめる矩形の幅 float widthName = rr * (float)Math.Cos(d) * 2; // テキストの長さ float textWidthName = font.getStringWidth(textName); // 名前の長さによるフォントサイズの調整 while (textWidthName > widthName) { fontSizeName -= 0.5f; font.setSize(fontSizeName); textWidthName = font.getStringWidth(textName); heightName = fontSizeName * 25.4f / 72.0f; d = (float)Math.Asin((heightName + yy + margin) / rr); widthName = rr * (float)Math.Cos(d) * 2; } paramWriteStringName.setFont(font); paramWriteStringName.setTextColor(color); paramWriteStringName.setOutlineColor(color); // 名前を描画 content.writeString(rectName, PtlContent.ALIGN.ALIGN_CENTER, textName, paramWriteStringName); } } } } }