# Error using PDF sharp in BPM

**URL:** <https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683>\
**Category:** Epicor ERP 10\
**Tags:** pdf, bpm\
**Created:** [July 10, 2024, 9:07pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683 "2024-07-10T21:07:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgeels](https://www.epiusers.help/user_avatar/www.epiusers.help/tgeels/32/48395_2.png) [@tgeels](https://www.epiusers.help/u/tgeels)\
**Post date:** [July 10, 2024, 9:07pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/1 "2024-07-10T21:07:42Z")

</div>

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

```auto
        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);

```

 ![image](https://www.epiusers.help/uploads/default/original/3X/3/4/34f1c8b65f07ee8d492322a288a791cec74ff357.png)

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [July 10, 2024, 9:08pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/2 "2024-07-10T21:08:38Z")

</div>

Pop the code in here so we can get some deets.

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [July 10, 2024, 9:09pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/3 "2024-07-10T21:09:24Z")

</div>

Apparently I was too quick.

![Too Fast Tempo GIF by DrSquatchSoapCo](https://media2.giphy.com/media/yTQT8Fz5rDYW9PXiNw/giphy.webp?cid=e90edba36vkjkvy04zmlbba6nf05dbzqcjy2utbkbjpz9oya&ep=v1_gifs_search&rid=giphy.webp&ct=g)

---

<div class="post-metadata">

**Author:** ![Randy](https://www.epiusers.help/user_avatar/www.epiusers.help/randy/32/51539_2.png) [@Randy](https://www.epiusers.help/u/Randy)\
**Post date:** [July 10, 2024, 9:11pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/4 "2024-07-10T21:11:23Z")

</div>

You’re just too fast.  
 ![Looney Tunes Running GIF by Looney Tunes World of Mayhem](https://media1.giphy.com/media/2dbnhlCH2JhwdI2gHp/giphy.webp?cid=e90edba3elcadlnxuosh1mxpwi2r8qysk5xqycj1ebkoly7a&ep=v1_gifs_search&rid=giphy.webp&ct=g)

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [July 10, 2024, 9:13pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/5 "2024-07-10T21:13:47Z")

</div>

Try using a more modern version of that library that references the newer System.Drawing.

---

<div class="post-metadata">

**Author:** ![Olga](https://www.epiusers.help/letter_avatar_proxy/v4/letter/o/57b2e6/32.png) [@Olga](https://www.epiusers.help/u/Olga)\
**Post date:** [July 10, 2024, 9:15pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/6 "2024-07-10T21:15:05Z")

</div>

With 10.2.7? I doubt that, maybe it should be opposite

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [July 10, 2024, 9:17pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/7 "2024-07-10T21:17:41Z")

</div>

Didn’t see that.

But surely not old as 2.0.0.0 ?

---

<div class="post-metadata">

**Author:** ![tgeels](https://www.epiusers.help/user_avatar/www.epiusers.help/tgeels/32/48395_2.png) [@tgeels](https://www.epiusers.help/u/tgeels)\
**Post date:** [July 10, 2024, 9:44pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/8 "2024-07-10T21:44:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![kve](https://www.epiusers.help/user_avatar/www.epiusers.help/kve/32/76150_2.png) [@kve](https://www.epiusers.help/u/kve)\
**Post date:** [July 11, 2024, 12:48am UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/9 "2024-07-11T00:48:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kve](https://www.epiusers.help/user_avatar/www.epiusers.help/kve/32/76150_2.png) [@kve](https://www.epiusers.help/u/kve)\
**Post date:** [July 11, 2024, 12:55am UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/10 "2024-07-11T00:55:34Z")

</div>

Here’s the relevant bit of the function we used to add watermarks using pdfSharp.

```auto
// Get bkg image, set properties
	var FormImage = XImage.FromFile ( @"C:\Path\To\Pdf.pdf" );
	var width = FormImage.PixelWidth * 72 / FormImage.HorizontalResolution;
	var height = FormImage.PixelHeight * 72 / FormImage.VerticalResolution;

// Draw watermark to SSRS report
	var source = PdfReader.Open ( pdfName );
	var gfx = XGraphics.FromPdfPage( source.Pages[0], XGraphicsPdfPageOptions.Prepend );

	gfx.DrawImage ( FormImage, 0, -180, width, height );
	source.Save ( pdfName );

```

---

<div class="post-metadata">

**Author:** ![tgeels](https://www.epiusers.help/user_avatar/www.epiusers.help/tgeels/32/48395_2.png) [@tgeels](https://www.epiusers.help/u/tgeels)\
**Post date:** [July 11, 2024, 4:31pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/11 "2024-07-11T16:31:09Z")

</div>

Thank you. I was going to add the watermark as an image which would work, but I was having issues getting it transparent.

---

<div class="post-metadata">

**Author:** ![kve](https://www.epiusers.help/user_avatar/www.epiusers.help/kve/32/76150_2.png) [@kve](https://www.epiusers.help/u/kve)\
**Post date:** [July 11, 2024, 4:46pm UTC](https://www.epiusers.help/t/error-using-pdf-sharp-in-bpm/116683/12 "2024-07-11T16:46:05Z")

</div>

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.
