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.

Fri Sep 06, 2024 3:30 pm

Have been having issues with Spire.PDF for .NET version 8.9.16 where I get an "Evaluation Warning" when converting xps files to pdfs in child processes spun off the main application. It should be noted that I updated to the latest version out and still got this problem. It seems that the license is applied properly in the main executable, but when the conversion is initiated in the child process I get the Evaluation Warning.

In order to minimize the number of spire references throughout the application, I refactored to consolidate the Spire pdf functionality into a single project. In that project we have embedded the license.elic.xml file as an embedded resource. Here is the class it uses to obtain the license and create the pdf documents.
Code: Select all
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Xml.Linq;
using Spire.License;
using Spire.Pdf;

namespace Utilities.Exports.Pdf.SpirePdf
{
    /// <summary>
    /// Used to obtain a licensed Spire PDF <see cref="PdfDocument"/>
    /// </summary>
    public static class PdfDocumentFactory
    {
        static PdfDocumentFactory()
        {
            string resourceName = "PenLink.Utilities.Exports.Pdf.SpirePdf.license.elic.xml";

            string licenseKey;

            // There is a stream based license loader for Spire PDF, but it doesn't read the stream immediately, but
            // later on.  Meaning you need to leave the stream open-ended.  Instead, read the
            // license key from the file and use that variant of license loading.
            Assembly assembly = Assembly.GetExecutingAssembly();
            using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
            {
                XDocument licenseDocument = XDocument.Load(resourceStream);
                licenseKey = licenseDocument.Root.Attribute("Key")
                    ?.Value;

                Debug.Assert(licenseKey is not null, "Unable to find the license key inside the license file.");
            }

            LicenseProvider.SetLicenseKey(licenseKey);
        }

        public static PdfDocument Create()
            => new PdfDocument();

        public static void EnsureInitialized()
        {
            // Do nothing.  The act of calling this method ensures the static constructor is executed.
        }
    }
}


I utilize this code in another static class in the same project to generate pdf from xps. Here's that code

Code: Select all
using System;
using System.Threading;
using Utilities.Exports.Pdf.SpirePdf;
using Spire.Pdf;

namespace Utilities.Exports.Pdf
{
    /// <summary>
    /// General utility for PDF documents.
    /// </summary>
    public static class PdfUtility
    {
        public static void GeneratePdfFromXps(
              string xpsPath
            , string pdfPath
            , CancellationToken cancellation
            , Action<CancellationToken> midProgressAction = null
            )
        {
            cancellation.ThrowIfCancellationRequested();

            using (PdfDocument doc = PdfDocumentFactory.Create())
            {
                cancellation.ThrowIfCancellationRequested();
                doc.LoadFromXPS(xpsPath);

                midProgressAction?.Invoke(cancellation);

                cancellation.ThrowIfCancellationRequested();
                doc.SaveToFile(pdfPath, FileFormat.PDF);
            }

            cancellation.ThrowIfCancellationRequested();
        }

        public static void MergePdfs(string[] inputFiles, string outputFile)
        {
            // Since this doesn't invoke the PdfDocumentFactory to create the document, we still need to ensure licensing.
            PdfDocumentFactory.EnsureInitialized();

            PdfDocument.MergeFiles(inputFiles, outputFile);
        }
    }
}


The issue I've been noticing is with the first method GeneratePdfFromXps(), but I would imagine the issue would also exist for the second method.

I have confirmed through debugging that the issue is not with loading the in the key.
Seems that our license is develop OEM subscription, so as I understood we should be able get license for multiple processes.

How can I apply license properly and get rid of the evaluation warning?

penlink_plit
 
Posts: 2
Joined: Mon Nov 06, 2023 8:42 pm

Mon Sep 09, 2024 9:34 am

Hello,

Thanks for your inquiry.I used your license to convert a XPS document, and the result is normal. I directly used the key from your license file, as shown in the screenshot below.
As for your situation, I suspect that the key value obtained is incorrect or failed. You can try passing the key directly like my testing. If there are still issues, you can send a project that can reproduce your problem via email( support@e-iceblue.com )to us.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Mon Sep 09, 2024 3:54 pm

I had already tried applying the license key explicitly like you showed and the issue still persists.

To clarify, the license is being properly applied in our main application, which I'll call MainApplication.exe, but when we launch a child process, that I'll call MainApplication.ChildProcess.exe, from the main app, the license IS NOT applied properly. Is there some sort of whitelist for process names that is checked when we attempt to obtain our license? Could that be why we fail to obtain it for the child process but it's successful for the parent?

Should be noted that MainApplication.exe and MainApplication.ChildProcess.exe are not the real names of these processes, but the point is the same.

penlink_plit
 
Posts: 2
Joined: Mon Nov 06, 2023 8:42 pm

Tue Sep 10, 2024 10:09 am

Hello,

Thank you for your feedback. I have sent my testing project to your via email for testing. After testing on your side, you can provide us with the results via email. Thank you in advance.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF

cron