I want to use PDF-XChange Editor to open pdf files from within mc. I tryed setting

Open=wine ~/PDFXEdit6_Portable/PDFXEdit.exe %f

in mc.ext, but it opens only the application, not the file.


[edit]

It seems to me the syntax of this field is close to that of exec in .desktop files, so I tried to adapt some of the solutions proposed on How to pass file as argument in .desktop file for wine application, but without success yet.

up vote 1 down vote accepted

Short answer.

You are using %f, but the filename You want to pass is stored in ${MC_EXT_FILENAME} variable.

Long answer.

How to open / view PDF files using Midnight Commander + wine + PDF-XChange Viewer / Editor Portable

note: I assume that windows portable apps are stored in "~/MyApps/*"

  • open Midnight Commander extension file for editing: F9 -> Command -> Edit extension file
  • navigate to the section of the file where PDF configuration is written: type /pdfEnter
  • comment out the following lines (just for a backup):


# PDF
#type/^PDF
#       Open=/usr/lib/mc/ext.d/doc.sh open pdf
#       View=%view{ascii} /usr/lib/mc/ext.d/doc.sh view pdf

  • add / replace with the following lines:


# PDF
type/^PDF
        Open=~/MyApps/start-pdf-mc.sh
        View=%view{ascii} ~/MyApps/start-pdf-mc.sh

  • exit and save the changes: :wq
  • create the ~/MyApps/start-pdf-mc.sh file with the following content:


#!/bin/bash
Filename="z:"${MC_EXT_FILENAME//\//\\}
App=`eval wine "~/MyApps/PDF-XChange_Viewer/PDFXCview.exe" "'$Filename'" > /dev/null 2>&1 &`
$App

note: You might want to create it in /usr/lib/mc/ext.d/*.sh (instead of ~/MyApps/ as I did)

  • make sure start-pdf-mc.sh file is executable (use chmod)

explanation of the start-pdf-mc.sh file

  • the filename we are trying to open is stored in ${MC_EXT_FILENAME} variable

  • when using wine, use drive letter z:

  • convert Linux-style file path (/) to Windows-style (\) with the following: ${MC_EXT_FILENAME//\//\\} to pass it as an argument to PDF-XChange Viewer later

  • > /dev/null 2>&1 and & are required to discard program output and to run it as a background process, otherwise (if you omit this), You've won't be able to use Midnight Commander till You close PDF-XChange Viewer which is obviously not desirable

tested with the following software

  • Linux Debian 32-bit

  • GNU Midnight Commander 4.8.13

  • wine-1.6.2

  • PDF-XChange Viewer v2.5.316.1

AND

  • Linux Debian 32-bit

  • GNU Midnight Commander 4.8.13

  • wine-1.6.2

  • PDF-XChange Editor v6.0.321.0

update according to Your comment

It seems that there is still some error in the filepath... Let's try to correct it.

1.

  • Open problematic pdf file with PDFXChange Editor (as you usually do, NOT with the Midnight Commander)

  • File -> Copy Full File Name

  • Paste it in any text file (just for later reference)

  • Close PDFXChange Editor

  • Open the same file with Midnight Commander + PDFXChange Editor (which shows your error message)

  • Compare if the file paths are identical (the one that You've just pasted for reference and the one in Your error message)

  • If the paths are NOT identical - correct the path accordingly in .sh file OR paste them here for me to help (just replace your username in the path with <username> for security)

2.

Also, this is not so likely, BUT if the paths ARE identical there might be an issue with permissions that are set on the file you are trying to open. Thus verify your file permissions are at least:

sudo chmod 644 your-file-name-here.pdf

update 2

It is possible to have access to all files from all drives including those that are NOT located in the ~/* (home user directory) or even stored on other HDDs just by using Z:\ (not using H:\ and other drive letters at all).

Check Your drive mapping in wine:

  • run in terminal

    $ winecfg

  • open the Drives tab

  • the following records have to be there by default

    Letter | Drive Mapping
    C:     | ../drive_c
    Z:     | /
    

As far as I know, any path starts with / (for any file on any HDD accessed in Linux) and thus can be accessed using the Z:\, because of the mapping described above.

For example, the above config allows me to access a pdf file

  • from /home/<username>/*.pdf (~/*.pdf), if it's located in home user directory
  • from /media/<drive-label>/*.pdf OR /mnt/<drive-label>/*.pdf, if it's located on some external drive or HDD, that I've mounted; (in windows the same drive might be accessed using the H:\, for example)

Drive mappings, however, would be another question, specific to Your setup. :-)

BTW, one more thing to check. Is your user home directory ~/* mapped to wine's My Documents folder?

  • in terminal: $ wine explorer
  • double click on My Documents folder
  • You should see the contents of your Linux ~/* home directory
  • Thanks for helping. I get an error, though: PDFXChange Editor says An error occurred while opening the document from the file: z:\home\...\file.pdf Error [operating system]: path not found. – Arch Stanton Apr 22 '17 at 9:29
  • Answer updated. Please, check it and report the results. – Dmytro Dzyubak Apr 22 '17 at 15:35
  • I think the problem is that the ${MC_EXT_FILENAME} is an absolute path while the "full file name" is relative to my home. The full file name is H:\Downloads\file.pdf, the Downloads folder is in /home/me/Downloads. – Arch Stanton Apr 23 '17 at 8:31
  • How have you managed to get to the H:\ drive letter from MC? Anyway, check out update 2. – Dmytro Dzyubak Apr 23 '17 at 18:48
  • My Documents is not mapped to ~/ and I don't want it so. Anyway, I didn't have Z: mapped to /. I added it and now it works. Thank you :-) – Arch Stanton Apr 23 '17 at 19:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.