Visit Our UNIX and Linux User Community


Linux C - how to open a pdf file with default reader


 
Thread Tools Search this Thread
Top Forums Programming Linux C - how to open a pdf file with default reader
# 1  
Old 03-21-2010
Linux C - how to open a pdf file with default reader

sorry if i repost this...

hi.. i want to ask how to open pdf files using C in Linux

in Windows, i just use this code:
ShellExecute(GetDesktopWindow(), "open", "D:\\Folder\\File.pdf", NULL, NULL, SW_SHOWNORMAL);

thanks for advance...
# 2  
Old 03-21-2010
there's no such thing as default readers in unix.
some desktop environments may support it.

there's no registry in unix.
# 3  
Old 03-21-2010
Good Evening,

One possibility is given below (errors checking is left to the readers...)

Code:
#include <stdlib.h>
#include <string.h>

const char* pdf_reader="evince "; /* put the name of your pdf reader here */

void
read_pdf(const char* name)
{
   char cmd[128];

   strcpy(cmd, pdf_reader);
   strncat(cmd, name, sizeof(cmd));
   system(cmd);
}

Cheers,
Loc
# 4  
Old 03-21-2010
I know Gnome has a utility program, gnome-open, which will take the file you pass to it and open that with the default application, whatever that is - presumably there's something similar for KDE and other popular desktop environments?

If you want it to be fairly portable, you could:

1) Check for the presence of, e.g. gnome-open with system("gnome-open --version"), and so on for other programs until you find one,

2) If that doesn't work, go down a similar list of raw pdf viewers (system("evince --version"), etc), and

3) If you still can't find one, prompt the user for the name of a program.

Apart from that, I don't think there's a lot else you can do.

Previous Thread | Next Thread
Test Your Knowledge in Computers #8
Difficulty: Easy
macOS is based on the Unix operating system.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a text file and a pdf file from Linux command results.

Hello. The task : Using multiple commands like : gdisk -l $SOME_DISK >> $SOME_FILEI generate some text file. For readiness I must insert page break. When the program is finished I want to convert the final text file to a pdf file. When finished, I got two files : One text file and One pdf... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Need script to monitor open file in Linux

Kindly advice with shell script to monitor open file in linux, if the open file count is greater then 5000 then send me an email.. command : lsof | wc -l (0 Replies)
Discussion started by: adminhelp
0 Replies

3. Shell Programming and Scripting

Scanning a pdf file in Linux shell

I want to search a keyword in a list of pdf files and when i find a match i want to write the title and author of that pdf file to another file. How will I do this using linux shell script? (7 Replies)
Discussion started by: SK33
7 Replies

4. Red Hat

Setting Password For PDF File--Linux

Hi, I am in need of help. My requirements are : 1) To convert the existing files (irrespective of their format) in a directory to PDF format 2) To make the converted files password protected. I did the attempt to do the same. Though the existing files (irrespective of their format) are... (1 Reply)
Discussion started by: MKR
1 Replies

5. Programming

How can this jar file open pdf ??

OKay so my question is that how does this jar file convert something in there and show pdf when open it? I don't get how it works. Can someone explain to me. I have a link below, in there will be a file call Tools, and please open the file called "PQ10-sample" it will automaticly open up a pdf as... (11 Replies)
Discussion started by: tonyduong15
11 Replies

6. Solaris

Replacing Gnome PDF with Adobe Reader

I'm attempting to replace gnome pdf with Acrobat Reader on a server and make Acrobat Reader the default program used to open .pdf files. I've been able to make the changes to individual users but don't want to have to edit each individuals profile. Is there a way, within Solaris 10, to make a... (2 Replies)
Discussion started by: goose25
2 Replies

7. Shell Programming and Scripting

How to open a pdf file from terminal?

how to open a .pdf file from terminal not using gpdf I work on fedora 12 and default application assigned for viewing the pdf files is document-viewer (3 Replies)
Discussion started by: rrd1986
3 Replies

8. AIX

pdf reader

which package is to be installed to view pdf files in AIX machine? i already have xpdf version 1...but, some pdf files are not opening in it.help me out. (1 Reply)
Discussion started by: me.kamph
1 Replies

9. UNIX for Dummies Questions & Answers

How to open WinZip file in linux

Hi i am an fresh engineer working in a Embedding company and i am new to linux so any one help me to teach or tell how to open a WinZip file in linux as i use gunzip but hte file suffix is not gz so can any one healp me... urs ... (2 Replies)
Discussion started by: wagmare
2 Replies

Featured Tech Videos