トップページ > システム製品情報 > PDF Driver API 製品トップ > サンプル集 > 入出力ファイルを指定する(C#)
サンプルコードの仕様概要
サンプルアプリケーションの実行
ダウンロード
/* Antenna House PDF Driver API V6.0 .NET Interface sample program 概要:入出力ファイルと設定ファイルを指定し設定を変更して保存後にPDF出力を行う Copyright 2016 Antenna House, Inc. */ using System; using System.Windows.Forms; using PdfDrvNet4_60; namespace sample01_cs { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //[PtlDrvConvert::convertFile()]ボタン //PDF出力を実行する private void button1_Click(object sender, EventArgs e) { textBox3.Text += "変換開始:" + textBox1.Text + " -> " + textBox2.Text + Environment.NewLine; //変換クラスを作成する。 PtlDrvConvert conv = new PtlDrvConvert(); PtlParamDriverSettings param = new PtlParamDriverSettings(); try { //設定ファイルが選択されていたら読み込む。 if (listView1.SelectedItems.Count > 0) { string fn = listView1.SelectedItems[0].SubItems[2].Text; param.load(fn); textBox3.Text += "設定ファイル:" + fn + Environment.NewLine; } else { textBox3.Text += "設定ファイルが選択されていません。" + Environment.NewLine; return; } //一般タブ設定 PtlParamCommonSettings common = new PtlParamCommonSettings(param.ParamCommonSettings); common.ViewAuto = false; //false = 作成後PDFを表示しない //PDFバージョンタブ設定 PtlParamPDFVersionSettings pdfver = new PtlParamPDFVersionSettings(param.ParamPDFVersionSettings); pdfver.PdfVersion = PtlParamPDFVersionSettings.Pdf17; //圧縮タブ設定 PtlParamCompressSettings compress = new PtlParamCompressSettings(param.ParamCompressSettings); //カラー compress.ColorImageAboveValue = 400; compress.ColorImageToValue = 150; compress.ColorImageMethod = PtlParamCompressSettings.Bilinear; compress.ColorImageCompression = PtlParamCompressSettings.Jpeg; compress.ColorImageQuality = PtlParamCompressSettings.HighQuality; //グレー compress.GlayScaleImageAboveValue = 400; compress.GlayScaleImageToValue = 300; compress.GlayScaleImageMethod = PtlParamCompressSettings.Bicubic; compress.GlayScaleImageCompression = PtlParamCompressSettings.Zlib; //compress.GlayScaleImageQuality = ;//zlibなので圧縮画質設定なし。 //モノクロ compress.MonochromeImageAboveValue = 400; compress.MonochromeImageToValue = 300; compress.MonochromeImageMethod = PtlParamCompressSettings.Bicubic; compress.MonochromeImageCompression = PtlParamCompressSettings.CCITT4; //その他 compress.CompressTextAndLineArt = true; compress.CompressObjectLevel = true; compress.ASCIIFormat = true; //フォント設定タブ PtlParamFontSettings font = new PtlParamFontSettings(param.ParamFontSettings); font.clearEmbedFont(); font.addEmbedFontName("MS 明朝"); font.addEmbedFontName("MS ゴシック"); font.CantEmbedFontStyle = PtlParamFontSettings.ContinueWithoutUnembeddableFont; font.EmbedFontStyle = PtlParamFontSettings.SelectedFont; font.EmbedBase14 = false; //セキュリティ設定タブ PtlParamSecuritySettings security = new PtlParamSecuritySettings(param.ParamSecuritySettings); security.UserPassword = ""; security.OwnerPassword = "owner"; //PDF1.4~ security.PDF14CopyContentFlag = false; security.PDF14TextAccessFlag = true; security.PDF14EditAllow = PtlParamSecuritySettings.EditPermissonCommentFillFormAndSign; security.PDF14PrintAllow = PtlParamSecuritySettings.PrintPermissionLowResolution; //256bit AESで暗号化する // → PtlParamPDFVersionSettingsのPdfVersionに「Pdf17」を設定する必要がある。 security.SecurityLevel = PtlParamSecuritySettings.AES256; //透かし設定タブ PtlParamWaterMarkSettings wm = new PtlParamWaterMarkSettings(param.ParamWaterMarkSettings); //テキスト透かし wm.WaterMarkType = PtlParamWaterMarkSettings.TypeText; wm.TextString = "透かしサンプル"; wm.TextFont = "MS ゴシック"; wm.TextFontSize = 50; wm.TextColorR = 255; wm.TextColorG = 10; wm.TextColorB = 40; wm.TextDiagonal = false; //画像・テキスト 共通設定 wm.LayoutHorizontal = PtlParamWaterMarkSettings.HorizontalCenter; wm.LayoutVertical = PtlParamWaterMarkSettings.VerticalCenter; wm.Place = PtlParamWaterMarkSettings.Front; wm.Transparence = 40; wm.DisplayShow = true;//表示する。 wm.PrintShow = false;//印刷しない。 //開き方 PtlParamOpenModeSettings om = new PtlParamOpenModeSettings(param.ParamOpenModeSettings); om.PageLayoutType = PtlParamOpenModeSettings.ContinuousSingle; //1ページ連続 om.TextDirection = PtlParamOpenModeSettings.LeftToRight; om.StartNumber = 1; om.PageAdjust = PtlParamOpenModeSettings.FitToWidth; om.PageMode = PtlParamOpenModeSettings.PageOnly; //情報タブ設定 PtlParamInformationSettings info = new PtlParamInformationSettings(param.ParamInformationSettings); info.Title = "たいとる"; info.SubTitle = "さぶたいとる"; info.Author = "さくせいしゃ"; info.Keyword = "きーわーど"; info.Creator = "くりえいた"; info.Comment = "こめんと"; //個別に編集したものをparamに適用する。 param.ParamCommonSettings = common; param.ParamPDFVersionSettings = pdfver; param.ParamCompressSettings = compress; param.ParamFontSettings = font; param.ParamSecuritySettings = security; param.ParamWaterMarkSettings = wm; param.ParamOpenModeSettings = om; param.ParamInformationSettings = info; //設定の表示名 param.SettingName = "C#サンプル"; //設定をファイルに保存する。 int re; re = param.saveAs(textBox4.Text); if (re != 0) { textBox3.Text += "設定ファイルの保存に失敗:err=" + re.ToString() + Environment.NewLine; return; } //編集した印刷設定を適用する。 conv.ParamSettings = param; //編集した設定値をParamSettingsにセットしてconvertFileする場合は、必ずByAPIをセットする。 //またこのケースでは、toDriver()を行ってはならない。 conv.SelectSettings = PtlDrvConvert.ByAPI; /* //** 上2行の代わりに↓の様にしても良い。 //編集した設定をドライバに送る。 param.toDriver(); //toDriver()で設定値をドライバに送りconvertFileする場合は、必ずUseCurrentSettingをセットする conv.SelectSettings = PtlDrvConvert.UseCurrentSetting; */ //変換。Word/Excel/PowerPoint/一太郎はCOMで印刷。TXTはWord使用。 bool ret = conv.convertFile(textBox1.Text, textBox2.Text); if (ret) { textBox3.Text += "成功。"; } else { textBox3.Text += "失敗。"; } } catch (PtlDrvException ex) { textBox3.Text += "例外:PtlDrvException:errorcode=" + ex.ErrorCode.ToString() + ":" + ex.ErrorMessageJP; } catch (Exception ex) { textBox3.Text += "例外:その他:" + ex.ToString(); } finally { //明示的に破棄する。 param.Dispose(); conv.Dispose(); } textBox3.Text += Environment.NewLine; } } }