彩票走势图

使用Adobe Acrobat Automation和Aspose.Pdf添加文本印章和水印

原创|其它|编辑:郝浩|2011-09-02 10:43:34.000|阅读 2861 次

概述:正如大家所知道的,Adobe Acrobat Automation和Aspose.Pdf for .NET 都允许你通过 编程的方式将文本印章/水印添加到PDF文件中。然而,Aspose.Pdf for .NET比Adobe Acrobat Automation 更易于使用。在这篇文章中,我将为大家展示如何使用Adobe Acrobat Automation和Aspose.Pdf for .NET 添加文本印章和水印,以及这两种产品之间的区别。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

  正如大家所知道的,Adobe Acrobat Automation和Aspose.Pdf for .NET 都允许你通过 编程的方式将文本印章/水印添加到PDF文件中。然而,Aspose.Pdf for .NET比Adobe Acrobat Automation 更易于使用。在这篇文章中,我将为大家展示如何使用Adobe Acrobat Automation和Aspose.Pdf for .NET 添加文本印章和水印,以及这两种产品之间的区别。

Adobe Acrobat Automation

  下面的代码片段向你展示了如何使用Adobe Acrobat Automation将文本印章/水印添加到PDF文件。

[C#]


// Create an AVDoc object

AcroAVDoc gAVDoc = new AcroAVDoc();

gAVDoc.Open("D:/Ap Data/Source_Files/Test.pdf","");

CAcroPDDoc pdDoc = (CAcroPDDoc)gAVDoc.GetPDDoc();

//Acquire the Acrobat JavaScript Object interface from the PDDoc object

Object jsObj = pdDoc.GetJSObject();

Type T = jsObj.GetType();

//get current time and make a string from it

System.DateTime currentTime = System.DateTime.Now;

// make a color object

Object colorObj = T.InvokeMember(

"color",

BindingFlags.GetProperty |

BindingFlags.Public |

BindingFlags.Instance,

null, jsObj, null);

Type colorType = colorObj.GetType();

Object blueColorObj = colorType.InvokeMember(

"blue",

BindingFlags.GetProperty |

BindingFlags.Public |

BindingFlags.Instance,

null, colorObj, null);

// Add a text watermark.

object[] addTextWatermarkParam = { currentTime.ToShortTimeString(),

1, "Helvetica", 100, blueColorObj, 0, 0, true, true, true, 0, 3, 20, -45, false, 1.0, false, 0, 0.7 };

T.InvokeMember(

"addWatermarkFromText",

BindingFlags.InvokeMethod |

BindingFlags.Public |

BindingFlags.Instance,

null, jsObj, addTextWatermarkParam);

[VB.NET]


' Create an AVDoc object

Dim gAVDoc As New AcroAVDoc()

gAVDoc.Open("D:/Ap Data/Source_Files/Test.pdf", "")

Dim pdDoc As CAcroPDDoc = CType(gAVDoc.GetPDDoc(), CAcroPDDoc)

'Acquire the Acrobat JavaScript Object interface from the PDDoc object

Dim jsObj As Object = pdDoc.GetJSObject()

Dim T As Type = jsObj.GetType()

'get current time and make a string from it

Dim currentTime As System.DateTime = System.DateTime.Now

' make a color object

Dim colorObj As Object = T.InvokeMember("color", BindingFlags.GetProperty Or BindingFlags.Public Or BindingFlags.Instance, Nothing, jsObj, Nothing)

Dim colorType As Type = colorObj.GetType()

Dim blueColorObj As Object = colorType.InvokeMember("blue", BindingFlags.GetProperty Or BindingFlags.Public Or BindingFlags.Instance, Nothing, colorObj, Nothing)

' Add a text watermark.

Dim addTextWatermarkParam() As Object = {currentTime.ToShortTimeString(), 1, "Helvetica", 100, blueColorObj, 0, 0, True, True, True, 0, 3, 20, -45, False, 1.0, False, 0, 0.7}

T.InvokeMember("addWatermarkFromText", BindingFlags.InvokeMethod Or BindingFlags.Public Or BindingFlags.Instance, Nothing, jsObj, addTextWatermarkParam)

Aspose.Pdf for .NET

  下面的代码片断展示了如何使用Aspose.Pdf for .NET控件中的PdfFileStamp类添加文本印章/水印到PDF文档中。

[C#]


//open document

PdfFileStamp fileStamp = new PdfFileStamp(@"D:\Source_Files\test.pdf", @"D:\Source_Files\output.pdf");

//create stamp

Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

//get current time and make a string from it

System.DateTime currentTime = System.DateTime.Now;

stamp.BindLogo(new FormattedText(currentTime.ToShortTimeString(), Color.Blue, Color.White, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 100));

//Set Origion

stamp.SetOrigin(100, 600);

//Set as Background

stamp.IsBackground = true;

//Set Opacity

stamp.Opacity = .7F;

//add stamp to PDF file

fileStamp.AddStamp(stamp);

//save updated PDF file

fileStamp.Close();

[VB.NET]


'open document

Dim fileStamp As New PdfFileStamp("D:\Source_Files\test.pdf", "D:\Source_Files\output.pdf")

'create stamp

Dim stamp As New Aspose.Pdf.Facades.Stamp()

'get current time and make a string from it

Dim currentTime As System.DateTime = System.DateTime.Now

stamp.BindLogo(New FormattedText(currentTime.ToShortTimeString(), Color.Blue, Color.White, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, True, 100))

'Set Origion

stamp.SetOrigin(100, 600)

'Set as Background

stamp.IsBackground = True

'Set Opacity

stamp.Opacity = 0.7F

'add stamp to PDF file

fileStamp.AddStamp(stamp)

'save updated PDF file

fileStamp.Close()

 


(慧都控件网版权所有,转载请注明出处,否则追究法律责任)
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP