converting doc to pdf using JodConverter

Step-1

After successfully Installation of OpenOffice.org, just move to “D:\Program Files\OpenOffice.org 3\program” as my Operating system is installed in “D:\” drive as in this fig.1
 Fig.1
Step-2
Here you can find all files and make sure “soffice.exe” is in that place or not. See it in fig.2
Fig.2
 
Step-3
Now Open the command prompt using run command like in this and copy the path from previous window. See in fig.3
                                                                       Fig.3
 
Copy D:\Program Files\OpenOffice.org 3\program and place it in command prompt and hit enter
Step-4
So all you have to do is start OOo(OpenOffice.org) with something like
soffice.exe-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager.

Most likely you should add the path of your OOo installation: “c:\program files\OpenOffice.org 3\program\soffice.exe” -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager
Note
here you have to place host as 127.0.0.1 and StarOffice.ServiceManager as  –nofirststartwizard 
So, Copy soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard and place it in command prompt and hit enter.
By this you can start this service to the OpenOffice.org; you can see it in fig.4
                                                          Fig.4
If You restart or shutdown the System in which OpenOffcie.org is installed , Then you have to follow these steps for sure as it is mandatory for start the service for communication soffice.exe to JODConverter.
Creating an OpenOffice.org Service on Unix-like systems
Creating a SysV-style init script for starting OpenOffice.org is not difficult but the details depend on your particular OS flavour/distribution.
The tricky part is that OpenOffice.org requires an X server to work. On a headless server, you can use Xvfb as a dummydisplay for OpenOffice.org.
However since OpenOffice.org 2.3 an X server server is no longer needed; it is now possible to start OpenOffice.org in “true” headless mode simply by making sure the DISPLAY environment variable is not defined:
$ unset DISPLAY
$ soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

Usage as a Java Library

Using JODConverter in your own Java application is very straightforward. The following example shows the skeleton code required to perform a one off conversion from a Word document to PDF:
File inputFile = new File("document.doc");
File outputFile = new File("document.pdf");

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();

// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);

// close the connection
connection.disconnect();
To convert from/to other formats, simply change the file names and the formats will be determined based on file extensions; e.g. to convert an Excel file to OpenDocument Spreadsheet:
File inputFile = new File("spreadsheet.xls");
File outputFile = new File("spreadsheet.pdf");
converter.convert(inputFile, outputFile);
Simple, isn’t it?
If you’re integrating JODConverter in a web application for example you may want to initialise a single OpenOfficeConnection instance when the app is started and disconnect it when the app is stopped.
Posted in Uncategorized | Leave a comment

How to Convert a Doc to PDF in Java

Converting a Word Document to Adobe Acrobat’s PDF (Portable Document Format) is possible through several approaches, some of which make use of open source (free) libraries. One such library relies on Open Office running as a background service on your computer or server

Instructions

    • 1 Download JODConverter from artofsolving.com. Download and install the OpenOffice suite from OpenOffice.org, the NetBeans IDE from NetBeans.org, and the Java JDK from java.sun.com. (See the References for download links.)
    • 2 Create a new Java application in NetBeans. Name the project “mypdf.” In the Project Location text box, type “\mypdf” at the end of the default location to add a new subfolder to that location.

      Check the Create Main Class checkbox, ensuring that the text box next to it reads “mypdf.Main.” Click Finish.

    • 3 Unzip the JODConverter zip file and copy its “lib” subfolder to the first “mypdf” subfolder. Verify that Windows Explorer’s right pane shows this list of files for that folder:

      lib
      mypdf
      nbproject
      src
      test

    • 4 Import the library into the IDE: in the IDE, right-click on the “mypdf” project in the Projects window and select “Properties.” Click the “Libraries” category, then click “Add JAR/Folder.” Navigate to inside the “lib” folder from Step 3, then press “Ctrl-A” to select all the jar files inside that lib folder. Select the “Reference as Relative Path” option, then press OK.
    • 5 Paste the following source code into the IDE’s code window:

      package mypdf;
      import java.io.*;
      import com.artofsolving.jodconverter.openoffice.connection.*;
      import com.artofsolving.jodconverter.openoffice.converter.*;
      import com.artofsolving.jodconverter.*;

      public class Main {

      public static void main(String[] args) throws Exception {

      // Link to OpenOffice.org, which needs to be running as a service in the background
      OpenOfficeConnection OOconnection = new SocketOpenOfficeConnection(8100);
      OOconnection.connect();

      File inFile = new File(“mydoc.doc”);
      File outFile = new File(“mydoc.pdf”);

      // do the conversion
      DocumentConverter PDFconverter = new OpenOfficeDocumentConverter(OOconnection);
      PDFconverter.convert(inFile, outFile);

      OOconnection.disconnect();
      }
      }

    • 6 Start up OpenOffice as a background service. Select Start, type “cmd” and press “Enter.” Navigate to the OpenOffice “program” subfolder using the command “cd” (change directory) DOS command. Type:

      cd “c:\Program Files”
      cd “OpenOffice.org <Version>”
      cd program

      where “<Version>” is the version you installed. Do include the quotation marks shown in the cd commands just listed. Start OpenOffice at the command prompt by typing the following on one line:   soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

    • 7 Create an MS Word document called “mydoc.doc” and copy it to inside the second mypdf folder. You should see these folders and files under the “mypdf\mypdf” folder in Windows Explorer:

      build
      build.xml
      manifest.mf
      mydoc.doc
      nbproject
      src
      test

    • 8 Compile and run the conversion program from the IDE: press “Shift-F6.” When the program finishes, look for the output PDF file, “mydoc.pdf”, in the same folder as “mydoc.doc.”
Posted in Uncategorized | Leave a comment

जब मैं छोटा था……..

           जब मैं छोटा थाशायद दुनिया
बहुत बड़ी हुआ करती थी..
मुझे याद है मेरे घर से “स्कूल” तक
का वो रास्ताक्या क्या नहीं था वहां,
चाट के ठेलेजलेबी की दुकान,
बर्फ के गोलेसब कुछ,
अब वहां “मोबाइल शॉप“,
विडियो पार्लर” हैं,
फिर भी सब सूना है..
शायद अब दुनिया सिमट रही है
जब मैं छोटा था,
शायद शामें बहुत लम्बी हुआ करती थीं…
मैं हाथ में पतंग की डोर पकड़े,
घंटों उड़ा करता था,
वो लम्बी “साइकिल रेस“,
वो बचपन के खेल,
वो हर शाम थक के चूर हो जाना,
अब शाम नहीं होतीदिन ढलता है
और सीधे रात हो जाती है.
शायद वक्त सिमट रहा है..
जब मैं छोटा था,
शायद दोस्ती
बहुत गहरी हुआ करती थी,
दिन भर वो हुजूम बनाकर खेलना,
वो दोस्तों के घर का खाना,
वो लड़कियों की बातें,
वो साथ रोना
अब भी मेरे कई दोस्त हैं,
पर दोस्ती जाने कहाँ है,
जब भी “traffic signal” पे मिलते हैं
“Hi” हो जाती है,
और अपने अपने रास्ते चल देते हैं,
होलीदीवालीजन्मदिन,
नए साल पर बस SMS आ जाते हैं,
शायद अब रिश्ते बदल रहें हैं..
जब मैं छोटा था
तब खेल भी अजीब हुआ करते थे,
छुपन छुपाईलंगडी टांग
पोषम पाकट केक,
टिप्पी टीपी टाप.
अब internet, office, 
से फुर्सत ही नहीं मिलती..
शायद ज़िन्दगी बदल रही है..

जिंदगी का सबसे बड़ा सच यही है.. 
जो अक्सर कबरिस्तान के बाहर 
बोर्ड पर लिखा होता है
मंजिल तो यही थी
बस जिंदगी गुज़र गयी मेरी 
यहाँ आते आते“.
ज़िंदगी का लम्हा बहुत छोटा सा है...
कल की कोई बुनियाद नहीं है
और आने वाला कल सिर्फ सपने में ही है.. 
अब बच गए इस पल में..
तमन्नाओं से भरी इस जिंदगी में 
हम सिर्फ भाग रहे हैं..
कुछ रफ़्तार धीमी करो,
मेरे दोस्त,
और इस ज़िंदगी को जियो…
खूब जियो मेरे दोस्त 
Posted in Uncategorized | Leave a comment

RaNjEeT Blog

Unlocking a password-protected PDF using the iText library

  1. import com.lowagie.text.pdf.PdfEncryptor;
  2. import com.lowagie.text.pdf.PdfReader;
  3. import com.lowagie.text.pdf.PdfWriter;
  4. public class UnlockPDF
  5. {
  6.    public static void main(String[] args) throws Exception
  7.    {
  8.       String lockedFile = “locked.pdf”                // Locked pdf filename
  9.       String password = “p@ssw0rd”;              // Locked pdf password
  10.       String unlockedFile = “unlocked.pdf”;      // Filename of the new unlocked pdf
  11.       PdfReader reader = new PdfReader(lockedFile, password.getBytes());
  12.       System.out.println(“Unlocking…”);
  13.       PdfEncryptor.encrypt(reader, new FileOutputStream(“unlocked.pdf”), null,
  14.          null, PdfWriter.AllowAssembly | PdfWriter.AllowCopy
  15.          | PdfWriter.AllowDegradedPrinting | PdfWriter.AllowFillIn
  16.          | PdfWriter.AllowModifyAnnotations | PdfWriter.AllowModifyContents
  17.          | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders, false);
  18.       System.out.println(“PDF Unlocked!”);
  19.    }
  20. }
Posted in Uncategorized | Leave a comment

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in Uncategorized | 1 Comment