Print Page | Close Window

How to get quickpdf to work on azure?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3955
Printed Date: 28 Mar 24 at 11:01AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: How to get quickpdf to work on azure?
Posted By: geauxOnAndOn
Subject: How to get quickpdf to work on azure?
Date Posted: 11 Oct 21 at 8:58PM
I have successfully gotten both the dll and the activeX to work on my local machine. However when I push to azure a totally dismal story. The dll will load but will not unlock. The activeX will not create comObject. 

My environment is Azure Web App, Core 5 and I am developing using the Code editor.  It is a development instance but not B1 plan, not shared, 64 bit. The key is a trial key. 

This is the entries I included in the the csproj. I confirmed azure deployment includes them in the root with the other compiled dlls and I  have even confirmed they are accessible by loading them into memory. 

  <ItemGroup>
    <None Update="DebenuPDFLibrary64DLL1811.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DebenuPDFLibraryDLL1811.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DebenuPDFLibrary64AX1811.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DebenuPDFLibraryAX1811.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

This is code I use with the dll that works fine locally. On azure it will create an object but instanceId is 0 and of course it will not unlock.

      public static string pdfKey = "br549";

        public static PDFLibrary newPdfLib()
        {
            var pdfLib = new PDFLibrary("./DebenuPDFLibrary64DLL1811.dll");
            var result = pdfLib.UnlockKey(pdfKey);
            return pdfLib;

        }

        public static void closePdfLib(PDFLibrary pdfLib)
        {
            pdfLib.ReleaseLibrary();
        }


This is code I am using for ActiveX which doesn't create a new object of the class.

   public class PDFLibraryAx
    {
        private object comObject;
        private Type comType;

        public static string pdfKey = "br549";
        public static bool unlocked = false;
        public static int renderer = 0;
        public static string error = "";

        public PDFLibraryAx()
        {
            try
            {
                comType = null;
                if (IntPtr.Size == 4)
                {
                    comType = Type.GetTypeFromProgID("DebenuPDFLibraryAX1811.PDFLibrary");
                }
                if (IntPtr.Size == 8)
                {
                    comType = Type.GetTypeFromProgID("DebenuPDFLibrary64AX1811.PDFLibrary");
                }
                if (comType != null)
                {
                    comObject = Activator.CreateInstance(comType);
                }
                else
                {
                    error = "comType is null";
                }
            }
            catch (Exception ex)
            {
                error = "bombs at com " + ex.Message;
            }
        }
}


this is the code that creates the activeX object. 

var pdfLib = new Debenu.PDFLibraryAx();
if (pdfLib is object)
{
Debenu.PDFLibraryAx.unlocked = pdfLib.UnlockKey(Debenu.PDFLibraryAx.pdfKey) == 1;
Debenu.PDFLibraryAx.renderer = pdfLib.SelectRenderer(2);
if (Debenu.PDFLibraryAx.unlocked)
{
var ret = pdfLib.LoadFromVariant(fileBytes, Debenu.PDFLibrary.pdfKey);

pdfLib.AddFreeTextAnnotation(100, 200, 300, 30, "Your mama don't dance", 0, 0);
pdfLib.AddFreeTextAnnotation(100, 160, 300, 30, "and your daddy don't rock and roll", 0, 0);
fileBytes = pdfLib.SaveToVariant();
}

pdfLib.ReleaseLibrary();
pdfLib = null;
}
else
{
// "bombs in data, not an object ";
}
}
catch (Exception ex)
{
// "bombs in data " + ex.Message;
}


Hopefully some brainiac, which I obviously am not, will pipe up and save me from this pain. I am shocked searching this site there was only one thread about azure. I had read that debenu will not work on azure because of GDI+ but I haven't gotten that far. I am hopeful if that is an issue using some of the other renderers available will solve that problem. I have used debenu in the past and really like it. Really want it to work.





Replies:
Posted By: geauxOnAndOn
Date Posted: 12 Oct 21 at 2:23PM
i guess i gotta be my own brainiac and fortune smiled upon me after I paid the pain price of trial and error. 

The problem was with loadLibrary. I changed the declaration to this.

    [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);

changed the dll constructor to this

          dllHandle = LoadLibrary(dllFileName);
            if (dllHandle == IntPtr.Zero) { 
            var error = Marshal.GetLastWin32Error(); }
            else
            {
 
last error returned 126 which means it could not find the dll I passed in.

this solved the problem

             var full = Path.GetFullPath(dllName64);
             var  pdfLib = new PDFLibrary(full);

Seems on my local machine kernel32 had no problem resolving a relative path but the azure server could not. So I sent loadLibrary the full path to the debenu dll and it worked. 

Onward to the next coding disaster, this one is history.
    







Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk