Asp.net Winnovative HTMLtoPDF转换器,添加水印

Asp.net Winnovative HTMLtoPDF转换器,添加水印,asp.net,pdf,winnovative,Asp.net,Pdf,Winnovative,是否有人使用Winnovative HTMLtoPDF转换器从HTML内容生成PDF?如果是这样,有没有人成功地在生成的PDF的任何或所有页面上添加水印?这很有趣。在Winnovative的网站上,我发现了一个有用的代码片段。搜索6.4.2.2并阅读该部分中的代码 下面是我使用的代码,基于我提供的链接。在我将pdf生成到PDFDocument对象中后,将调用此函数 public void PostDocProcessing(Winnovative.WnvHtmlConvert.PdfDocume

是否有人使用Winnovative HTMLtoPDF转换器从HTML内容生成PDF?如果是这样,有没有人成功地在生成的PDF的任何或所有页面上添加水印?

这很有趣。在Winnovative的网站上,我发现了一个有用的代码片段。搜索6.4.2.2并阅读该部分中的代码

下面是我使用的代码,基于我提供的链接。在我将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();
}