Watermark Stamp in PDF for .Net 6 Error on Linux Kernel

Exception while executing function: AssembleReport The type initializer for ‘Gdip’ threw an exception. System.Drawing.Common is not supported on non-Windows platforms. See Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn for more information.

Is there an Aspose version that does not have this dependency and will work on Linux kernel?

@brooksclarkpwc,

What version are you using?

I have seen this issue before and I know that the dependency has been removed in the latest version.

Can you try version 23.2 and let me know?

It was 22.12. Tried 23.2 and get the same error.

@brooksclarkpwc,

Can you provide the Code Snippet and all the input files please.

WORKS ON WINDOWS OS, FAILS ON LINUX:

using Aspose.Pdf.Facades;
using Aspose.Pdf.Drawing;
using Aspose.Words;
using Aspose.Words.Layout;
using Azure.Storage.Blobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

 //SET DRAFT WATERMARK AND SAVE THE DOC
using (var pdfDocument = new Aspose.Pdf.Document(sourceStream))
{
   MakeNotEditable(pdfDocument);

   using (var watermarkStream = await watermarkBlobClient.OpenReadAsync())
   {
           var fileStamp = new PdfFileStamp();
          fileStamp.BindPdf(pdfDocument);
           // Create stamp
          var stamp = new Stamp();
          stamp.BindImage(watermarkStream);
          stamp.SetOrigin(-180, -50);
          stamp.Rotation = 45.0F;
          stamp.IsBackground = false;

           pdfDocument.Flatten();

           // Add stamp to PDF file
           fileStamp.AddStamp(stamp);
           using (var writeStream = await reportDocBlobClient.OpenWriteAsync(true))
           {
               fileStamp.Save(writeStream);
           }
           fileStamp.Close();
    }
}


 private static void MakeNotEditable(Aspose.Pdf.Document pdfDocument)
        {
            //Forbid all privileges on the document
            var privilege = DocumentPrivilege.ForbidAll;
            privilege.AllowPrint = true;
            privilege.AllowCopy = true;
            var fileSecurity = new PdfFileSecurity();
            fileSecurity.BindPdf(pdfDocument);
            fileSecurity.SetPrivilege(privilege);
        }

@brooksclarkpwc,

you are missing then input files(the image and the pdf documents), please.

DraftWatermark.png (5.6 KB)

Any pdf will work.

@brooksclarkpwc,

Please remove Aspose.PDF and install Aspose.Pdf.Drawing from NuGet instead.

This does not have a dependency on System.Drawing.Common.

This nugget:

Then how do I open the document?

watermark.pdf (134.2 KB)

@brooksclarkpwc,

The same way, This is a library for non windows environments that haves issues with System.Drawing.Common

You said to remove Aspose.PDF, so I can’t open it the same way.

@brooksclarkpwc,

You absolutly can. The namespaces are the same. You dont even have to change anything but this:

See where the document class is coming from:

You have to at least try it before saying you cannot.

I’m using Aspose.Total. Just so I don’t get scolded again…you are saying to replace Aspose.Total with each of the individual packages that we use, and use Aspose.Pdf.Drawing instead of Aspose.Pdf

Are you using nugget to get your DLLs? or do you download them from a zip file?

Your Aspose.total license show work on the nugget version of Aspose.Pdf.Drawing.

EDIT:
Can you try to only use Aspose.Pdf.Drawing to manipulate PDF?
Does it throw the error when using the document object from that Assembly?
Does the license work?

Those question are important. If any of those fails let me know.

I dont think you have to replace anything. You use the classes from the Aspose.Pdf.Drawing instead of total. In case you are using Aspose.Total for other things not related to PDFs.

I have swapped out the nuget packages and run locally (windows). Pushing out to my server (linux) now…

That solved the problem. Thanks!

@brooksclarkpwc,

Good to know.

Only so I understand how it it is. Did you had to remove Aspose.Total? or you just added the new Assembly PDF.Drawing and that was it?

Removed Aspose.Total and replaced with Aspose.Words and Aspose.Pdf.Drawing

1 Like