html转 pdf 添加水印,Winnovative HTMLtoPDF转换器,添加水印

这很有意思。 Winnovative网站上的this page我发现了一个很有用的代码片段。搜索6.4.2.2并阅读该部分的代码。

这是我使用的代码,基于我提供的链接。这被称为AFTER我生成PDF到PDFDocument对象。

public void PostDocProcessing(Winnovative.WnvHtmlConvert.PdfDocument.Document document, string sBackgroundImagePath)

{

// get the first page the PDF document

PdfPage firstPage = document.Pages[0];

System.Drawing.Image logoImg = System.Drawing.Image.FromFile(sBackgroundImagePath);

// calculate the watermark location

System.Drawing.SizeF imageSizePx = logoImg.PhysicalDimension;

// transform from pixels to points

float imageWidthPoints = UnitsConverter.PixelsToPoints(imageSizePx.Width);

float imageHeightPoints = UnitsConverter.PixelsToPoints(imageSizePx.Height);

float watermarkXLocation = (firstPage.ClientRectangle.Width - imageWidthPoints);

float watermarkYLocation = -50;

// add a template watermark to the document repeated on each document page

// the watermark size is equal to image size in points

Template watermarkTemplate = document.AddTemplate(new System.Drawing.RectangleF(watermarkXLocation, watermarkYLocation, imageWidthPoints, imageHeightPoints));

// add an image to the watermak

ImageElement watermarkImageElement = new ImageElement(0, -300, logoImg);

watermarkImageElement.Transparency = 100;

watermarkTemplate.AddElement(watermarkImageElement);

// dispose the image

logoImg.Dispose();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值