PDFに変換するときのレンダリングオプションの指定
PDF形式は固定ページ形式であり、ユーザーの間で非常に人気があり、PDF文書はどのデバイスでも同じように見えるため、さまざまなアプリケーションで広くサポー そのため、PDFへの変換はAspose.Wordsの重要な機能です。
PDFは複雑な形式です。 レイアウト計算を含む、ドキュメントをPDFに変換するプロセスでは、いくつかの段階の計算が必要です。 これらの段階には複雑な計算が含まれているため、時間がかかります。 また、PDF形式はそれ自体ではかなり複雑です。 これは、特定のファイル構造、グラフィックスモデルとフォントの埋め込みを持っています。 さらに、文書構造タグ、暗号化、デジタル署名、編集可能なフォームなど、いくつかの複雑な出力機能を備えています。
Aspose.Wordsレイアウトエンジンは、Microsoft Wordのページレイアウトエンジンの動作を模倣しています。 したがって、Aspose.WordsはPDF出力文書をMicrosoft Wordで見ることができるものにできるだけ近く見えるようにします。 追加のオプションを指定する必要がある場合がありますが、これは文書をPDF形式で保存した結果に影響を与える可能性があります。 これらのオプションは、PDF出力がどのように表示されるかを決定するプロパティを含むPdfSaveOptionsクラスを使用して指定できます。
PdfSaveOptionsの使用例をいくつか以下に示します。
現在、あなたはに保存することができますPDF 1.7, PDF 2.0, PDF/A-1a, PDF/A-1b, PDF/A-2a, PDF/A-2u, とPDF/UA-1形式。 PdfCompliance列挙体を使用して、PDF標準準拠レベルを設定します。 PDF/A形式では、出力ファイルのサイズは通常のPDFファイルのサイズよりも大きいことに注意してください。
PdfCompliance.PdfA1aとPdfCompliance.PdfA1bは廃止されたものとしてマークされています。
PDF/Aの詳細については、次の記事"PDF/Aへの変換の機能について"を参照してください。
入力可能なフォームを使用したPDFドキュメントの作成
入力可能なフォームをMicrosoft Wordドキュメントから出力PDFにエクスポートすることもできます。 入力可能なフォームで文書をPDFとして保存するには、PreserveFormFieldsプロパティを使用します。
Microsoft Wordとは対照的に、PDF形式には、textbox、combo box、checkboxなどの編集可能なフォームのオプションの数が限られていることに注意してください。 Microsoft Wordには、カレンダーの日付ピッカーなど、より多くの種類のフォームがあります。 一般に、PDFでMicrosoft Wordの動作を完全に模倣することはできません。 したがって、いくつかの複雑なケースでは、PDFの出力はMicrosoft Wordに表示されるものと異なる場合があります。
次のコード例は、指定されたJpeg圧縮と品質で入力可能なフォームを使用して文書をPDFとして保存する方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(dataDir + "SaveOptions.PdfImageCompression.rtf"); | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setImageCompression(PdfImageCompression.JPEG); | |
options.setPreserveFormFields(true); | |
doc.save(dataDir + "SaveOptions.PdfImageCompression.pdf", options); | |
PdfSaveOptions options17 = new PdfSaveOptions(); | |
options17.setCompliance(PdfCompliance.PDF_17); | |
options17.setImageCompression(PdfImageCompression.JPEG); | |
options17.setJpegQuality(100);// Use JPEG compression at 50% quality to reduce file size | |
options17.setImageColorSpaceExportMode(PdfImageColorSpaceExportMode.SIMPLE_CMYK); | |
doc.save(dataDir + "SaveOptions.PdfImageComppression_17.pdf", options17); |
ドキュメント構造とカスタムプロパティのエクスポート
ExportDocumentStructureプロパティを使用すると、文書構造をPDF出力にエクスポートできます。
PDF論理構造ファシリティは、文書の内容構造に関する情報をPDFファイルに組み込むためのメカニズムを提供します。 Aspose.Wordsは、段落、リスト、表、脚注/文末脚注など、Microsoft Word文書からの構造に関する情報を保持します。Aspose.Wordsは、段落、リスト、表、脚注/文末脚注など、Microsoft Word文書からの構造に関する情報を保
次の例では、ドキュメントをPDF形式で保存し、ドキュメントの構造を保持する方法を示します:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// For complete examples and data files, please go to // | |
// https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a document | |
Document doc = new Document(dataDir + "Paragraphs.docx"); | |
// Create a PdfSaveOptions object and configure it to preserve the logical | |
// structure that's in the input document | |
// The file size will be increased and the structure will be visible in the | |
// "Content" navigation pane | |
// of Adobe Acrobat Pro, while editing the .pdf | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setExportDocumentStructure(true); | |
doc.save(dataDir + "PdfSaveOptions.ExportDocumentStructure.pdf", options); |
Aspose.Wordsでは、ドキュメントのカスタムプロパティをPDFにエクスポートすることもできます。:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// For complete examples and data files, please go to // | |
// https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a document | |
Document doc = new Document(); | |
// Add a custom document property that doesn't use the name of some built in | |
// properties | |
doc.getCustomDocumentProperties().add("Company", "My value"); | |
// Configure the PdfSaveOptions like this will display the properties | |
// in the "Document Properties" menu of Adobe Acrobat Pro | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setCustomPropertiesExport(PdfCustomPropertiesExport.STANDARD); | |
doc.save(dataDir + "PdfSaveOptions.CustomPropertiesExport.pdf", options); |
出力PDFのブックマークと見出しからアウトラインをエクスポートする
出力PDFでブックマークをアウトラインとしてエクスポートする場合は、DefaultBookmarksOutlineLevelプロパティを使用できます。 このプロパティは、Microsoft Wordブックマークが表示されるドキュメントアウトラインの既定のレベルを指定します。 ドキュメントのヘッダー/フッターにブックマークが含まれている場合は、HeaderFooterBookmarksExportModeプロパティをFirstまたはAllに設定して、出力PDFでエクスポートする方法を指定できます。 HeaderFooterBookmarksExportModeの値がNoneの場合、ヘッダー/フッターのブックマークはエクスポートされません。
以下のコード例は、セクションの最初のヘッダー/フッターからブックマークをエクスポートする方法を示しています:
この例の出力PDFを以下に示します:
HeaderFooterBookmarksExportModeがFirstに設定されていて、ドキュメントに偶数と奇数のヘッダー/フッター、または異なる最初のページのヘッダー/フッターがある場合、セクション内の最初の一意のヘッダー/フッターのブックマークがエクスポートされます。
HeadingsOutlineLevelsプロパティを使用して、出力PDFの見出しをエクスポートすることもできます。 このプロパティは、ドキュメントアウトラインに含まれる見出しのレベルの数を指定します。
次のコード例は、3つのレベルの見出しをエクスポートする方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// For complete examples and data files, please go to // | |
// https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a document | |
Document doc = new Document(dataDir + "Rendering.doc"); | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.getOutlineOptions().setHeadingsOutlineLevels(3); | |
options.getOutlineOptions().setExpandedOutlineLevels(1); | |
doc.save(dataDir + "Rendering.SaveToPdfWithOutline.pdf", options); |
この例の出力PDFを以下に示します:
ドキュメントサイズを縮小するための画像のダウンサンプリング
Aspose.Wordsは、DownsampleOptionsプロパティを使用して、出力PDFサイズを小さくするために画像をダウンサンプリングする機能を提供します。 ダウンサンプリングは、DownsampleImagesプロパティで既定で有効になっています。
Resolutionプロパティに特定の解像度を設定したり、ResolutionThresholdプロパティに解像度のしきい値を設定したりすることもできます。 2番目のケースでは、画像の解像度がしきい値より小さい場合、ダウンサンプリングは適用されません。
次のコード例は、出力PDFドキュメント内の画像の解像度を変更する方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// For complete examples and data files, please go to // | |
// https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a document | |
Document doc = new Document(dataDir + "Rendering.doc"); | |
// If we want to convert the document to .pdf, we can use a SaveOptions | |
// implementation to customize the saving process | |
PdfSaveOptions options = new PdfSaveOptions(); | |
// We can set the output resolution to a different value | |
// The first two images in the input document will be affected by this | |
options.getDownsampleOptions().setResolution(36); | |
// We can set a minimum threshold for downsampling | |
// This value will prevent the second image in the input document from being | |
// downsampled | |
options.getDownsampleOptions().setResolutionThreshold(128); | |
doc.save(dataDir + "PdfSaveOptions.DownsampleOptions.pdf", options); |
解像度は、ページ上の実際の画像サイズに応じて計算されます。
AdobePDF形式でフォントを埋め込む
Aspose.Wordsを使用すると、結果のPDFドキュメントにフォントを埋め込む方法を制御することもできます。 フォントは、任意のマシンでドキュメントを正しくレンダリングできるようにするために、AdobePDFドキュメントに埋め込む必要があります(フォントレンダ TrueTypeフォントの使用). デフォルトでは、Aspose.Wordsはドキュメントで使用されるフォントのサブセットを生成されたPDFに埋め込みます。 この場合、文書で使用されているグリフ(文字)のみがPDFに保存されます。
フルフォントを使用する場合とサブセット化する場合
完全なフォントを埋め込むためのAspose.Wordsのオプションを指定する方法があります。 さらなる詳細は、各設定のいくつかの利点および欠点とともに、以下の表に記載されている。
埋め込みフォントモード | 利点 | デメリット |
---|---|---|
Full |
テキストを追加または変更して、結果のPDFを後で編集する場合に便利です。 すべてのフォントが含まれているため、すべてのグリフが存在します。 | 一部のフォントは大きい(数メガバイト)ため、サブセットなしで埋め込むと、出力ファイルが大きくなる可能性があります。 |
Subset |
サブセットは、出力ファイルのサイズを小さくしたい場合に便利です。 | ユーザーは、出力PDFドキュメント内のサブセットされたフォントを使用してテキストを完全に追加または編集することはできません。 これは、フォントのすべてのグリフが存在するわけではないためです。 複数のPDFsがサブセットされたフォントで保存され、一緒に組み立てられた場合、結合されたPDF文書には多くの不要なサブセットを含むフォントが含まれている可能性があります。 |
PDFにフルフォントを埋め込む
EmbedFullFontsプロパティを使用すると、Aspose.Wordsが出力PDFドキュメントにフォントを埋め込む方法を指定できます。
- 出力PDFドキュメントに完全なフォントを埋め込むには、EmbedFullFontsをtrueに設定します
- PDFに保存するときにフォントをサブセット化するには、EmbedFullFontsをfalseに設定します
次の例は、出力PDFドキュメントに完全なフォントを埋め込む方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a Document | |
Document doc = new Document(dataDir + "Rendering.doc"); | |
// Aspose.Words embeds full fonts by default when EmbedFullFonts is set to true. | |
// The property below can be changed | |
// Each time a document is rendered. | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setEmbedFullFonts(true); | |
String outPath = dataDir + "Rendering.EmbedFullFonts_out.pdf"; | |
// The output PDF will be embedded with all fonts found in the document. | |
doc.save(outPath, options); |
次の例では、出力PDFのフォントをサブセット化するためにAspose.Wordsを設定する方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a Document | |
Document doc = new Document(dataDir + "Rendering.doc"); | |
// To subset fonts in the output PDF document, simply create new PdfSaveOptions | |
// and set EmbedFullFonts to false. | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setEmbedFullFonts(false); | |
dataDir = dataDir + "Rendering.SubsetFonts_out.pdf"; | |
// The output PDF will contain subsets of the fonts in the document. Only the | |
// glyphs used | |
// In the document are included in the PDF fonts. | |
doc.save(dataDir, options); |
コアフォントとWindows標準フォントの埋め込みを制御する方法
コアフォントとWindows標準フォントは"標準"フォントのセットであり、通常はターゲットマシン上に存在するか、ドキュメントリーダーによって提供されるため、出力PDFに埋め込む必要はありません。 これらのフォントを埋め込んでいないことで、レンダリングされたPDFドキュメントのサイズを小さくし、移植性を維持できます。
Aspose.Words には、フォントを PDF にエクスポートする方法を選択するオプションがあります。出力 PDF にコア フォントと標準フォントを埋め込むか、埋め込みをスキップして代わりにターゲット マシン上の標準コア PDF フォントまたはシステム フォントを使用するかを選択できます。これらのオプションのいずれかを使用すると、通常、Aspose.Words によって生成される PDF ドキュメントのファイル サイズが大幅に削減されます。
- これらのオプションは相互に排他的であるため、一度に1つだけ選択する必要があります。
- PDF/A-1準拠で保存する場合は、使用されるすべてのフォントをPDFドキュメントに埋め込む必要があります。 この準拠で保存する場合は、UseCoreFontsプロパティをfalseに設定し、FontEmbeddingModeプロパティをEmbedAll.に設定する必要があります
コアフォントの埋め込み
コアフォントを埋め込むオプションは、UseCoreFontsプロパティを使用して有効または無効にできます。 Trueに設定されている場合、次の最も一般的な"True Type"フォント(ベース14フォント)は出力PDFドキュメントに埋め込まれません:
Arial
Times New Roman
Courier New
Symbol
これらのフォントは、PDFが開かれたときにリーダーによって提供される対応するコアタイプ1フォントに置き換えられます。
以下に示す例は、コアフォントの埋め込みを回避し、読者がそれらをPDFタイプ1フォントで置き換えるようにAspose.Wordsを設定する方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a Document | |
Document doc = new Document(dataDir + "Rendering.doc"); | |
// To disable embedding of core fonts and subsuite PDF type 1 fonts set | |
// UseCoreFonts to true. | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setUseCoreFonts(true); | |
String outPath = dataDir + "Rendering.DisableEmbedWindowsFonts_out.pdf"; | |
// The output PDF will not be embedded with core fonts such as Arial, Times New | |
// Roman etc. | |
doc.save(outPath); |
PDFビューアはサポートされている任意のプラットフォームでコアフォントを提供するため、このオプションはドキュメントの移植性を高める必要がある場合にも役立ちます。 ただし、コアフォントはシステムフォントとは異なる場合があります。
システムフォントの埋め込み
このオプションはFontEmbeddingModeプロパティを使用して有効または無効にすることができます。 このプロパティがEmbedNonstandardに設定されている場合、“Arial"および"Times New Roman"true typeフォントはPDFドキュメントに埋め込まれません。 この場合、クライアントビューアはクライアントオペレーティングシステムにインストールされているフォントに依存します。 FontEmbeddingModeプロパティがEmbedNoneに設定されている場合、Aspose.Wordsはフォントを埋め込みません。
以下の例は、Aspose.Wordsを設定してArialフォントとTimes New RomanフォントをPDF文書に埋め込むのをスキップする方法を示しています:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a Document | |
Document doc = new Document(dataDir + "Rendering.doc"); | |
// To disable embedding standard windows font use the PdfSaveOptions and set the | |
// EmbedStandardWindowsFonts property to false. | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setFontEmbeddingMode(PdfFontEmbeddingMode.EMBED_NONE); | |
// The output PDF will be saved without embedding standard windows fonts. | |
doc.save(dataDir + "Rendering.DisableEmbedWindowsFonts.pdf"); |
このモードは、出力PDF内のフォントの正確な外観を維持しながら、同じプラットフォーム上でドキュメントを表示する場合に最も便利です。