46,174 questions
Ask the author or community at https://github.com/topics/pdfsharp
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do I add my pdf file on my computer to the code below (to add watermark to pdf) I use pdfshap sdk
// Variation 1: Draw a watermark as a text string.<font></font>
<font></font>
// Get an XGraphics object for drawing beneath the existing content.<font></font>
var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);<font></font>
<font></font>
// Get the size (in points) of the text.<font></font>
var size = gfx.MeasureString(watermark, font);<font></font>
<font></font>
// Define a rotation transformation at the center of the page.<font></font>
gfx.TranslateTransform(page.Width / 2, page.Height / 2);<font></font>
gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);<font></font>
gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);<font></font>
<font></font>
// Create a string format.<font></font>
var format = new XStringFormat();<font></font>
format.Alignment = XStringAlignment.Near;<font></font>
format.LineAlignment = XLineAlignment.Near;<font></font>
<font></font>
// Create a dimmed red brush.<font></font>
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));<font></font>
<font></font>
// Draw the string.<font></font>
gfx.DrawString(watermark, font, brush,<font></font>
new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),<font></font>
format);<font></font>
Ask the author or community at https://github.com/topics/pdfsharp