2

Winnovative HTMLtoPDFコンバーターを使用してHTMLコンテンツからPDFを生成した人はいますか?もしそうなら、誰かがその結果のPDFの一部またはすべてのページに透かしを入れることに成功しましたか?

4

1 に答える 1

4

これは面白くなりました。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();
}
于 2009-12-03T16:02:46.160 に答える