logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Paul Rayman  
#1 Posted : Tuesday, January 5, 2016 6:53:21 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 779

Thanks: 1 times
Was thanked: 97 time(s) in 95 post(s)
Question:
I having issues getting the Pdfium.Net library to locate the pdfium.dll in an MVC web project.
I've followed your installation instructions (marking both x86 and x64 versions as Copy to Output Directory=Copy always) and it works fine in a class library and WinForms application. The web site cannot seem to find it though. I've verified the pdfium.dll is copied to the bin folder along with the Patagames.Pdf.dll and have even tried adding pdfium.dll manually in different spots. Do you have any other suggestions?

Answer:
This is happens because the Web application is running in a IIS's working directory, unlike the classical apps. In consequence of that, the LoadLibrary function can't find the pdfium.dll during initialization process.
You can specify the full path to pdfium.dll through specificPath parameter into Initialize method to solve this problem.

Code:

public void InitWebApp()
{
    //Gets the location of the current assembly as URI
    string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
    UriBuilder uri = new UriBuilder(codeBase);
    string assemblyPath = Uri.UnescapeDataString(uri.Path);
    //Gets directory for assembly
    var base_path = System.IO.Path.GetDirectoryName(assemblyPath);
    //Combine path to Pdfium.dll
    var path = System.IO.Path.Combine(base_path, @"x86\pdfium.dll");
    //Initialize library
    PdfCommon.Initialize(null, path);
}
thanks 1 user thanked Paul Rayman for this useful post.
shifra on 9/18/2017(UTC)
Paul Rayman  
#2 Posted : Monday, January 22, 2018 12:15:33 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 779

Thanks: 1 times
Was thanked: 97 time(s) in 95 post(s)
Initialize method search pdfium.dll at following locations:
1. Specific path (which you pass to Initialzie method)
2. [Current directory]\[x64|x86]\pdfium.dll depends on target platform
3. [Current directory]\pdfium.dll
4. [CodeBase of Pdfium.Patagames.dll]\[x64|x86]\pdfium.dll depends on target platform
5. [CodeBase of Pdfium.Patagames.dll]\pdfium.dll

In the 3.16.2704 version were added following search paths
6. [AppDomain base directory]\[x64|x86]\pdfium.dll depends on target platform
7. [AppDomain base directory]\pdfium.dll
8. [AppDomain base directory]\Bin\[x64|x86]\pdfium.dll depends on target platform
9. [AppDomain base directory]\Bin\pdfium.dll

You may turn on logging to see where exactly the engine search for library in your case.
To do that download latest version and modify you app.config file as below:

Code:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="Patagames.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

  <system.diagnostics>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="PatagamesOutput.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
  
  <applicationSettings>
    <Patagames.Properties.Settings>
      <setting name="LogLevel" serializeAs="String">
        <value>1</value>
      </setting>
    </Patagames.Properties.Settings>
  </applicationSettings>
</configuration>




TheImprover  
#3 Posted : Wednesday, May 23, 2018 3:53:46 AM(UTC)
TheImprover

Rank: Newbie

Groups: Registered
Joined: 5/22/2018(UTC)
Posts: 3
United Kingdom

Also, per this thread (link), the server may be running in 64 bit mode. My code to get to the correct version of the library on a web server is as follows:

Code:

string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
path = Uri.UnescapeDataString(uri.Path);
string base_path = Path.GetDirectoryName(path);
base_path = Path.GetFullPath(Path.Combine(base_path, "..\\"));
base_path = path = Path.Combine(base_path, "Resources");
string pdfiumFolder = "PDFium";
pdfiumFolder += Environment.Is64BitProcess ? "64" : "32";
base_path = Path.Combine(base_path, pdfiumFolder);
path = Path.Combine(base_path, @"pdfium.dll");

PdfCommon.Initialize(null, path);

Edited by moderator Saturday, July 7, 2018 12:11:15 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.