如何在asp.net中使用itextsharp在pdf或现有pdf上显示水印文本

时间:2011-05-26 04:58:47

标签: asp.net pdf itextsharp

帮助我在asp.net中使用itextsharp在pdf上显示水印文本 谢谢, 苏尼。

2 个答案:

答案 0 :(得分:1)

请参阅this以了解您的问题,该问题清除了您对您的问题的疑问。

答案 1 :(得分:0)

implode 与pdfsharp '导入此

    Imports System.IO
    Imports PdfSharp.Pdf
    Imports PdfSharp.Pdf.IO
    Imports PdfSharp.Drawing

    Dim doc = ReturnCompatiblePdf(path_of_pdf_file)
    Dim document As New PdfDocument
    document = PdfReader.Open(doc, PdfDocumentOpenMode.Modify)
    Dim watermark As String = "This is my watermark"

    For Each page_ As PdfPage In document.Pages

        Dim gfx As XGraphics = XGraphics.FromPdfPage(page_, XGraphicsPdfPageOptions.Append)
        Dim fontx As New XFont("Trebuchet MS", 8, FontStyle.Bold)
        Dim posx, posy As Double
        posx = (page_.Width.Value - watermark.Length) / 2
        posy = page_.Height.Value - 8
        gfx.TranslateTransform(posx, posy)
        gfx.DrawString(watermark, fontx, XBrushes.Black, New XPoint(1, 1), XStringFormats.Default)
    Next

    If File.Exists(save_path) = False Then
        document.Save(save_path)
    End If