当前位置 > 首页 > Asp.net

GdPicture.NET使用教程:在PDF文件中添加水印

2012-12-10 10:24:00来源:Asp.net

GdPicture.NET的功能强大之处除了可实现文档显示,获取TWAIN扫描图像,进行图像处理,执行光学字符识别等功能外,也可以在文档中添加水印,下面是使用GdPicture.NET在PDF文件中添加水印的代码示例:

》》》下载GdPicture.NET试用版

Const text As String = "WATERMARK"
Const textSize As Integer = 100
Const rotation As Single = 320 'Note: rotation is anti-clockwise
Const font As String = "Arial"

Using gdPicturePDF As New GdPicturePDF
gdPicturePDF.LoadFromFile("c:\input.pdf", False)
gdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint)
gdPicturePDF.SelectPage(1)
Using gdpicturePDFBack As New GdPicturePDF
gdpicturePDFBack.NewPDF()
Dim pageWidth As Single = gdPicturePDF.GetPageWidth()
Dim pageHeight As Single = gdPicturePDF.GetPageHeight()

gdpicturePDFBack.ClonePage(gdPicturePDF, 1)

gdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdPicturePDF.ClearPageContent()

Dim fontResName As String = gdPicturePDF.AddTrueTypeFont(font, True, False, False)
gdPicturePDF.SetTextSize(textSize)
gdPicturePDF.DrawRotatedText(fontResName, 0, gdPicturePDF.GetTextHeight(fontResName, textSize), text, rotation)
gdPicturePDF.SaveGraphicsState()
gdPicturePDF.SetBlendMode(PdfBlendMode.PdfBlendModeNormal)
gdPicturePDF.SetFillAlpha(200)

Dim status As GdPictureStatus = gdPicturePDF.DrawPage(gdpicturePDFBack, 1, 0, pageHeight, pageWidth, pageHeight)

gdPicturePDF.ResetGraphicsState()

gdPicturePDF.SaveToFile("c:\output.pdf")
End Using
End Using

本文链接