Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2008, 04:24 PM
Member
 
Join Date: Feb 2008
Posts: 12
aparna is on a distinguished road
open a pdf file in linux
Hi... I want to open a pdf file in linux with java code
In windows i am using
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + path);

In Mac
Runtime.getRuntime().exec("open /Users/source/abc.pdf");

but I didnt find any solution for Linux
Somewhere I found solution
Runtime.getRuntime().exec("open file:/home/source/abc.pdf");
But its not working and this solution is specific to KDE desktop. I want a common solution for any desktop in linux. Please help me
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-27-2008, 03:43 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 720
Nicholas Jordan is on a distinguished road
PDF is proprietary, probably study Post Script, which is popular in the college cs crowd and leads to pdf eventually
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-27-2008, 06:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Did you try to find the common execution location of pdf? Because that's not related to Java anymore. May be our Linux users can help you. At the time try to search on a Linux forum as well. Sorry pal, I'm not a linux user.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-28-2008, 06:30 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Nicholas Jordan View Post
PDF is proprietary
This was true, but Adobe has released the specs. So its sort of open license, and there are open source tools to read it.

But, and this is a big but, the format is complex. Most programmers prefer to not reinvent the wheel. So find some code that already does what you need.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-28-2008, 07:37 AM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 287
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Download library from here :
New: 100% Java PDF Renderer and Viewer
then create two file:
Code:
import java.awt.*; import java.awt.geom.*; import java.io.*; import java.nio.*; import java.nio.channels.*; import javax.swing.*; import com.sun.pdfview.*; public class Renderer { private Image image; private String fileName; private PDFFile pdfFile; private double height; private double width; private int numpages; private Image[] images; public Renderer(String file,int pagenum){ fileName=file; try{ RandomAccessFile raf = new RandomAccessFile (new File (fileName), "r"); FileChannel fc = raf.getChannel (); ByteBuffer buf = fc.map (FileChannel.MapMode.READ_ONLY, 0, fc.size ()); pdfFile = new PDFFile (buf); } catch(IOException e){ System.out.println("the file wasn't found"); } numpages = pdfFile.getNumPages (); System.out.println ("Number of pages = "+numpages); /*if (pagenum > numpages) pagenum = numpages; */ images=new Image[numpages]; int counter=1; for(int i=0;i<images.length;i++){ PDFPage page = pdfFile.getPage (counter); Rectangle2D r2d = page.getBBox (); width = r2d.getWidth (); height = r2d.getHeight (); width /= 72.0; height /= 72.0; int res = Toolkit.getDefaultToolkit ().getScreenResolution (); width *= res; height *= res; image = page.getImage ((int) width, (int) height, r2d, null, true, true); images[i]=image; counter++; } } public Image[] getImagePDFArray(){ return this.images; } public Image getPDFImage(){ return this.image; } public double getWidth(){ return this.width; } public int getNumOfPages(){ return this.numpages; } public int getHeight(){ return (int)this.height; } }
the seocnd one:
Code:
import java.awt.*; import java.awt.geom.*; import java.io.*; import java.nio.*; import java.nio.channels.*; import javax.swing.*; import com.sun.pdfview.*; import java.awt.event.*; public class PDFViewer extends JFrame { // static Image image; public PDFViewer (String title) { super (title); setDefaultCloseOperation (EXIT_ON_CLOSE); pack (); } public static void main (final String [] args) throws IOException { int pagenum=1; final Renderer rend=new Renderer(fileName,pagenum); Runnable r = new Runnable () { int y=0; JViewport view; public void run () { PDFViewer pdf= new PDFViewer ("PDF Viewer: "+"<Your pdf file>"); JToolBar toolBar=new JToolBar(); JButton buttonScroll=new JButton("Next"); toolBar.add(buttonScroll); toolBar.setVisible(true); JLabel[] labels=new JLabel[rend.getNumOfPages()]; JPanel main=new JPanel(); main.setLayout(new BoxLayout(main,BoxLayout.Y_AXIS)); for(int i=0;i<labels.length;i++){ labels[i]=new JLabel(new ImageIcon (rend.getImagePDFArray()[i])); labels[i].setVerticalAlignment (JLabel.BOTTOM); main.add(labels[i]); } JScrollPane pane=new JScrollPane (main); JSplitPane splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,toolBar,pane); splitPane.setDividerSize(4); view = pane.getViewport(); Point p = new Point(0,y); view.setViewPosition(p); y=rend.getHeight(); buttonScroll.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ int r=0; double rp=0.0; rp=view.getViewPosition().getY(); r=(int)rp/rend.getHeight(); y=rend.getHeight()*r+rend.getHeight(); Point p = new Point(0,y); view.setViewPosition(p); } }); pdf.setContentPane (splitPane); pdf.setSize(800,600); pdf.setVisible (true); } }; EventQueue.invokeLater (r); } }
Search where you have PDFViewer pdf= new PDFViewer ("PDF Viewer: "+"<Your pdf file>"); and insert your own file pdf to open
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to open a file through URL katie New To Java 3 07-13-2008 04:53 AM
Windows Linux conflict - TrayIcon image not display in Linux Eranga Advanced Java 0 03-25-2008 07:37 AM
new member need help with linux praveena New To Java 0 01-22-2008 12:22 PM
Is it possible to open a txt file? jason27131 New To Java 20 08-07-2007 03:24 AM
Linux and java Alan Advanced Java 2 05-31-2007 04:30 PM


All times are GMT +3. The time now is 11:46 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org