在图像下方但在 C# 的打印区域内添加水印

Add watermark below image but within print area in C#

我正在尝试在我的 windows 表单中的 TIFF 图像下方插入文本水印,非常感谢任何人的帮助。我有一个打印按钮,可以检索图像,将其缩小,然后根据我的边距,相应地放置图像以进行打印。我想在图像打印之前添加一个额外的部分,我在图像下方添加了一个文本水印(在本例中为日期戳)。

我试过调整边距,但这只会增加(或减少,具体取决于数字设置)图像比例,但不会增加我想添加水印的额外空间。以下是我目前所拥有的代码:

    protected void PrintPage(object sender, PrintPageEventArgs e)
    {
        if (this.Image == null)
        {
            e.Cancel = true;
            return;
        }
        //ADD TIME STAMP WATERMARK
        string watermark = "DATE ISSUED:  " + String.Format("{0:MM/dd/yyyy}", System.DateTime.Now.Date); 
        System.Drawing.Graphics gpr = Graphics.FromImage(Image);
        System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);
        Font font = new System.Drawing.Font("Arial", 55, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);

        SizeF size = e.Graphics.MeasureString(watermark, font);

        float x = 0;
        float y = Image.Height-size.Height;
        RectangleF printArea = new RectangleF(x, y, size.Width, size.Height);           
        gpr.DrawString(watermark, font, brush, printArea); 

        e.Graphics.DrawImage(this.Image, e.MarginBounds);

    }

我在我的App.config中设置的e.MarginBounds的值包括以下值:Left=70,Right=90,Top=190;底部=475。所有打印输出都将在 Letter 8 1/2 x 11 尺寸的纸张上以纵向样式打印。

我可以在图片上方的任何位置显示水印,但我希望将其放在下方。当我调整 y 坐标时,它恰好在图像下方,当我打印时,我假设它在打印区域之外,因此水印不会打印在页面上(它只显示图像)。

我很感激任何人在这方面的帮助,因为我一直在为此绞尽脑汁,但没有运气。

你不是在图片下方打印文字吗?我想你想在 y=Image.Height + e.MarginBounds.Top 和 x=e.MarginBounds.Left

开始打印

这将在图像下方的空白处打印一个左对齐的标签。

更新:有效:

y=-size.Height + e.MarginBounds.Bottom; 
x = e.MarginBounds.Left; 
e.Graphics.DrawImage(Image, e.MarginBounds); 

// note the change.  Using e.graphics instead of gpr below
e.Graphics.DrawString(watermark, font, brush, printArea);