Hello,
I’m trying to add a watermark to a pdf that we are attaching in Epicor in a Method Directive. I’m attempting to use PDF sharp to do so. I’m getting an error saying FontFamily is defined in an assembly that is not referenced.
I’ve tried adding a using statement referencing System.Drawing. I’ve added System.Drawing.Common as reference. Not sure if anyone has any ideas on how to get this error to go away. I’ve also tried the same exact code in a customization and it works with no errors. Here is my code below, it is the XFont line that has the error
PdfDocument document = PdfReader.Open(mytempfile, PdfDocumentOpenMode.Modify);
// Create font and brush for the watermark
XFont font = new XFont("Arial",40,XFontStyle.Bold);//"Arial", 40, XFontStyle.Bold);
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0)); // Semi-transparent red
// Add watermark to each page
foreach (PdfPage page in document.Pages)
{
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
gfx.TranslateTransform(page.Width / 2, page.Height / 2);
gfx.RotateTransform(-45);
gfx.DrawString("Watermark", font, brush, 0, 0, XStringFormats.Center);
}
document.Save(mytempfile);
Yep, it appears I’m using an old version of pdf sharp (version 1.50). I will try using a newer version and see if that fixes the error. It does make me wonder why the same code works in a customization… Appreciate the quick responses!
We did this at my last job, I’m fairly certain we were able to use the same version of PDFSharp on 10.2.700 and 2023.1. I’ll get version numbers for you in a minute, and share the code we’re using for the watermark.
Oh I see. I think we just made the source image more transparent to get around that. I did not try the way you were doing it, and that wouldn’t work if the watermark is not static.