Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 27, 2019 8:51 am

Hi All,
I am in the process of evaluating Spire.PDF for my customer. As an experiment I was just using the watermark functionality.

Structure of the solution

    Class library (.NET Standard 20 )
    EXE (.NET 461)

Class library
The class library project has the following class and Nuget package reference to "Spire.PDF 5.8.7"
Code: Select all
    public class SpireWrapper
    {
        public void StampFile(string fileIn, string fileOut, string waterMark)
        {
            using (var doc = new Spire.Pdf.PdfDocument(fileIn))
            {
                foreach (PdfPageBase page in doc.Pages)
                {
                    PdfTilingBrush brush
                       = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
                    brush.Graphics.SetTransparency(0.3f);
                    brush.Graphics.Save();
                    brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
                    brush.Graphics.RotateTransform(-45);
                    brush.Graphics.DrawString(waterMark,
                        new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0,
                        new PdfStringFormat(PdfTextAlignment.Center));
                    brush.Graphics.Restore();
                    brush.Graphics.SetTransparency(1);
                    page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
                }
                doc.SaveToFile(fileOut);
            }
        }

        public void ReadAllText1(string fileIn)
        {
            using (var doc = new Spire.Pdf.PdfDocument(fileIn))
            {
                foreach (PdfPageBase page in doc.Pages)
                {
                    var allText=page.FindAllText();
                }
            }

        }
    }


Console EXE project
This project has the following class

Code: Select all
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var wrapper = new ClassLibrary1.SpireWrapper();
                string file = "Brainjuicer100308flash.pdf";
                string fileIn = file;
                string fileOut = "result.pdf";
                wrapper.StampFile(fileIn, fileOut, "Watermark message");

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }


Results

During execution the EXE throws the error

Code: Select all
System.IO.FileLoadException: Could not load file or assembly 'Spire.Pdf, Version=5.8.7.2320, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Spire.Pdf, Version=5.8.7.2320, Culture=neutral, PublicKeyToken=663f351905198cb3'
   at ClassLibrary1.SpireWrapper.StampFile(String fileIn, String fileOut, String waterMark)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\saurabhd\MyTrials\Apex-Stuff\Apex-issues\APEX-1766-Watermark\WaterMark\ConsoleApp1\Program.cs:line 20


Workaround

If the class library is changed to .NET Framework 461 then there are no problems. However this becomes problematic because we would like to target all our class libraries for .NET Standard 20. Because of this we now have to maintain two sets of class libraries with shared code. It works, but not desirable.

As per Microsoft's documentation (I was not allowed to post the MSDN url)
.NET Standard 20 and .NET Framework 461 should be compatible.

Any suggestions?

saurabhd
 
Posts: 6
Joined: Tue Aug 27, 2019 8:37 am

Tue Aug 27, 2019 10:40 am

Hi,

Thanks for your inquiry.
Please also add Spire.PDF Standard dlls in "Console EXE" project, then there won’t be the "System.IO.FileLoadException". But I found the program will throw another exception "MethodAccessException". I have logged this new issue into our bug tracking system, once there is any progress, we will inform you.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Aug 27, 2019 11:43 am

Thanks for the quick reply. This is really appreciated. What do you imply by "add Spire.PDF Standard DLLs" in Console EXE?

Do you want me to add a NUGET reference in the Console EXE ?
OR
Do you want me to physically copy over the .NET Standard assemblies from the USER\.nuget\packages\spire.pdf\5.8.7\lib\netstandard2.0 folder into the Bin of the Console EXE?

Thanks,
Sau

saurabhd
 
Posts: 6
Joined: Tue Aug 27, 2019 8:37 am

Wed Aug 28, 2019 9:53 am

Hi,

Thank for your reply.
I am afraid you cannot install the Spire.PDF standard dlls via NuGet. Since the framework of "Console EXE" project is .net framework, but the dlls you need to add are .net standard dlls. If you add the dlls via NuGet, the .net framework dlls will be added into the project automatically.
Please manually reference(not just copy the dlls into BIN folder) the .NET standard dlls from the folder USER\.nuget\packages\spire.pdf\5.8.7\lib\netstandard2.0 into "Console EXE" project.
Or you could download Spire.PDF Pack(Hot Fix) Version:5.8.7 from our website then manually reference the .NET standard dlls from the folder ……\……\spire.pdf_5.8.7\BIN\netstandard2.0 into "Console EXE" project.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Fri Aug 30, 2019 9:48 am

Hi,

Thanks for your patient waiting.
Glad to tell you that the previous issue has been fixed in Spire.PDF Pack(Hot Fix) Version:5.8.16. Welcome to download and test it from the following links.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
NuGet link: https://www.nuget.org/packages/Spire.PDF/5.8.16

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.PDF