1

I need help in identifying the feature attributes displaying a pdf file when click in that feature. I see many examples but I don't have success. I try this code:

command = "firefox";
imagerelpath = "images_test/test_image.jpg";
layer = qgis.utils.iface.activeLayer();
import os.path;
layerpath = layer.source() if layer.providerType() == 'ogr'
  else (qgis.core.QgsDataSourceURI(layer.source()).database()
  if layer.providerType() == 'spatialite' else None);
path = os.path.dirname(str(layerpath));
image = os.path.join(path,imagerelpath);
import subprocess;
subprocess.Popen( [command, image ] );

but it gives me always an error:

WindowsError: [Error 2] The system cannot find the file specified

Basically, I have a shapefile and I want to click in a feature and open a pdf file. I want to develop that in a python plugin.

user27513
  • 29
  • 2
  • Where is the pdf file (I only see a jpg image) ? If the command "firefox" is not in the PATH ( you can use it in the shell), the subprocess module needs the complete path of Firefox. If not, it don't know what is the command – gene Jul 18 '14 at 16:07
  • Hi. Thanks for the response. The code that I introduce is not my code, it is in this page (http://docs.qgis.org/2.2/en/docs/user_manual/working_with_vector/vector_properties.html#actions-menu) and I use that. So in imagerelpath I have the path for my pdf file (c:\users\desktop\teste.pdf). I don't know if it is correct. My doubt is in command "firefox". How I know if the command is in PATH? What is the complete path of Firefox that you said? – user27513 Jul 18 '14 at 16:19
  • I you are on Windows, it is "C:\Program Files\Mozilla Firefox\firefox.exe" , look at How to add links to PDFs in a Shapefile?, for example – gene Jul 18 '14 at 17:37
  • I don't have Mozilla firefox. Thats why this doesn't work, right? So, can I use another command? Or a different code to obtain the pdf with a click? – user27513 Jul 21 '14 at 08:27

0 Answers0