Leadtools.Forms.DocumentWriters名前空間 :PdfDocumentOptionsクラス |
[DataContractAttribute()] [SerializableAttribute()] public class PdfDocumentOptions : DocumentOptions
'Declaration
<DataContractAttribute()> <SerializableAttribute()> Public Class PdfDocumentOptions Inherits DocumentOptions
'Usage
Dim instance As PdfDocumentOptions
public sealed class PdfDocumentOptions : DocumentOptions
@interface LTPdfDocumentOptions : LTDocumentOptions <NSCopying, NSCoding>
public class PdfDocumentOptions extends DocumentOptions
function Leadtools.Forms.DocumentWriters.PdfDocumentOptions()
[DataContractAttribute()] [SerializableAttribute()] public ref class PdfDocumentOptions : public DocumentOptions
ユーザーがDocumentFormat.Pdf形式を用いてドキュメントを保存するとき、PdfDocumentOptionsクラスで設定されるオプションが使われます。
PDF文書を作成するためにLEADTOOLSドキュメントライタを使用する前に、ドキュメントライタがLEADTOOLS OCRエンジンから使われない限り、RasterSupportType.DocumentWritersPdfキーをロック解除しなければなりません。詳細については、「特殊なLEAD機能のアンロック」を参照してください。
PDF形式で使われるオプションを変更して、以下の手順を実行すること:
PdfDocumentOptionsクラスは、以下の機能を格納します:
機能 | 説明 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PDFドキュメントタイプをPDFまたはPDF/Aに設定します。 | ドキュメントタイプをPDFかPDF/Aに設定するために、PdfDocumentOptions.DocumentTypeプロパティを使います。 | ||||||||||||||||||||
フォント埋め込みモードを制御します | フォントがどのように結果として生じるPDF文書に埋められるかについて制御するために、PdfDocumentOptions.FontEmbedModeプロパティを使います。PDF/Aファイルを保存するとき、PdfDocumentOptions.FontEmbedModeが使われないことに注意すべきです;すべてのフォントは、常にファイルに埋められます。 | ||||||||||||||||||||
PDFコンテンツの上のオーバレイとして、imageを追加します。 | PDFコンテンツの上のオーバレイとしてオリジナルのラスター画像を追加するために、PdfDocumentOptions.ImageOverTextプロパティを使います。結果として生じるドキュメントは、正確にオリジナルドキュメントのように見えます。このオプションが使われるならば、オーバレイimageはDocumentWriter.AddPageメソッドに渡されるDocumentPageオブジェクトのimageプロパティで設定されなければなりません。このimageの品質を制御するために、ImageOverTextSizeとImageOverTextModeプロパティを使います。 | ||||||||||||||||||||
高速ウェブ表示のために最適化される線形化PDF文書を作成します。 | 線形化PDFファイルは、ネットワーク環境で効果的な漸進的なアクセスを有効にする特別な方法にまとめられたファイルです。ファイル全体がウェブサーバからダウンロードされる前に、これはPDFファイルの最初のページをユーザーウェブブラウザで表示させられます。線形化PDF文書の作成を有効にするために、PdfDocumentOptions.Linearizedプロパティを使います。PDFリニアライズは、PDFとPDF/A形式でサポートされます。 | ||||||||||||||||||||
PDF文書メタデータを設定します | ドキュメントに関連づけられる結果として生じるPDF缶封じ込め任意メタデータ。このメタデータは、検索して、PDF文書を分類するために、外部の検索とインデクシングエンジンにより用いられることがありえます。ドキュメントメタデータを設定するために、PdfDocumentOptions.Title、PdfDocumentOptions.Subject、PdfDocumentOptions.AuthorとPdfDocumentOptions.Keywordsを使います。 | ||||||||||||||||||||
PDF最初のビュープロパティを設定します |
ユーザーは、以下のように生成されるPDFファイルのintialなビュープロパティを制御することができます:
|
||||||||||||||||||||
セキュリティ、アクセス権と暗号化 |
PDF文書は、2つのメソッドを用いて保護されていることができます(確保される):
PDF文書が編集(オーナーパスワードを用いることにより)から保護されているとき、暗号化レベルとオーナーアクセス権は結果として生じるドキュメントで与えられることができるか、否定されることができます。以下のテーブルは、LEADTOOLSドキュメントライタでサポートされるPDFアクセス権をリストします:
|
||||||||||||||||||||
addは、最終的なPDF文書でブックマークします。 | 最終的なPDF文書で自動であるかカスタム(ユーザー)ブックマークを作成するために、PdfAutoBookmarkまたはPdfCustomBookmarkを使います。 | ||||||||||||||||||||
アノテーションオブジェクトを追加することによって、アノテーション対象となるPDF文書を作成します。 | PDF文書内の注釈を付けるページごとに有効なLEADTOOLSアノテーションコンテナーを渡して、注釈付きPDFを作成できます。DocumentWriter.AddPagemethodを呼び出す前に、AnnotationContainerプロパティを有効なLEADTOOLSアノテーションコンテナに設定します。 |
次の表に、PDFファイルをアーカイブするために、許容できる品質を維持しながら出力ファイルサイズを最小限に抑えるPDF文書オプションの推奨値を示します。
プロパティ |
値 |
解説 |
---|---|---|
JBIG2形式は、最善1ビット画像圧縮を提供します。 |
||
カラー画像の圧縮(8ビットまたは24ビット)にはJPXが最も適しています。imageが8または24以外のピクセル当たりビット値を持っているならば、flate圧縮に戻ります。 |
||
テキストの上に画像を重ねるオプションを使用するとき(ImageOverTextがtrueのとき)にのみ使用されます。オーバーレイ画像のサイズが半分になり、ページを覆うように画像が引き伸ばされます。これにより、画質を維持しながらサイズを最大75%節約できます。 |
||
テキストの上に画像を重ねるオプションを使用するとき(ImageOverTextがtrueのとき)にのみ使用されます。任意のグレースケールオーバレイimageは、ノイズとシャドウを無視している間、白黒に変換されます。 |
||
50または100 |
テキストオプション(ImageOverTextはtrueです)にかかっているimageを使うとき、50を使います。テキストにかかっているimageが使われない(ImageOverTextはfalseです)とき、100を使います。 |
|
PDFファイルでフォントを埋め込みません。警告:結果PDFは、それを作成するのに用いられる同じフォントを持っていると保証されません。代理をしているフォントが特定のシナリオで許容できる場合だけ、このオプションを使います。フォントの置き換えが許容されない場合、このプロパティはデフォルト値のDocumentFontEmbedMode.Auto。のままにしてください。 |
以下のコードスニペットは、許容できる品質で最小限のファイルサイズを生じるためにPDFオプションを設定する方法を示します:
void SetPDFOptions(DocumentWriter documentWriter, bool useImageOverText)
{
// Get the current PDF options
PdfDocumentOptions pdfOptions = documentWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
// Use JBIG2 for B/W images
pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Jbig2;
// Use JPEG2000 or Flate for colored images
pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpx;
// Embed fonts automatically
pdfOptions.FontEmbedMode = DocumentFontEmbedMode.Auto;
if (useImageOverText)
{
// Use image over text
pdfOptions.ImageOverText = true;
// Re-size the overlay image by 2
pdfOptions.ImageOverTextSize = DocumentImageOverTextSize.Half;
// Convert grayscale to black and white if possible
pdfOptions.ImageOverTextMode = DocumentImageOverTextMode.Relaxed;
// Use quality factor of 50
pdfOptions.QualityFactor = 50;
}
else
{
// Will not use image over text
pdfOptions.ImageOverText = false;
// Use quality factor of 100
pdfOptions.QualityFactor = 100;
}
// Set our options
documentWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);
}
このサンプルは、いろいろなサポートされたオプションを用いて新しいAdobe Portable Document Formatドキュメント(PDF)ファイルを作成します。
Imports Leadtools.Forms.DocumentWriters Imports Leadtools.Forms.Ocr Imports Leadtools Imports Leadtools.Codecs Public Sub PdfDocumentOptionsExample() Dim inputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.docx") Dim outputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf") ' Setup a new RasterCodecs object Dim codecs As New RasterCodecs() codecs.Options.RasterizeDocument.Load.Resolution = 300 ' Get the number of pages in the input document Dim pageCount As Integer = codecs.GetTotalPages(inputFileName) ' Create a new instance of the LEADTOOLS Document Writer Dim docWriter As New DocumentWriter() ' Change the PDF options Dim pdfOptions As PdfDocumentOptions = DirectCast(docWriter.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions) pdfOptions.DocumentType = PdfDocumentType.Pdf pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None pdfOptions.ImageOverText = False pdfOptions.Linearized = False pdfOptions.Title = "Add your title here" pdfOptions.Subject = "Add your subject here" pdfOptions.Keywords = "Add your keywords here" pdfOptions.Author = "Add author name here" pdfOptions.Protected = True pdfOptions.UserPassword = "User password" pdfOptions.OwnerPassword = "Owner password" pdfOptions.EncryptionMode = PdfDocumentEncryptionMode.RC128Bit pdfOptions.PrintEnabled = False pdfOptions.HighQualityPrintEnabled = True pdfOptions.CopyEnabled = False pdfOptions.EditEnabled = True pdfOptions.AnnotationsEnabled = True pdfOptions.AssemblyEnabled = False pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Flate pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpeg pdfOptions.QualityFactor = 2 ' Use default resolution pdfOptions.DocumentResolution = 0 pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed ' Setup empty page size (Letter size) pdfOptions.EmptyPageWidth = 8.5 pdfOptions.EmptyPageHeight = 11 pdfOptions.EmptyPageResolution = 300 docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions) ' Create a new PDF document Console.WriteLine("Creating new PDF document: {0}", outputFileName) docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf) ' Loop through all the pages For pageNumber As Integer = 1 To pageCount ' Get the page as SVG Console.WriteLine("Loading page {0}", pageNumber) Dim page As New DocumentSvgPage() page.SvgDocument = codecs.LoadSvg(inputFileName, pageNumber, Nothing) ' Add the page Console.WriteLine("Adding page {0}", pageNumber) docWriter.AddPage(page) page.SvgDocument.Dispose() Next ' Finally finish writing the PDF file on disk docWriter.EndDocument() codecs.Dispose() End Sub
using Leadtools.Forms.DocumentWriters; using Leadtools.Forms.Ocr; using Leadtools; using Leadtools.Codecs; public void PdfDocumentOptionsExample() { var inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.docx"); var outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf"); // Setup a new RasterCodecs object var codecs = new RasterCodecs(); codecs.Options.RasterizeDocument.Load.Resolution = 300; // Get the number of pages in the input document var pageCount = codecs.GetTotalPages(inputFileName); // Create a new instance of the LEADTOOLS Document Writer var docWriter = new DocumentWriter(); // Change the PDF options var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; pdfOptions.DocumentType = PdfDocumentType.Pdf; pdfOptions.FontEmbedMode = DocumentFontEmbedMode.None; pdfOptions.ImageOverText = false; pdfOptions.Linearized = false; pdfOptions.Title = "Add your title here"; pdfOptions.Subject = "Add your subject here"; pdfOptions.Keywords = "Add your keywords here"; pdfOptions.Author = "Add author name here"; pdfOptions.Protected = true; pdfOptions.UserPassword = "User password"; pdfOptions.OwnerPassword = "Owner password"; pdfOptions.EncryptionMode = PdfDocumentEncryptionMode.RC128Bit; pdfOptions.PrintEnabled = false; pdfOptions.HighQualityPrintEnabled = true; pdfOptions.CopyEnabled = false; pdfOptions.EditEnabled = true; pdfOptions.AnnotationsEnabled = true; pdfOptions.AssemblyEnabled = false; pdfOptions.OneBitImageCompression = OneBitImageCompressionType.Flate; pdfOptions.ColoredImageCompression = ColoredImageCompressionType.FlateJpeg; pdfOptions.QualityFactor = 2; // Use default resolution pdfOptions.DocumentResolution = 0; pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; // Setup empty page size (Letter size) pdfOptions.EmptyPageWidth = 8.5; pdfOptions.EmptyPageHeight = 11; pdfOptions.EmptyPageResolution = 300; docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); // Create a new PDF document Console.WriteLine("Creating new PDF document: {0}", outputFileName); docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf); // Loop through all the pages for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++) { // Get the page as SVG Console.WriteLine("Loading page {0}", pageNumber); var page = new DocumentSvgPage(); page.SvgDocument = codecs.LoadSvg(inputFileName, pageNumber, null); // Add the page Console.WriteLine("Adding page {0}", pageNumber); docWriter.AddPage(page); page.SvgDocument.Dispose(); } // Finally finish writing the PDF file on disk docWriter.EndDocument(); codecs.Dispose(); }