使用Aspose.PDF更改PDF文件的内容

来源:慧都控件网 http://www.evget.com/zh-CN/Info/catalog/18035.html

Aspose.Pdf中含有一个PdfFileEditor类的ResizeContents方法,可以允许您调整PDF文件中的页面内容。ContentsResizeParameters类用于指定要使用的参数来调整这个页面。你可以使用ResizeContents方法调整所有的页面或者一个页面的特定内容

C#

//Create PdfFileEditor Object
PdfFileEditor fileEditor = new PdfFileEditor();

//Open PDF Document
Document doc = new Document("input.pdf");

//Specify Parameter to be used for resizing
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
//left margin = 10% of page width
PdfFileEditor.ContentsResizeValue.Percents(10),//new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
null,//right margin is 10% of page
PdfFileEditor.ContentsResizeValue.Percents(10),//top margin = 10% of height
PdfFileEditor.ContentsResizeValue.Percents(10),//new contents height is calculated automatically (similar to width)
null,//bottom margin is 10%
PdfFileEditor.ContentsResizeValue.Percents(10)
);

//Resize Page Contents
fileEditor.ResizeContents(doc,new int[] { 1,2,3 },parameters);

//save document into new location.
doc.Save("output.pdf");

VB.NET

'Create PdfFileEditor Object
Dim fileEditor As New PdfFileEditor()

'Open PDF Document
Dim doc As New Document("input.pdf")

'Specify Parameter to be used for resizing
'left margin = 10% of page width
'new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
'right margin is 10% of page
'top margin = 10% of height
'new contents height is calculated automatically (similar to width)
'bottom margin is 10%
Dim parameters As New PdfFileEditor.ContentsResizeParameters(PdfFileEditor.ContentsResizeValue.Percents(10),nothing,PdfFileEditor.ContentsResizeValue.Percents(10),PdfFileEditor.ContentsResizeValue.Percents(10))

'Resize Page Contents
fileEditor.ResizeContents(doc,New Integer() { 1,parameters)

'save document into new location.
doc.Save("output.pdf")

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...