简体   繁体   English

如何在中间底部添加水印

[英]How to Add Watermark in The Middle Bottom

I'm trying to add a watermark in a pdf file in the center bottom of pdf file .. I tried many ways but i did not figure out how it's works exactly to select the location of watermark. 我正在尝试在pdf文件底部的pdf文件中添加水印。我尝试了多种方法,但我不知道选择水印位置的确切方法。

Anyway here is the code: 无论如何,这里是代码:

string filepath = @"~/Images/logo-01.png";
                iTextSharp.text.Image pageIn = iTextSharp.text.Image.GetInstance(Server.MapPath(filepath));


                pageIn.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
                pageIn.ScaleToFit(150, 150);
                pageIn.Alignment = iTextSharp.text.Image.UNDERLYING;
                pageIn.SetAbsolutePosition((PageSize.A4.Width - pageIn.ScaledWidth) / 2, (PageSize.A4.Height - pageIn.ScaledHeight) / 10);

Again i want to make the watermark position in the max center bottom of the page. 再次,我想使水印位置在页面的最大中心底部。

You may try using GroupDocs.Watermark for .NET that allows controlling the horizontal and vertical position of the watermark in the documents. 您可以尝试使用.NET的GroupDocs.Watermark,它可以控制文档中水印的水平和垂直位置。 This is how you can add watermark at the bottom of the pages in a PDF document: 您可以通过以下方法在PDF文档的页面底部添加水印:

using (PdfDocument doc = Document.Load<PdfDocument>("D:\\sample.pdf"))
{
        // Add text watermark
        TextWatermark watermark = new TextWatermark("Protected Document", new Font("Arial", 8));
        watermark.HorizontalAlignment = HorizontalAlignment.Center;
        watermark.VerticalAlignment = VerticalAlignment.Bottom;
        doc.AddWatermark(watermark);

        // Add image watermark
        ImageWatermark imageWatermark = new ImageWatermark("D:\\watermark.png");
        imageWatermark.HorizontalAlignment = HorizontalAlignment.Center;
        imageWatermark.VerticalAlignment = VerticalAlignment.Bottom;
        doc.AddWatermark(imageWatermark);

        // Save document
        doc.Save("D:\\output.pdf");
}

Disclosure: I work as a Developer Evangelist at GroupDocs. 披露:我是GroupDocs的一名开发人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM