ItextSharp-在单独的行上添加文本水印

ItextSharp-在单独的行上添加文本水印,itext,watermark,Itext,Watermark,我正在尝试使用itextsharp 5.1.2.0在pdf文件中添加watermak 我希望水印位于页面中心,呈45°角,在这些线周围有一个边框 这是我的密码: for (int i = 1; i <= reader.NumberOfPages; i++) { iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i); PdfContentByte pdfPageContents;

我正在尝试使用itextsharp 5.1.2.0在pdf文件中添加watermak

我希望水印位于页面中心,呈45°角,在这些线周围有一个边框

这是我的密码:

 for (int i = 1; i <= reader.NumberOfPages; i++)
{
    iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i);

    PdfContentByte pdfPageContents;
    pdfPageContents = pdfStamper.GetOverContent(i);

    pdfPageContents.BeginText();
    PdfGState gstate = new PdfGState();
    gstate.FillOpacity = 0.4f;
    gstate.StrokeOpacity = 0.4f;
    pdfPageContents.SaveState();
    pdfPageContents.SetGState(gstate);

    BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, false);

    pdfPageContents.SetRGBColorFill(255, 0, 0);

    double radians = Math.Atan2(pageSize.Height, pageSize.Width);
    float textAngle = radians * (180 / Math.PI);

    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Phrase 1 This is Phrase 2 and must be centered below phrase 1" , pageSize.Width / 2, pageSize.Height / 2, textAngle);
    //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Phrase 1", pageSize.Width / 2, pageSize.Height / 2, textAngle);
    //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This is Phrase 2 and must be centered below phrase 1", pageSize.Width / 2 + 20 , pageSize.Height / 2 - 20, textAngle);
}

for(int i=1;i基本上,我为我的项目所做的工作如下……这里字体大小和样式是变量……同时,llx、lly、urx、ury是对应位置和大小的变量。在对齐变量中,您可以轻松设置对齐。。。。
对于不透明度,您的代码可以正常工作(您可以添加状态选项)


您可以添加一个变量lineHeight并在该变量中指定行的高度..然后可以为下一行添加该变量..这在iText 7中更加容易。iText 5.2.1.0从2011年8月开始生效,不再受支持。谢谢!我使用您提供的代码完成了此操作,并根据我的要求对其进行了修改。
             Dim Font = New Font(arial, FONT_SIZE, STYLE, iTextSharp.text.Color.BLACK )


            dim text = GetRowValue(row, "CONTROL_MAP")
            Dim ct As ColumnText = New ColumnText(pdf_cb)
            ct.SetSimpleColumn(LLX, LLY, URX, URY, FONT_SIZE, ALIGNMENT)
            ct.SetText(New Paragraph(0, text, Font))
            ct.Go()