title: I want Java code to convert word file (doc file having text, images, tables etc. ) into pdf file.
body: <p>I have added all the necessary jar files including <code>itextpdf-5.1.0.jar</code> but still it gives errors.. 
  please refer below code.
  I searched it on net but it's not working.</p>
  
  <p>It gives error while importing </p>
  
  <pre>com.lowagie.text.Document; 
  com.lowagie.text.Paragraph; 
  com.lowagie.text.pdf.PdfWriter;</pre>
  
  <p>Don't understand what is going wrong. I added latest version of <code>iText jar</code> file but not getting the solution.</p>
  
  <p>please give me correct solution or code.
  please mention it stepwise.
  because I'm doing this first time...</p>
  
  <pre>
      import com.lowagie.text.Document;   
      import com.lowagie.text.Paragraph;    
      import com.lowagie.text.pdf.PdfWriter;    
      import java.io.File;
      import java.io.FileOutputStream;    
      public class Doc2Pdf2 {    
          /**
           * This method is used to convert the given file to a PDF format
           * 
           * @param inputFile
           *            - Name and the path of the file
           * @param outputFile
           *            - Name and the path where the PDF file to be saved
           * @param isPictureFile
           */
          private void createPdf(String inputFile, String outputFile,
                  boolean isPictureFile) {
              Document pdfDocument = new Document();
              String pdfFilePath = outputFile;
              try {
                  FileOutputStream fileOutputStream = new FileOutputStream(
                          pdfFilePath);
                  PdfWriter writer = null;
                  writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
                  writer.open();
                  pdfDocument.open();    
                  if (isPictureFile) {                    pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
                  } else {
                      File file = new File(inputFile);
                      pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils
                              .readFileToString(file)));
                  }
                  pdfDocument.close();
                  writer.close();
              } catch (Exception exception) {
                  System.out.println("Document Exception!" + exception);
              }
          }    
          public static void main(String args[]) {
              PDFConversion pdfConversion = new PDFConversion();
              pdfConversion.createPdf("C:/demo.doc", "C:/demopdf.pdf", true);    
          }    
      }
  
  </pre>