Class Document
Namespace: Aspose.Pdf
Assembly: Aspose.PDF.dll
表示 PDF 文档的类
public sealed class Document : IDisposable
继承
实现
继承的成员
object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
构造函数
Document(Stream)
从 input
流初始化新的 Document 实例。
public Document(Stream input)
参数
input
Stream
包含 PDF 文档的流。
Document(Stream, string, bool)
从 input
流初始化新的 Document 实例。
public Document(Stream input, string password, bool isManagedStream)
参数
input
Stream
包含 PDF 文档的流。
password
string
用户或所有者密码。
isManagedStream
bool
如果设置为 true
,则在退出之前关闭内部流;否则,不关闭。
Document(Stream, bool)
从 input
流初始化新的 Document 实例。
public Document(Stream input, bool isManagedStream)
参数
input
Stream
包含 PDF 文档的流。
isManagedStream
bool
如果设置为 true
,则在退出之前关闭内部流;否则,不关闭。
Document(string)
仅使用 filename
初始化 Document。与 Aspose.Pdf.Document.#ctor(System.IO.Stream) 相同。
public Document(string filename)
参数
filename
string
PDF 文档文件的名称。
Document(Stream, string)
从 input
流初始化新的 Document 实例。
public Document(Stream input, string password)
参数
input
Stream
输入流对象,对应的 PDF 受密码保护。
password
string
用户或所有者密码。
Document()
初始化空文档。
public Document()
Document(string, string)
初始化 Aspose.Pdf.Document 类的新实例以处理加密文档。
public Document(string filename, string password)
参数
filename
string
文档文件名。
password
string
用户或所有者密码。
Document(string, string, bool)
初始化 Aspose.Pdf.Document 类的新实例以处理加密文档。
public Document(string filename, string password, bool isManagedStream)
参数
filename
string
文档文件名。
password
string
用户或所有者密码。
isManagedStream
bool
如果设置为 true
,则在退出之前关闭内部流;否则,不关闭。
Document(string, LoadOptions)
从文件打开现有文档,提供必要的转换选项以获取 PDF 文档。
public Document(string filename, LoadOptions options)
参数
filename
string
要转换为 PDF 文档的输入文件。
options
LoadOptions
表示将 filename
转换为 PDF 文档的属性。
Document(Stream, LoadOptions)
从流打开现有文档,提供必要的转换以获取 PDF 文档。
public Document(Stream input, LoadOptions options)
参数
input
Stream
要转换为 PDF 文档的输入流。
options
LoadOptions
表示将 input
转换为 PDF 文档的属性。
字段
DefaultNodesNumInSubtrees
public const byte DefaultNodesNumInSubtrees = 10
字段值
属性
Actions
获取文档操作。此属性是 DocumentActions 类的实例,允许获取/设置 BeforClosing、BeforSaving 等操作。
public DocumentActionCollection Actions { get; }
属性值
DocumentActionCollection
示例
此示例演示如何获取文档的打开后操作:
Aspose.Pdf.Document document = new Aspose.Pdf.Document("d:\\work\\aspose\\aspose.pdf.kit.net.new\\trunk\\testdata\\Aspose.Pdf\\PdfWithOpenAction.pdf");
Aspose.Pdf.Annotations.DocumentActionCollection actions = document.Actions;
Aspose.Pdf.Annotations.PdfAction afterSavingAction = actions.AfterSaving;
AllowReusePageContent
允许合并页面内容以优化文档大小。如果使用,则不同但重复的页面可以引用同一内容对象。请注意,此模式可能会导致副作用,例如在其他页面更改时更改页面内容。
public bool AllowReusePageContent { get; set; }
属性值
Background
获取或设置文档的背景颜色。
public Color Background { get; set; }
属性值
Color
CenterWindow
获取或设置标志,指示文档窗口的位置是否应居中于屏幕。
public bool CenterWindow { get; set; }
属性值
示例
示例演示如何获取 CenterWindow 标志:
Document document = new Document("sample.pdf");
bool value = document.CenterWindow;
Collection
获取文档的集合。
public Collection Collection { get; set; }
属性值
Collection
CryptoAlgorithm
获取文档的安全设置,如果文档被加密。 如果文档未加密,则在 .net 1.1 中将引发相应异常, 或对于其他 .net 版本,CryptoAlgorithm 将为 null。
public CryptoAlgorithm? CryptoAlgorithm { get; }
属性值
CryptoAlgorithm?
Destinations
获取目的地集合。 已弃用。请使用 NamedDestinations。
public DestinationCollection Destinations { get; }
属性值
DestinationCollection
Direction
获取或设置文本的阅读顺序:L2R(从左到右)或 R2L(从右到左)。
public Direction Direction { get; set; }
属性值
Direction
DisableFontLicenseVerifications
许多与字体相关的操作无法执行,如果这些操作被此字体的许可证禁止。 例如,如果许可证规则禁用此字体的嵌入,则某些字体无法嵌入到 PDF 文档中。 此标志用于禁用当前 PDF 文档中所有字体的任何许可证限制。 使用此标志时请小心。当设置此标志时,意味着设置此标志的人, 承担所有可能的许可证/法律违规责任。 因此,他承担自己的风险。 强烈建议仅在您完全确认未违反 版权法时使用此标志。 默认值为 false。
public bool DisableFontLicenseVerifications { get; set; }
属性值
DisplayDocTitle
获取或设置标志,指示文档的窗口标题栏是否应显示文档标题。
public bool DisplayDocTitle { get; set; }
属性值
示例
示例演示如何获取 DisplayDocTitle 标志:
Document document = new Document("sample.pdf");
bool value = document.DisplayDocTitle;
Duplex
获取或设置打印双面模式处理选项,以便在打印文件时使用。
public PrintDuplex Duplex { get; set; }
属性值
PrintDuplex
EmbedStandardFonts
声明文档必须嵌入所有标准 Type1 字体的属性, 其标志 IsEmbedded 设置为 true。所有 PDF 字体都可以通过将标志 IsEmbedded 设置为 true 嵌入到文档中,但 PDF 标准 Type1 字体是此规则的例外。 标准 Type1 字体的嵌入需要大量时间,因此要嵌入这些字体,不仅需要将指定字体的 IsEmbedded 标志设置为 true, 还需要在文档级别上设置附加标志 - EmbedStandardFonts = true; 此属性只能为所有字体设置一次。 默认值为 false。
public bool EmbedStandardFonts { get; set; }
属性值
EmbeddedFiles
获取嵌入到文档中的文件集合。
public EmbeddedFileCollection EmbeddedFiles { get; }
属性值
EmbeddedFileCollection
EnableObjectUnload
获取或设置标志,允许文档部分从内存中卸载。 这可以减少内存使用,但可能对性能产生负面影响。
public bool EnableObjectUnload { get; set; }
属性值
EnableSignatureSanitization
获取或设置标志以管理签名字段的清理。默认启用。
public bool EnableSignatureSanitization { get; set; }
属性值
FileName
导致此文档的 PDF 文件的名称。
public string FileName { get; }
属性值
FitWindow
获取或设置标志,指示文档窗口是否必须调整大小以适合第一个显示的页面。
public bool FitWindow { get; set; }
属性值
示例
示例演示如何获取 FitWindow 标志:
Document document = new Document("sample.pdf");
bool value = document.FitWindow;
FontUtilities
IDocumentFontUtilities 实例。
public Document.IDocumentFontUtilities FontUtilities { get; }
属性值
Document.IDocumentFontUtilities
Form
获取文档的 Acro 表单。
public Form Form { get; }
属性值
Form
HandleSignatureChange
如果文档将以更改保存并具有签名,则抛出异常。
public bool HandleSignatureChange { get; set; }
属性值
HideMenubar
获取或设置标志,指示当文档处于活动状态时菜单栏是否应隐藏。
public bool HideMenubar { get; set; }
属性值
示例
示例演示如何获取 HideMenubar 标志:
Document document = new Document("sample.pdf");
bool value = document.HideMenubar;
HideToolBar
获取或设置标志,指示当文档处于活动状态时工具栏是否应隐藏。
public bool HideToolBar { get; set; }
属性值
示例
示例演示如何获取 HideToolBar 标志:
Document document = new Document("sample.pdf");
bool value = document.HideToolBar;
HideWindowUI
获取或设置标志,指示当文档处于活动状态时用户界面元素是否应隐藏。
public bool HideWindowUI { get; set; }
属性值
示例
示例演示如何获取 HideWindowUI 标志:
Document document = new Document("sample.pdf");
bool value = document.HideWindowUI;
Id
获取 ID。
public Id Id { get; }
属性值
Id
IgnoreCorruptedObjects
获取或设置忽略源文件中错误的标志。 当源文档中的页面复制到目标文档时,如果源文件中的某些对象损坏,则复制过程将停止并引发异常, 如果此标志为 false。 示例:dest.Pages.Add(src.Pages); 如果将此标志设置为 true,则损坏的对象将被空值替换。 默认值:true。
public bool IgnoreCorruptedObjects { get; set; }
属性值
Info
获取文档信息。
public DocumentInfo Info { get; }
属性值
DocumentInfo
IsEncrypted
获取文档的加密状态。如果文档被加密,则为 true。
public bool IsEncrypted { get; }
属性值
IsLicensed
获取系统的许可状态。如果系统以许可模式运行,则返回 true,否则返回 false。
public static bool IsLicensed { get; }
属性值
IsLinearized
获取或设置一个值,指示文档是否已线性化。
public bool IsLinearized { get; set; }
属性值
IsPdfUaCompliant
获取文档是否符合 pdfua 标准。
public bool IsPdfUaCompliant { get; }
属性值
IsPdfaCompliant
获取文档是否符合 pdfa 标准。
public bool IsPdfaCompliant { get; }
属性值
IsXrefGapsAllowed
获取或设置文档是否允许 xref 间隙。
public bool IsXrefGapsAllowed { get; set; }
属性值
JavaScript
文档级的 JavaScript 集合。
public JavaScriptCollection JavaScript { get; }
属性值
JavaScriptCollection
LogicalStructure
获取文档的逻辑结构。
public RootElement LogicalStructure { get; }
属性值
RootElement
Metadata
文档元数据。 (PDF 文档可以包括一般信息, 例如文档的标题、作者以及创建和修改日期。 关于文档的此类全局信息(与其内容或结构相对)称为元数据, 旨在帮助在外部数据库中对文档进行分类和搜索。)
public Metadata Metadata { get; }
属性值
Metadata
NamedDestinations
文档中命名目的地的集合。
public NamedDestinationCollection NamedDestinations { get; }
属性值
NamedDestinationCollection
NonFullScreenPageMode
获取或设置页面模式,指定在退出全屏模式时如何显示文档。
public PageMode NonFullScreenPageMode { get; set; }
属性值
PageMode
OpenAction
获取或设置在打开文档时执行的操作。
public IAppointment OpenAction { get; set; }
属性值
IAppointment
示例
示例演示如何获取 CenterWindow 标志:
Document document = new Document("sample.pdf");
IAppointment value = document.OpenAction;
OptimizeSize
获取或设置优化标志。当页面添加到文档时,如果设置了此标志,则结果文件中的相同资源流将合并为一个 PDF 对象。 这可以减少结果文件的大小,但可能导致执行速度变慢和更大的内存需求。 默认值:false。
public bool OptimizeSize { get; set; }
属性值
Outlines
获取文档的轮廓。
public OutlineCollection Outlines { get; }
属性值
OutlineCollection
OutputIntents
获取文档中的输出意图集合。
public OutputIntents OutputIntents { get; }
属性值
OutputIntents
PageInfo
获取或设置页面信息(仅供生成器使用,读取文档时未填充)。
public PageInfo PageInfo { get; set; }
属性值
PageInfo
PageLabels
获取文档中的页面标签。
public PageLabelCollection PageLabels { get; }
属性值
PageLabelCollection
PageLayout
获取或设置在打开文档时应使用的页面布局。
public PageLayout PageLayout { get; set; }
属性值
PageLayout
PageMode
获取或设置页面模式,指定打开文档时应如何显示文档。
public PageMode PageMode { get; set; }
属性值
PageMode
Pages
获取或设置文档页面的集合。 请注意,集合中的页面编号从 1 开始。
public PageCollection Pages { get; }
属性值
PageCollection
示例
下面的示例演示如何操作文档页面: 如何获取页面数量以及如何获取文档起始页面的矩形。
Aspose.Pdf.Document document = new Aspose.Pdf.Document("sample.pdf");
Aspose.Pdf.PageCollection pages = document.Pages;
System.Console.WriteLine("Document contains " + pages.Count);
Page page = pages[1];
Rectangle rect = page.Rect;
PdfFormat
获取 PDF 格式。
public PdfFormat PdfFormat { get; }
属性值
PdfFormat
Permissions
获取文档的权限。
public int Permissions { get; }
属性值
PickTrayByPdfSize
获取或设置标志,指示是否应使用 PDF 页面大小来选择输入纸盘。
public bool PickTrayByPdfSize { get; set; }
属性值
PrintScaling
获取或设置在显示此文档的打印对话框时应选择的页面缩放选项。
public PrintScaling PrintScaling { get; set; }
属性值
PrintScaling
TaggedContent
获取对 TaggedPdf 内容的访问。
public ITaggedContent TaggedContent { get; }
属性值
ITaggedContent
示例
该示例演示如何使用标记内容创建具有标题、段落和图像的新文档。
// 创建新文档
Document document = new Document();
// 获取标记内容
ITaggedContent taggedContent = document.TaggedContent;
// 设置文档语言
taggedContent.SetLanguage("en-US");
// 设置 PDF 文档标题
taggedContent.SetTitle("Example document");
// 创建并添加节
SectElement sect = taggedContent.CreateSectElement();
taggedContent.RootElement.AppendChild(sect);
// 创建标题
HeaderElement h1 = taggedContent.CreateHeaderElement(1);
h1.SetText("The Header");
sect.AppendChild(h1);
// 创建段落
ParagraphElement p = taggedContent.CreateParagraphElement();
p.SetTag("Paragraph");
p.SetText("The text of paragraph.");
sect.AppendChild(p);
// 创建插图
IllustrationElement figure1 = taggedContent.CreateFigureElement();
sect.AppendChild(figure1);
figure1.AlternativeText = "Figure 1";
figure1.Title = "Image 1";
figure1.SetTag("Fig");
figure1.SetImage("path/of/image.jpg");
// 保存文档
document.Save("example.pdf");
Version
获取 PDF 文件头中的 PDF 版本。
public string Version { get; }
属性值
方法
BindXml(string)
将 XML 绑定到文档。
public void BindXml(string file)
参数
file
string
XML 文件。
BindXml(string, string)
将 XML/XSL 绑定到文档。
public void BindXml(string xmlFile, string xslFile)
参数
xmlFile
string
XML 文件。
xslFile
string
如果使用了 XSLT,则为 XSL 文件。
BindXml(Stream, Stream)
将 XML/XSL 绑定到文档。
public void BindXml(Stream xmlStream, Stream xslStream)
参数
xmlStream
Stream
XML 流。
xslStream
Stream
如果使用了 XSLT,则为 XSL 流。
BindXml(Stream, Stream, XmlReaderSettings)
将 XML/XSL 绑定到文档。
public void BindXml(Stream xmlStream, Stream xslStream, XmlReaderSettings settings)
参数
xmlStream
Stream
XML 流。
xslStream
Stream
如果使用了 XSLT,则为 XSL 流。
settings
XmlReaderSettings
XML 读取器设置。
BindXml(Stream)
将 XML 绑定到文档。
public void BindXml(Stream stream)
参数
stream
Stream
XML 流。
ChangePasswords(string, string, string)
更改文档密码。此操作只能使用所有者密码进行。
public void ChangePasswords(string ownerPassword, string newUserPassword, string newOwnerPassword)
参数
ownerPassword
string
所有者密码。
newUserPassword
string
新用户密码。
newOwnerPassword
string
新所有者密码。
Check(bool)
验证文档。
public bool Check(bool doRepair)
参数
doRepair
bool
如果为 true,发现的问题将被修复。
返回
如果文档已修复,则为 true;否则为 false。
Convert(string, PdfFormat, ConvertErrorAction, ConvertTransparencyAction)
转换文档并将错误保存到指定文件中。
public bool Convert(string outputLogFileName, PdfFormat format, ConvertErrorAction action, ConvertTransparencyAction transparencyAction)
参数
outputLogFileName
string
存储注释的文件路径。
format
PdfFormat
PDF 格式。
action
ConvertErrorAction
无法转换的对象的操作。
transparencyAction
ConvertTransparencyAction
图像遮罩对象的操作。
返回
操作结果。
Convert(Stream, PdfFormat, ConvertErrorAction, ConvertTransparencyAction)
转换文档并将错误保存到指定文件中。
public bool Convert(Stream outputLogStream, PdfFormat format, ConvertErrorAction action, ConvertTransparencyAction transparencyAction)
参数
outputLogStream
Stream
存储注释的流。
format
PdfFormat
PDF 格式。
action
ConvertErrorAction
无法转换的对象的操作。
transparencyAction
ConvertTransparencyAction
图像遮罩对象的操作。
返回
操作结果。
Convert(string, PdfFormat, ConvertErrorAction)
转换文档并将错误保存到指定文件中。
public bool Convert(string outputLogFileName, PdfFormat format, ConvertErrorAction action)
参数
outputLogFileName
string
存储注释的文件路径。
format
PdfFormat
PDF 格式。
action
ConvertErrorAction
无法转换的对象的操作。
返回
操作结果。
Convert(PdfFormatConversionOptions)
使用指定的转换选项转换文档。
public bool Convert(PdfFormatConversionOptions options)
参数
options
PdfFormatConversionOptions
用于转换 PDF 文档的选项集。
返回
操作结果。
Convert(CallBackGetHocrWithPage, bool)
识别文档中的图像并在其上添加 hocr 字符串。
public bool Convert(Document.CallBackGetHocrWithPage callback, bool flattenImages = false)
参数
callback
Document.CallBackGetHocrWithPage
将由 hocr 识别处理的图像的操作。
flattenImages
bool
PDF 图像中的文本可以使用遮罩机制绘制,在这种情况下,图像必须被压平。
返回
操作结果。如果文档中没有图像,则返回 false。
Convert(CallBackGetHocr, bool)
识别文档中的图像并在其上添加 hocr 字符串。
public bool Convert(Document.CallBackGetHocr callback, bool flattenImages = false)
参数
callback
Document.CallBackGetHocr
将由 hocr 识别处理的图像的操作。
flattenImages
bool
PDF 图像中的文本可以使用遮罩机制绘制,在这种情况下,图像必须被压平。
返回
操作结果。如果文档中没有图像,则返回 false。
Convert(Stream, PdfFormat, ConvertErrorAction)
转换文档并将错误保存到指定流中。
public bool Convert(Stream outputLogStream, PdfFormat format, ConvertErrorAction action)
参数
outputLogStream
Stream
存储注释的流。
format
PdfFormat
PDF 格式。
action
ConvertErrorAction
无法转换的对象的操作。
返回
操作结果。
Convert(Fixup, Stream, bool, object[])
通过应用 Fixup 转换文档。
public bool Convert(Fixup fixup, Stream outputLog, bool onlyValidation = false, object[] parameters = null)
参数
fixup
Fixup
Fixup 类型。
outputLog
Stream
过程日志。
onlyValidation
bool
仅文档验证。
parameters
object[]
无法设置的 Fixup 属性。
返回
操作结果。
Convert(Fixup, string, bool, object[])
通过应用 Fixup 转换文档。
public bool Convert(Fixup fixup, string outputLog, bool onlyValidation = false, object[] parameters = null)
参数
fixup
Fixup
Fixup 类型。
outputLog
string
过程日志。
onlyValidation
bool
仅文档验证。
parameters
object[]
无法设置的 Fixup 属性。
返回
操作结果。
Convert(string, LoadOptions, string, SaveOptions)
将源文件从源格式转换为目标文件的目标格式。
public static void Convert(string srcFileName, LoadOptions loadOptions, string dstFileName, SaveOptions saveOptions)
参数
srcFileName
string
源文件名称。
loadOptions
LoadOptions
源文件格式。
dstFileName
string
目标文件名称。
saveOptions
SaveOptions
目标文件格式。
Convert(Stream, LoadOptions, string, SaveOptions)
将源格式的流转换为目标文件的目标格式。
public static void Convert(Stream srcStream, LoadOptions loadOptions, string dstFileName, SaveOptions saveOptions)
参数
srcStream
Stream
源流。
loadOptions
LoadOptions
源流格式。
dstFileName
string
目标文件名称。
saveOptions
SaveOptions
目标文件格式。
Convert(string, LoadOptions, Stream, SaveOptions)
将源文件从源格式转换为目标格式的流。
public static void Convert(string srcFileName, LoadOptions loadOptions, Stream dstStream, SaveOptions saveOptions)
参数
srcFileName
string
源文件名称。
loadOptions
LoadOptions
源文件格式。
dstStream
Stream
目标流。
saveOptions
SaveOptions
目标流格式。
Convert(Stream, LoadOptions, Stream, SaveOptions)
将源格式的流转换为目标格式的流。
public static void Convert(Stream srcStream, LoadOptions loadOptions, Stream dstStream, SaveOptions saveOptions)
参数
srcStream
Stream
源流。
loadOptions
LoadOptions
源流格式。
dstStream
Stream
目标流。
saveOptions
SaveOptions
目标文件格式。
ConvertPageToPNGMemoryStream(Page)
将页面转换为 PNG,以便用于 DSR、OMR、OCR 图像流。
public MemoryStream ConvertPageToPNGMemoryStream(Page page)
参数
page
Page
要转换的页面。
返回
图像流。
Decrypt()
解密文档。然后调用 Save 以获取解密版本的文档。
public void Decrypt()
Dispose()
关闭此文档使用的所有资源。
public void Dispose()
Encrypt(string, string, DocumentPrivilege, CryptoAlgorithm, bool)
加密文档。然后调用 Save 以获取加密版本的文档。
public void Encrypt(string userPassword, string ownerPassword, DocumentPrivilege privileges, CryptoAlgorithm cryptoAlgorithm, bool usePdf20)
参数
userPassword
string
用户密码。
ownerPassword
string
所有者密码。
privileges
DocumentPrivilege
文档权限,详见 Aspose.Pdf.Document.Permissions。
cryptoAlgorithm
CryptoAlgorithm
加密算法,详见 Aspose.Pdf.Document.CryptoAlgorithm。
usePdf20
bool
支持修订 6(扩展 8)。
Encrypt(string, string, Permissions, CryptoAlgorithm)
加密文档。然后调用 Save 以获取加密版本的文档。
public void Encrypt(string userPassword, string ownerPassword, Permissions permissions, CryptoAlgorithm cryptoAlgorithm)
参数
userPassword
string
用户密码。
ownerPassword
string
所有者密码。
permissions
Permissions
文档权限,详见 Aspose.Pdf.Document.Permissions。
cryptoAlgorithm
CryptoAlgorithm
加密算法,详见 Aspose.Pdf.Document.CryptoAlgorithm。
Encrypt(string, string, Permissions, CryptoAlgorithm, bool)
加密文档。然后调用 Save 以获取加密版本的文档。
public void Encrypt(string userPassword, string ownerPassword, Permissions permissions, CryptoAlgorithm cryptoAlgorithm, bool usePdf20)
参数
userPassword
string
用户密码。
ownerPassword
string
所有者密码。
permissions
Permissions
文档权限,详见 Aspose.Pdf.Document.Permissions。
cryptoAlgorithm
CryptoAlgorithm
加密算法,详见 Aspose.Pdf.Document.CryptoAlgorithm。
usePdf20
bool
支持修订 6(扩展 8)。
ExportAnnotationsToXfdf(string)
将所有文档注释导出到 XFDF 文件。
public void ExportAnnotationsToXfdf(string fileName)
参数
fileName
string
XFDF 文件名称。
ExportAnnotationsToXfdf(Stream)
将所有文档注释导出到流中。
public void ExportAnnotationsToXfdf(Stream stream)
参数
stream
Stream
存储 XFDF 的流。
Flatten()
从文档中删除所有字段,并替换其值。
public void Flatten()
Flatten(FlattenSettings)
从文档中删除所有字段(和注释),并替换其值。
public void Flatten(Form.FlattenSettings flattenSettings)
参数
flattenSettings
Form.FlattenSettings
平整过程的设置。
FlattenTransparency()
用不透明的光栅和矢量图形替换透明内容。
public void FlattenTransparency()
FreeMemory()
清除内存。
public void FreeMemory()
GetCatalogValue(string)
从目录字典中返回项目值。
public object GetCatalogValue(string key)
参数
key
string
项目的键。
返回
项目值 - 如果成功找到键;否则为 null。
GetObjectById(string)
获取文档中具有指定 ID 的对象。
public object GetObjectById(string id)
参数
id
string
对象 ID。
返回
具有指定 ID 的对象。如果未找到 ID,则为 null。
GetXmpMetadata(Stream)
从文档中获取 XMP 元数据。
public void GetXmpMetadata(Stream stream)
参数
stream
Stream
将存储元数据的流。
HasIncrementalUpdate()
检查当前 PDF 文档是否已使用增量更新保存。
public bool HasIncrementalUpdate()
返回
true
如果 PDF 文档具有增量更新;否则,false
。
ImportAnnotationsFromXfdf(string)
从 XFDF 文件导入注释到文档。
public void ImportAnnotationsFromXfdf(string fileName)
参数
fileName
string
XFDF 文件名称。
ImportAnnotationsFromXfdf(Stream)
从流导入注释到文档。
public void ImportAnnotationsFromXfdf(Stream stream)
参数
stream
Stream
包含 XFDF 数据的流。
LoadFrom(string, LoadOptions)
加载文件,将其转换为 PDF。
public void LoadFrom(string filename, LoadOptions options)
参数
filename
string
要打开的文件路径。
options
LoadOptions
加载选项。
异常
PdfException
如果无法加载文件。
如果未找到文件。
Merge(MergeOptions, params Document[])
合并文档。
public void Merge(Document.MergeOptions mergeOptions, params Document[] documents)
参数
mergeOptions
Document.MergeOptions
合并选项。
documents
Document[]
要合并的文档。
Merge(MergeOptions, params string[])
合并文档。
public void Merge(Document.MergeOptions mergeOptions, params string[] files)
参数
mergeOptions
Document.MergeOptions
合并选项。
files
string[]
要合并的 PDF 文件。
Merge(params Document[])
合并文档。
public void Merge(params Document[] documents)
参数
documents
Document[]
要合并的文档。
Merge(params string[])
合并 PDF 文件。
public void Merge(params string[] files)
参数
files
string[]
要合并的 PDF 文件。
MergeDocuments(MergeOptions, params string[])
合并文档。
public static Document MergeDocuments(Document.MergeOptions mergeOptions, params string[] files)
参数
mergeOptions
Document.MergeOptions
合并选项。
files
string[]
要合并的 PDF 文件。
返回
合并后的文档。
MergeDocuments(MergeOptions, params Document[])
合并文档。
public static Document MergeDocuments(Document.MergeOptions mergeOptions, params Document[] files)
参数
mergeOptions
Document.MergeOptions
files
Document[]
要合并的文档。
返回
合并后的文档。
MergeDocuments(params string[])
合并 PDF 文件。
public static Document MergeDocuments(params string[] files)
参数
files
string[]
要合并的 PDF 文件。
返回
合并后的文档。
MergeDocuments(params Document[])
合并文档。
public static Document MergeDocuments(params Document[] documents)
参数
documents
Document[]
要合并的文档。
返回
合并后的文档。
Optimize()
线性化文档以便于
- 尽快打开第一页;
- 尽快显示下一页或跟随链接到下一页;
- 在通过慢速通道传输页面数据时增量显示页面(首先显示最有用的数据);
- 允许用户交互,例如在接收和显示整个页面之前执行跟随链接。 调用此方法实际上并不会保存文档。相反,文档仅准备具有优化的结构, 然后调用 Save 以获取优化的文档。
public void Optimize()
OptimizeResources()
优化文档中的资源:
- 删除未在文档页面上使用的资源;
- 将相等资源合并为一个对象;
- 删除未使用的对象。
public void OptimizeResources()
OptimizeResources(OptimizationOptions)
根据定义的优化策略优化文档中的资源。
public void OptimizeResources(OptimizationOptions strategy)
参数
strategy
OptimizationOptions
优化策略。
PageNodesToBalancedTree(byte)
将文档中的页面树节点组织成一个平衡树。 仅当文档中的页面对象数量超过 nodesNumInSubtrees 时,才执行此操作;否则不执行。 在迭代 Pages 元素时不要调用此方法,这可能会导致不可预测的结果。
public void PageNodesToBalancedTree(byte nodesNumInSubtrees = 10)
参数
nodesNumInSubtrees
byte
所需的子节点数量。默认值为 10。
ProcessParagraphs()
处理生成器的段落。
public void ProcessParagraphs()
RemoveMetadata()
从文档中删除元数据。
public void RemoveMetadata()
RemovePdfUaCompliance()
从文档中删除 pdfUa 合规性。
public void RemovePdfUaCompliance()
RemovePdfaCompliance()
从文档中删除 pdfa 合规性。
public void RemovePdfaCompliance()
Repair()
修复损坏的文档。
public void Repair()
Save(Stream)
将文档存储到流中。
public void Save(Stream output)
参数
output
Stream
将存储文档的流。
Save(string)
将文档保存到指定的文件中。
public void Save(string outputFileName)
参数
outputFileName
string
将存储文档的文件路径。
Save()
增量保存文档(即使用增量更新技术)。
public void Save()
备注
为了增量保存文档,我们应该打开文档文件以进行写入。 因此,Document 必须使用可写流初始化,如下代码片段所示: Document doc = new Document(new FileStream(“document.pdf”, FileMode.Open, FileAccess.ReadWrite)); // 进行一些更改并增量保存文档 doc.Save();
Save(SaveOptions)
使用保存选项保存文档。
public void Save(SaveOptions options)
参数
options
SaveOptions
保存选项。
Save(string, SaveFormat)
使用新名称及文件格式保存文档。
public void Save(string outputFileName, SaveFormat format)
参数
outputFileName
string
将存储文档的文件路径。
format
SaveFormat
格式选项。
Save(Stream, SaveFormat)
使用新名称及文件格式保存文档。
public void Save(Stream outputStream, SaveFormat format)
参数
outputStream
Stream
将存储文档的流。
format
SaveFormat
格式选项。
异常
当 Aspose.Pdf.HtmlSaveOptions 被传递给方法时,系统.ArgumentException。将文档保存到 HTML 流是不支持的。请使用方法保存到文件。
Save(string, SaveOptions)
使用新名称并设置其保存选项保存文档。
public void Save(string outputFileName, SaveOptions options)
参数
outputFileName
string
将存储文档的文件路径。
options
SaveOptions
保存选项。
Save(Stream, SaveOptions)
使用保存选项将文档保存到流。
public void Save(Stream outputStream, SaveOptions options)
参数
outputStream
Stream
将存储文档的流。
options
SaveOptions
保存选项。
异常
当 Aspose.Pdf.HtmlSaveOptions 被传递给方法时,系统.ArgumentException。将文档保存到 HTML 流是不支持的。请使用方法保存到文件。
SaveAsync(Stream, CancellationToken)
将文档存储到流中。
public Task SaveAsync(Stream output, CancellationToken cancellationToken)
参数
output
Stream
将存储文档的流。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
SaveAsync(string, CancellationToken)
将文档保存到指定的文件中。
public Task SaveAsync(string outputFileName, CancellationToken cancellationToken)
参数
outputFileName
string
将存储文档的文件路径。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
SaveAsync(CancellationToken)
增量保存文档(即使用增量更新技术)。
public Task SaveAsync(CancellationToken cancellationToken)
参数
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
备注
为了增量保存文档,我们应该打开文档文件以进行写入。 因此,Document 必须使用可写流初始化,如下代码片段所示: Document doc = new Document(new FileStream(“document.pdf”, FileMode.Open, FileAccess.ReadWrite)); // 进行一些更改并增量保存文档 doc.Save();
SaveAsync(SaveOptions, CancellationToken)
使用保存选项保存文档。
public Task SaveAsync(SaveOptions options, CancellationToken cancellationToken)
参数
options
SaveOptions
保存选项。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
SaveAsync(string, SaveFormat, CancellationToken)
使用新名称及文件格式保存文档。
public Task SaveAsync(string outputFileName, SaveFormat format, CancellationToken cancellationToken)
参数
outputFileName
string
将存储文档的文件路径。
format
SaveFormat
格式选项。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
SaveAsync(Stream, SaveFormat, CancellationToken)
使用新名称及文件格式保存文档。
public Task SaveAsync(Stream outputStream, SaveFormat format, CancellationToken cancellationToken)
参数
outputStream
Stream
将存储文档的流。
format
SaveFormat
格式选项。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
异常
当 Aspose.Pdf.HtmlSaveOptions 被传递给方法时,系统.ArgumentException。将文档保存到 HTML 流是不支持的。请使用方法保存到文件。
SaveAsync(string, SaveOptions, CancellationToken)
使用新名称并设置其保存选项保存文档。
public Task SaveAsync(string outputFileName, SaveOptions options, CancellationToken cancellationToken)
参数
outputFileName
string
将存储文档的文件路径。
options
SaveOptions
保存选项。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
SaveAsync(Stream, SaveOptions, CancellationToken)
使用保存选项将文档保存到流。
public Task SaveAsync(Stream outputStream, SaveOptions options, CancellationToken cancellationToken)
参数
outputStream
Stream
将存储文档的流。
options
SaveOptions
保存选项。
cancellationToken
CancellationToken
取消令牌。
返回
异步任务。
异常
当 Aspose.Pdf.HtmlSaveOptions 被传递给方法时,系统.ArgumentException。将文档保存到 HTML 流是不支持的。请使用方法保存到文件。
SaveXml(string)
将文档保存为 XML。
public void SaveXml(string file)
参数
file
string
文档模型 XML 文件。
SendTo(DocumentDevice, Stream)
将整个文档发送到文档设备进行处理。
public void SendTo(DocumentDevice device, Stream output)
参数
device
DocumentDevice
用于处理文档的文档设备。
output
Stream
输出流,包含使用给定设备处理的文档结果。
SendTo(DocumentDevice, int, int, Stream)
将文档的特定页面发送到文档设备进行处理。
public void SendTo(DocumentDevice device, int fromPage, int toPage, Stream output)
参数
device
DocumentDevice
用于处理文档的文档设备。
fromPage
int
用于处理的第一页。
toPage
int
用于处理的最后一页。
output
Stream
输出流,包含使用给定设备处理的文档页面的结果。
SendTo(DocumentDevice, string)
将整个文档发送到文档设备进行处理。
public void SendTo(DocumentDevice device, string outputFileName)
参数
device
DocumentDevice
用于处理文档的文档设备。
outputFileName
string
处理结果的输出文件名称。
SendTo(DocumentDevice, int, int, string)
将整个文档发送到文档设备进行处理。
public void SendTo(DocumentDevice device, int fromPage, int toPage, string outputFileName)
参数
device
DocumentDevice
用于处理文档的文档设备。
fromPage
int
用于处理的第一页。
toPage
int
用于处理的最后一页。
outputFileName
string
处理结果的输出文件名称。
SetTitle(string)
为 PDF 文档设置标题。
public void SetTitle(string title)
参数
title
string
文档的标题。
SetXmpMetadata(Stream)
设置文档的 XMP 元数据。
public void SetXmpMetadata(Stream stream)
参数
stream
Stream
包含 XMP 元数据的流。
Validate(string, PdfFormat)
验证文档并输出到指定文件。
public bool Validate(string outputLogFileName, PdfFormat format)
参数
outputLogFileName
string
存储注释的文件路径。
format
PdfFormat
PDF 格式。
返回
操作结果。
Validate(Stream, PdfFormat)
验证文档并输出到指定文件。
public bool Validate(Stream outputLogStream, PdfFormat format)
参数
outputLogStream
Stream
存储注释的流。
format
PdfFormat
PDF 格式。
返回
操作结果。
Validate(PdfFormatConversionOptions)
验证文档并输出到指定文件。
public bool Validate(PdfFormatConversionOptions options)
参数
options
PdfFormatConversionOptions
用于转换 PDF 文档的选项集。
返回
操作结果。
FontSubstitution
当字体在文档中替换为另一种字体时发生。
public event Document.FontSubstitutionHandler FontSubstitution