一つ以上の単一ページ(または複数ページ)のPNG,JPEG,TIFFなどの画像をPDFに変換します。
画像の圧縮レベル、画像品質、解像度を選択して、PDFに変換する際の処理方法を指定できます。
ページ サイズ、領域、拡大縮小、画像の位置と方向など、出力PDFの書式を選択できます。
出力となるPDF準拠レベルを指定できます。属性、権限、代替テキストなどのドキュメント形式を追加指定できます。
APIリファレンスはこちらです。(すべて英文)
入力ファイルの規格 | 出力ファイルの規格 | BMP, GIF, JBIG2, JPEG, JPEG2000, JPEG-LS, PBM, PNG, TIFF, LZW, CCITT | PDF 1.x, PDF 2.0, PDF/A-1, PF/A-1b, PDF/A-2, PDF/A-2b, PDF/A-2u, PDF/A-3, PDF/A-3b, PDF/A-3u |
---|
画像処理
ページ・レイアウト
PDF指定
C#のサンプルプロジェクトではPdftools SDKライブラリ(DLL)をNuGetから自動でダウンロードします。
CのサンプルプロジェクトにはPdftools SDKライブラリ(DLL)が含まれています。
ライセンスキー無し(無償)で試用できます。ただし、結果に「透かし」が入ります。
「透かし」の削除をご希望の場合は問い合わせページまたはメールでお問い合わせください。
License Agreement(利用許諾契約書)が含まれていますので必ず確認してください。
画像をPDF文書に変換します。
ここでは変換プロファイルのデフォルト設定が使用されています。
変換プロファイルは画像の各ページをA4サイズ縦向きページに配置し各辺の余白2cmにします。
// 入力画像ファイルを開く pInStream = _tfopen(szInPath, _T("rb")); GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pInStream, _T("Failed to open the input file \"%s\" for reading.\n"), szInPath); TPdfToolsSys_StreamDescriptor inDesc; PdfToolsSysCreateFILEStreamDescriptor(&inDesc, pInStream, 0); pInDoc = PdfToolsImage_Document_Open(&inDesc); GOTO_CLEANUP_IF_NULL_PRINT_ERROR( pInDoc, _T("Failed to create a document from the input file \"%s\". %s (ErrorCode: 0x%08x).\n"), szInPath, szErrorBuff, PdfTools_GetLastError()); // 書き込み用の出力ストリームを生成 pOutStream = _tfopen(szOutPath, _T("wb+")); GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutStream, _T("Failed to open the output file \"%s\" for writing.\n"), szOutPath); TPdfToolsSys_StreamDescriptor outDesc; PdfToolsSysCreateFILEStreamDescriptor(&outDesc, pOutStream, 0); // 変換パラメータを定義するプロファイルを生成 // 既定のプロファイルは画像をPDF文書に変換します pProfile = (TPdfToolsImage2PdfProfiles_Profile*)PdfToolsImage2PdfProfiles_Default_New(); // 画像をPDF文書に変換 pConverter = PdfToolsImage2Pdf_Converter_New(); pOutDoc = (TPdfToolsPdf_Document*)PdfToolsImage2Pdf_Converter_Convert(pConverter, pInDoc, &outDesc, pProfile, NULL); GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutDoc, _T("The processing has failed. (ErrorCode: 0x%08x).\n"), PdfTools_GetLastError());
private static void Image2Pdf(string inPath, string outPath) { // 入力画像ファイルを開く using var inStr = File.OpenRead(inPath); using var inDoc = Document.Open(inStr); // 変換パラメータを定義するプロファイルを生成 // 既定のプロファイルは画像をPDF文書に変換します var profile = new Profiles.Default(); // オプションで:変換プロセスの要件に応じてプロファイルのパラメータを変更できます // 出力ストリームを生成 using var outStr = File.Create(outPath); // 画像をPDF文書に変換 using var outDoc = new Converter().Convert(inDoc, outStr, profile); }
def convert_image_to_pdf(input_path: str, output_path: str): # 入力画像ファイルを開く with io.FileIO(input_path, 'rb') as in_stream: with Document.open(in_stream) as input_document: # 変換パラメータを定義するプロファイルを生成 (既定のプロファイル) # 既定のプロファイルは画像をPDF文書に変換します profile = Default() # オプションで:変換プロセスの要件に応じてプロファイルのパラメータを変更できます # 出力ストリームを生成 with io.FileIO(output_path, 'wb+') as output_stream: # 画像をPDF文書に変換 converter = Converter() converter.convert(input_document, output_stream, profile)
# オプションで: 以下のようにプロキシを指定できます # Sdk.set_proxy("http://myproxy:8080") convert_image_to_pdf(input_path, output_path)
画像をアクセシブルなPDF/A-2a文書に変換します。
PDF/AレベルAの要件に従って画像に代替テキストを追加します。
このことで、支援技術を使用する障害のある方にもアクセシビリティを確保するサンプルです。
private static void Image2Pdf(string inPath, string alternateText, string outPath) { // 画像ファイルをオープン using var inStr = File.OpenRead(inPath); using var inDoc = Document.Open(inStr); // 変換パラメータを定義するプロファイルを作成 // Archiveプロファイルは、アーカイブ用に画像を PDF/A ドキュメントに変換します。 var profile = new Profiles.Archive(); // 出力ドキュメントの準拠をPDF/A-2aに設定 profile.Conformance = new Conformance(2, Conformance.PdfALevel.A); // PDF/AレベルAの場合は画像の各ページに代替テキストが必要 // これは他のPDF/A(PDF/A-2bなど)レベルではオプションです profile.Language = "en"; profile.AlternateText.Add(alternateText); // オプションで:変換プロセスの要件に応じて他のプロファイル パラメータを変更することもできます。 // 出力ストリームを生成 using var outStr = File.Create(outPath); // 画像をタグ付きPDF/Aドキュメントに変換 using var outDoc = new Converter().Convert(inDoc, outStr, profile); }
def image_to_pdf(input_path: str, alternate_text: str, output_path: str): # 画像ファイルをオープン with io.FileIO(input_path, 'rb') as image_stream: with Document.open(image_stream) as image_document: # 変換パラメータを定義するプロファイルを作成 # Archiveプロファイルは、アーカイブ用に画像を PDF/A ドキュメントに変換します。 profile = Archive() # 出力ドキュメントの準拠をPDF/A-2aに設定 profile.conformance = Conformance.PDF_A2_A # PDF/AレベルAの場合は画像の各ページに代替テキストが必要 # これは他のPDF/A(PDF/A-2bなど)レベルではオプションです profile.language = "en" profile.alternate_text.append(alternate_text) # オプションで、変換プロセスの要件に応じて他のプロファイル パラメータを変更することもできます。 # 出力ストリームを生成 with io.FileIO(output_path, 'wb+') as output_stream: # 画像をタグ付きPDF/Aドキュメントに変換 converter = Converter() converter.convert(image_document, output_stream, profile)
image_to_pdf(input_path, alternate_text, output_path)
複数の画像をPDF文書に変換します。
画像リストを単一のPDFに変換します。
サポートされている画像形式は、TIFF、JPEG、BMP、GIF、PNG、JBIG2、JPEG2000です。
private static void Images2Pdf(IEnumerableinPaths, string outPath) { var streams = new List (); var images = new DocumentList(); try { // 入力画像を開いてリストに保存 foreach (var inPath in inPaths) { var stream = File.OpenRead(inPath); streams.Add(stream); images.Add(Document.Open(stream)); } // 変換パラメータを定義するプロファイルを生成 var profile = new Profiles.Default(); // オプションで:変換プロセスの要件に応じてプロファイルのパラメータを変更できます。 // 出力ストリームを生成 using var outStream = File.Create(outPath); using var outPdf = new Converter().ConvertMultiple(images, outStream, profile); } finally { foreach (var image in images) image.Dispose(); foreach (var stream in streams) stream.Dispose(); } }
def images_to_pdf(input_image_paths: list[str], output_file_path: str): try: stream_list = [] images = ImageDocumentList() # 入力画像を開いてリストに保存 for input_image_path in input_image_paths: image_stream = io.FileIO(input_image_path, 'rb') stream_list.append(image_stream) images.append(ImageDocument.open(image_stream)) # 変換パラメータを定義するプロファイルを生成 profile = Default() # オプションで:変換プロセスの要件に応じてプロファイルのパラメータを変更できます。 # 出力ストリームを生成 with io.FileIO(output_file_path, 'wb+') as output_stream: converter = Converter() converter.convert_multiple(images, output_stream, profile) finally: if 'images' in locals(): for image in images: image.__exit__(None, None, None) if 'stream_list' in locals(): for stream in stream_list: stream.__exit__(None, None, None)
images_to_pdf(input_image_paths, output_file_path)
他の機能サンプルを参照してください。
質問のページからお送りいただくようお願いします。
または、メールでsupport@trustss.co.jpあてにお送りください。
ご購入前の技術的質問も無償で対応します。サポート受付ページからお願いします。