首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Winnovative HTMLtoPDF转换器,添加水印

Winnovative HTMLtoPDF转换器,添加水印
EN

Stack Overflow用户
提问于 2009-12-02 12:16:59
回答 1查看 2.4K关注 0票数 2

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-12-04 00:02:46

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

这是我使用的代码,基于我提供的链接。这是在我将pdf生成到PDFDocument对象中之后调用的。

代码语言:javascript
复制
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();
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1830614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档