0

I have been running in circles trying to figure out how to get my Django app to recognise the trial version of PDFNet:

https://pypi.python.org/pypi/PDFTron-PDFNet-SDK-for-Python/5.7

I tried adding the files to my ~/usr/bin directory, I tried dropping them into my virtualenv's bin directory. Neither has worked. I have read all the documentation i can find. I am too new of a Python developer to look at this package and know how to install it and utilize it in my project.

Please help!

update I attempted to create an app folder, and list this component as an app in the app list, but when I run the code to start the application, I get the following error:

Library not loaded: @rpath/libPDFNetC.dylib

I placed all of the lib files into this folder within my project:

  • __init.py (empty)
  • _PDFNetPython.so
  • libPDFNetC.dylib
  • PDFNetPython.py
  • PDFNetRuby.bundle

I used the following import code at the top of the py file I was attempting to use the component on:

import site
site.addsitedir("../pdfnetc")
from pdfnetc.PDFNetPython import *

I put the lib files into a app folder named pdfnetc. once I had this, the import statements were no longer listed as unfound by pycharm.

here is the stack trace:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2217, in <module>
    globals = debugger.run(setup['file'], None, None)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1643, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/ntregillus/myapp/manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/ntregillus/myapp/statements/models.py", line 12, in <module>
    from statements.managers import StatementTemplateManager, StatementManager
  File "/Users/ntregillus/myapp/statements/managers.py", line 8, in <module>
    from statements.utils import render_to_pdf, StatementContextBuilder
  File "/Users/ntregillus/myapp/statements/utils.py", line 23, in <module>
    from pdfnetc.PDFNetPython import *
  File "/Users/ntregillus/myapp/pdfnetc/PDFNetPython.py", line 28, in <module>
    _PDFNetPython = swig_import_helper()
  File "/Users/ntregillus/myapp/pdfnetc/PDFNetPython.py", line 24, in swig_import_helper
    _mod = imp.load_module('_PDFNetPython', fp, pathname, description)
ImportError: dlopen(/Users/ntregillus/myapp/pdfnetc/_PDFNetPython.so, 2): Library not loaded: @rpath/libPDFNetC.dylib
  Referenced from: /Users/ntregillus/myapp/pdfnetc/_PDFNetPython.so
  Reason: image not found
Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91
  • note: I am able to run the test files via the shell scripts. it is just figuring out how to integrate the dependency into my current project is the problem – Nathan Tregillus May 01 '15 at 15:51

4 Answers4

2

python -m pip install PDFNetPython3 home page link here

keca13
  • 52
  • 6
1

Below are steps to install the PDFNet module:

  1. Download the Python and Ruby prebuilt binaries. Make sure you download the right architecture for your Python interpreter.
  2. Extract the downloaded zip file and navigate to it.
  3. Navigate to the /PDFNetC/Lib directory of the Python SDK download and execute:
> chmod a+x fix_rpaths.sh
./fix_rpaths.sh
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
neydoo
  • 13
  • 3
0

I am not knowledgable of django, but take a close look at the sample py files that are in the SDK. For example, take a look at PDFNetC/Samples/AddImageTest/PYTHON folder. In there is a .py file, and look at the first 4 lines of code, they indicate what needs to load.

Please note that you need all the files that are in PDFNetC/Lib folder, including the PDFNetC.dll file.

If this does not help, please post the exact (first) error message you get.

Ryan
  • 2,473
  • 1
  • 11
  • 14
  • added another attempt I made, and the error message – Nathan Tregillus May 01 '15 at 14:53
  • You should take a look at the answer by Caleb Shay to this question. http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib I think this will help you solve why the so cannot load. Also, double check the permissions on those files. – Ryan May 01 '15 at 18:11
  • Unfortunately, Caleb's question was about a statically set dylib reference, where as the PDFTron reference is using the special @rpath attribute within the path, meaning it should work as long as the file is within the same directory as the so file. Still lost why this is not working here, but works in the example bundle – Nathan Tregillus May 04 '15 at 16:20
-1

It just works fine for me when i try to run the shell script, btw iam using the python as my programming language for pdfnet,

Try to use these commands to run the pdfn

#!/bin/sh
TEST_NAME=PDFATest
export LD_LIBRARY_PATH=../../../PDFNetC/Lib
python -u $TEST_NAME.py

The PDFATest specifies the python code, and then the export will get the required packages such as the PDFNet which is in

../../Lib

folder so make sure you use that file in the lib and then run your code and you will not have any issues with PDFNet, btw i dont answer this with respect to django but sure this will help you out.

Sundeep Pidugu
  • 2,377
  • 2
  • 21
  • 43