Sunday, January 27, 2008

PDF Viewer with Text Highlighting

Unfortunately xpdf, evince, acroread etc. cannot highlight text or add comments to PDFs. PDFedit cannot select text properly for many PDFs.

However, there is a nice and free alternative, but you need wine to run it: PDF-Xchange-Viewer. There's also a thread on this on the SuSE forum.

Update: Apparently with newer wine versions you don't need the script below anymore, since opening files out of the PDF-Xchange-Viewer works directly. Also see the comments below on this.

After installing the viewer, the following script handles file opening:

#!/bin/bash

# PDF-XChange-Viewer crashes wine when File->Open is used.
# Command line argument filenames work, though.
# However they may only point to files in the current working directory.

PDFXVIEWER="C:\Program Files\Tracker Software\PDF-XChange Viewer\pdf-viewer\PDFXCview.exe"

if (($# != 1)); then
echo "usage: $0 filename"
exit 1
fi

cd `dirname "$1"`
wine "$PDFXVIEWER" `basename "$1"`

30 comments:

rhino said...

where do you put the script? I got everything else to work except for the script part. newb

leo said...

Hi rhino!

You can put the script anywhere you want, as long as the installation path to the Xchange-Viewer is correct (it should be for the standard installation).

If you want to be able to invoke the script without specifying its full path, you could put it into e.g.
/usr/local/bin/pdfxchangeview.sh
(using sudo).

Don't forget to make it executable:
sudo chmod +x /usr/local/bin/pdfxchangeview.sh

Afterwards, you should be able to invoke it from anywhere using
pdfxchangeview.sh /path/to/my.pdf

rhino said...

Thanks for the reply. I can't mess with it for the next few days because I have some high pri stuff at work. I intend to ask a few questions in 3 days or so.

rhino said...

The script that you provided...do I paste that in an editor like kwrite and save it? What file extension do I save it as?

leo said...

Yes, exactly, you save it with a standard text editor like kwrite.

The extension is arbitrary, I've used ".sh" to indicate a shell script.

However it's important to set the executable-bit using chmod (as stated in my post above). Otherwise you'd have to run it manually invoking bash each time.

rhino said...

Before I try it out can you tell me what the script will do?
Right now I enter info in my terminal to open each pdf file and of course to open another one I have to do it each time in the terminal because the open function in exchange viewer freezes as noted in that suse post. Will your script help avoid using the terminal each time?

leo said...

The function of the script is really trivial: It changes to the directory of the supplied PDF file before it starts the Xchange-Viewer. As described in the SuSE forum post the Xchange-Viewer can only open PDFs in the current working directory when using wine.

You could assign the script to open PDF files instead of your current viewer if you want to circumvent the terminal.

Otherwise, the Python script from the SuSE post provides a graphical interface (I haven't tried it though).

Anonymous said...

In Wine 1.0 works well when File-> Open is used.
Anyway, the following script is to open any PDF with XChange:

#!/bin/bash
wine "C:\Program Files\Tracker Software\PDF-XChange Viewer\pdf-viewer\PDFXCview.exe" "`winepath -w "$@"`"

With Spanish Wine installation (En español):

#!/bin/bash
wine "C:\Archivos de programa\Tracker Software\PDF-XChange Viewer\pdf-viewer\PDFXCview.exe" "`winepath -w "$@"`"

Give a name to the script. Make it executable and copy the script to:
/usr/local/bin/
Now you can open the pdf invoking the script or associating pdf's with the script.
Goodbye and good luck!

rhino said...

thx yafu. I'll try it when I get off work away from windows. May have questions. By the way is the script only for wine 1.0?

Anonymous said...

@rhino
I think it should work with previous versions of Wine, you can try. Make the script and in the file manager, open PDF's with the script. I use KDE, and after to copying the script called "pdfxchange" in /usr/local/bin, right button in pdf file and "Open With" >> "pdfxchange". I think in GNOME and Nautilus works in similar way.
Also, adapting the script and indicating the right path, can be used to open other files and associate with other applications of wine.
By the way, I hope you understand my poor english. Spanish is my languaje. Bye!

Anonymous said...

great tip: just what i've been looking for for years. thanks for sharing.

Anonymous said...

Since Wine 1.0 PDF-X-Change doesn't freeze anymore when opening a file w/o the script. I am using Ubuntu 8.04

rhino said...

So your saying you can use the open function as designed? If so what version xchange viewer are you using?

leo said...

It's nice to know that "open" is now working directly. Thanks for the comment!

Anonymous said...

It works charmingly with Ubuntu 8.04 and Wine 1.0. Thank you very much for this useful post.
I think PDFEdit needs a serious development to be operational.

Anonymous said...

xournal.sourceforge.net

Muhammad Rahiz said...

I copied the script and placed it in /usr/local/bin.
The executable file is in ~/Desktop/pdf.

When I run

> pdfx.sh file.pdf, I get the following error

wine: cannot find 'C:\Program Files\Tracker Software\PDF-XChange Viewer\pdf-viewer\PDFXCview.exe'

leo said...

Muhammad Rahiz, if you installed the viewer into a different directory, you need to change the path to the executable inside the script.

But as written in the blog post (see "update"), the script apparently is not necessary anymore with newer version of PDF-Xchange Viewer.

Muhammad Rahiz said...

I have the latest pdfxchange viewer (and the portable version) and have installed wine 1.1.

But how do I use it? Right clicking on the pdf file does not prompt for the file to be opened in pdfexchange viewer...

Muhammad Rahiz said...

Following from my earlier post, I used the script and changed the path to /home/rahiz/Desktop.

Then I did
> pdfx.sh file.pdf.

I was then guided through the windows installation procedure and am able edit my pdf.

Is this the way it is supposed to be i.e. does the viewer have to be installed every time I want to edit a pdf file?

On a related note, I don't know what I did but somehow, right clicking on the pdf file allows me to 'Open with Pdfexchange viewer'. But when I do that, it gives an error window.

leo said...

Muhammad Rahiz, I think you forgot to install the viewer before. Now after changing the path inside the script, you actually ran the setup executable. Probably you could change the script back now to use the original path to the viewer executable. However that depends on what path you selected in the setup.

Regarding opening PDFs using the right-click context menu, you need to make sure that wine is used to start the viewer. Basically that's also all the script does.

Muhammad Rahiz said...

Hi Leo,
When I did

> pdfx.sh file.pdf

it guides me through the installation process.

I changed to PDF-Xchange-Portable - it works, without having to install anything.

I still can't

1. right click a pdf file to open in Xchange-Viewer
2. open the application without specifying the filename
3. set Xchange viewer as default application for pdf files.

But these are minor issues.

Thanks for your assistance and for this blog - it's great!

leo said...

Muhammad Rahiz, you're welcome!

Thanks for the hint to the portable version, that's nice.

Just in case you still want to get the right-click open to work:

- First of all, make sure the path to the PDFXCview.exe is correct in your script.

- Make the script executable:
chmod +x /usr/local/bin/pdfx.sh

- Check if loading a PDF using

/usr/local/bin/pdfx.sh file.pdf

works.

- I assume you're using the Gnome window manager in Ubuntu. In a file browser window, right-click a PDF file and select "Properties". Go to the "Open With" tab, click "Add", select "Use a custom command" in the bottom. Enter the full path to your script there, together with a "%f", e.g.

/usr/local/bin/pdfxsh.sh "%f"

Click "Add", and back in the previous window you can also select this to be the default application to open PDF files with.

- If you want to open the application without directly opening a PDF file, just create a shortcut that points to

wine /home/rahiz/Desktop/PDFV_Portable/PDFXCview.exe

or similar (depending on where you expanded the zip archive).

Unknown said...

Hi,

I can't open a file (double clicking it) if its name has an accent (á, é, ó etc.). Is there a way to fix this?

Thanks

Anonymous said...
This comment has been removed by a blog administrator.
rocannon said...

thanks for the original article. It helped me make my choice to use this app. At this point I have a question about backups/migration.

I just moved to a new hard drive and reinstalled PDFexchange. I thought that I might have to go through some kind of meta-data transfer process to get all my previous highlighting to show up again. Magically, all the old highlighting was still there. I had assumed it was stored in some profile, but it seems to actually be stored in the files itself.

Do you know if this is incorrect? I want to be absolutely sure that I understand the backup process, since my metadata is so important. That's why I use the program, obviously.

Either way, do you know exactly how and where the metadata is stored, for pristine backups?

thanks again

leo said...

Hi, I'm glad the article was helpful for you! I'm pretty sure that if you add comments to a PDF file with Xchange-Viewer, those comments are actually saved directly in the PDF file itself.

salmonella said...

Very useful, thanks

Armando Flores Ibarra said...

I'm using Ubuntu 10.04. I did not know about PDF-XChange. Thank you very much por your post !!!

Alex said...
This comment has been removed by a blog administrator.