Enquiry on converting a *.txt file to a *.pdf file

Enquiry on converting a *.txt file to a *.pdf file
Aim of this software: Let the user to choose a *.txt file to convert it to a *.pdf file.
1. User clicks a choose file button. [chooseFileButton]
2. User clicks the Export 2 button [exportButton2]
3. User clicks the Text -> PDF button [pdfConverterButton]
After choosing the file and click the choose file button:
System prints out (for debbuging use...)
---------------------------Print from Trans.java - method transMemory--------------------
File's name: file.txt
File's path: C:\Users\charles\Desktop\netbean\Pdfproject1\file.txt
After clicking the Export 2 button, system prints out:
---------------Print out the File's name - from DataOut.java - getData() Method-------------------------
File's Name: file.txt
----------------Print out the file's path - from DataOut.java - getData() Method--------------
File's path: C:\Users\charles\Desktop\netbean\Pdfproject1\file.txt
The file now being read by the system: transNameData.txt
The data being copied to this file: copyOfFileName.txt Destination
This file has been copied: file.txt Original
The following content has been copied:
---start of content - from TheFile.java - save2() method---
Some content.....................................
--------end of content--------
Jul 18, 2010 3:32:04 PM mainFrame1 exportButton2ActionPerformed
SEVERE: null
java.io.IOException: Permission denied
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:199)
at java.io.DataInputStream.read(DataInputStream.java:132)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at TheFile.save2(TheFile.java:144)
at mainFrame1.exportButton2ActionPerformed(mainFrame1.java:168)
at mainFrame1.access$200(mainFrame1.java:30)
at mainFrame1$3.actionPerformed(mainFrame1.java:79)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
After clicking the text -> PDF button, system prints out:
The following data is called by the PDF converter button...
---------------Print out the File's name - from DataOut.java - getData() Method-------------------------
File's Name: file.txt
----------------Print out the file's path - from DataOut.java - getData() Method--------------
File's path: C:\Users\charles\Desktop\netbean\Pdfproject1\file.txt
MakePdf.java is loading... - createPdf() method
File you have chosen and this file will be converted to a PDF file: file.txt
And the content of the file is:
---start of content--- (Info from MakePdf.java)
Some content.....................................
---end of content---
Print out the content again: Some content..................................... ---> Info from SubClass DocToPdf of MakePdf.java
Exception in thread "AWT-EventQueue-0" ExceptionConverter: java.io.IOException: The document has no pages.
at com.lowagie.text.pdf.PdfPages.writePageTree(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
at com.lowagie.text.Document.close(Unknown Source)
at MakePdf$DocToPdf.createDoc(MakePdf.java:140)
at MakePdf.createPdf(MakePdf.java:97)
at TheFile.forPdfUse(TheFile.java:267)
at mainFrame1.pdfConverterButtonActionPerformed(mainFrame1.java:184)
at mainFrame1.access$300(mainFrame1.java:30)
at mainFrame1$4.actionPerformed(mainFrame1.java:86)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 1 minute 41 seconds)

Source code: MakePdf.java
import com.lowagie.text.DocumentException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.lang.String;
import java.io.*;
public class TheFile {
String pathData;
String nameData;
     public void PrepareJFileChooserData2(){
        try {
            // Create a object for JFileChooser.
            final JFileChooser choose = new JFileChooser();
            choose.showOpenDialog(null);
            File file = new File(choose.getSelectedFile(), "");
            pathData = file.getPath(); //get the path of the chosen file
            nameData = file.getName(); //get the name of the chosen file
            //Try to copy file to a temp file.
            Cfile2 cfile = new Cfile2();
            cfile.writeFile(nameData); // write nameData into the temp.txt file.
            //return pathData;
        } catch (IOException ex) {
            Logger.getLogger(TheFile.class.getName()).log(Level.SEVERE, null, ex);
      public String getPathName(){
            return pathData;
      public String getNameData(){
          return nameData;
    public class Cfile2{
    public void writeFile(String fName) throws IOException {
        PrintWriter pr = new PrintWriter(new File("temp.txt"));
        pr.println();
        pr.print("\n");
        pr.write("-------------------From SubClass - Cfile2 in TheFile.java----------------------");
        pr.write("File Name: " +nameData); // write the value of nameData to temp.txt
        pr.print("\n");
        pr.write("File's Path: "+pathData); // write the value of pathData to temp.txt
        pr.print("\n");
        pr.print("-------------------------------------------------------------------------------");
        pr.flush();  // Flush the data.
        pr.close();  // Close to unlock and flush to disk.
    public void save2() throws FileNotFoundException, IOException{
       // Copy and print out the file's name only
       String fileName = "transNameData.txt";
       File originFile = new File(fileName); //open the file to read
       System.out.println("The file now being read by the system: " +originFile);  //originFile = transNameData.txt
       File destinationFile = new File("copyOfFileName.txt"); // open another file and prepare to write in
    try {
        //Start trying to write data to file - copyOfFileName.txt
      byte[] readData = new byte[2048];
      FileInputStream fis = new FileInputStream(new File(fileName)); // Seems it writes the value of transNameData.txt to copy.txt
      int count = fis.available();
      if(count>0){
      FileOutputStream fos = new FileOutputStream(destinationFile);
      int i = fis.read(readData);
      while (i != -1) {
        fos.write(readData, 0, i);
        i = fis.read(readData);
      System.out.println("The data being copied to this file: " +destinationFile+ " Destination");
      fos.flush();
      fos.close();
      fis.close();
        }else{
          System.out.print("Error");
    } catch (IOException e) {
      System.out.println(e);
    // Copy the content of the file only
    FileInputStream fstream = new FileInputStream("transNameData.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      System.out.println ("This file has been copied: " +strLine+ " Original"); //Work successfully, strLine has the value [file's title]
      File newDestinationFile = new File("ContentCopy.txt"); //Open the newCopy.txt file
      byte[] newReadData = new byte[2048];
      FileInputStream newFileInputStream = new FileInputStream(new File(strLine)); // See whether it can write it in... ok done!
      //String newString = newReadData.toString();
      //System.out.print("Content that has been copied: " +newString); //It prints out data in byte form...?!
      FileOutputStream newFileOutputStream = new FileOutputStream(newDestinationFile);
      int i = newFileInputStream.read(newReadData);
      while (i != -1) {
        newFileOutputStream.write(newReadData, 0, i);
        i = newFileInputStream.read(newReadData);
    FileInputStream newfstream = new FileInputStream(strLine);
    // Get the object of DataInputStream
    DataInputStream newin = new DataInputStream(newfstream);
        BufferedReader newbr = new BufferedReader(new InputStreamReader(newin));
    String content;
    //Read File Line By Line
    while ((content = newbr.readLine()) != null)   {
      // Print the content on the console
        System.out.println("\n");
        System.out.println("The following content has been copied: ");
        System.out.println(" ");
        System.out.println("---start of content - from TheFile.java - save2() method---");
        System.out.println(" ");
        System.out.println(content);
        System.out.println(" ");
        System.out.println("--------end of content--------");
    //Close the input stream
    in.close();
    //Close the input stream
    in.close();
//----------- start PDF parser  ---> to txt format -------
   public void pdf() throws FileNotFoundException, IOException{
    //-----again--
   FileInputStream inStream = new FileInputStream("transNameData.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(inStream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      System.out.println ("Watch out: " +strLine+ "  ---> It should be printed successfully!!"); //Work successfully
    //---again......
    PDFTextParser pdftextparser = new PDFTextParser();
    pdftextparser.pdftoText(strLine);
    public void forPdfUse() throws FileNotFoundException, IOException, DocumentException{
        MakePdf makePdf = new MakePdf();
        makePdf.createPdf();
}

Similar Messages

  • How can I convert an odg. file to a pdf. file?

    Hello, how can I convert an odg. file to a pdf. file?
    When choosing Drawing as template in OpenOffice, it saves projekt as odg. which apparently gives difficulties compared to pdf.

    Try this: http://www.convertfiles.com/convert/document/ODG-to-PDF.html
    Let me know if it helps,
    Kevin

  • How do I convert an InDesign file into a PDF file, it won't let me do it when I 'Save As'. Help??

    I need help with converting an InDesign file into a PDF file.
    I've tried looking into the program and seeing if i can do it, but it is not giving me the option.
    I need to be able to do this for work purposes.
    Please help.

    Try Exporting. There are also number of useful Export PDF presets that come with design.
    What do you want to do with the PDF?

  • Convert Multiple Outlook Emails to Multiple PDF Files (Not Portfolio or Single PDF) for Archiving?

    Hi all, I am learning how to convert emails to PDF files and there is some great functionality there!!  I have not discovered how to convert multiple outlook emails into multiple PDF files (one PDF file for each email) - all at the same time (not one at a time)!!  Is there a way to do this using Acrobat X??  The purpose of this is for long-term business archiving.  When I search for an email in the archive, I do not want to pull up a portfolio containing 1000 emails or a 1000 page PDF file with multiple emails run together!!!  I want to pull up individual emails containing my search terms.  I have been searching for a way to archive emails and MS OUTLOOK .PST files are NOT the answer.  I get a lot of business emails with large attachments and I do not file my emails in separate sub-folders (by client or job).  I want to convert multiple emails (by date range) from my UNIVERSAL INBOX into multiple PDF files for long term storage (with each email being converted into its own, separate PDF file and named with the same name as the "Re: line" of the email).  This has been a HUGE problem for me....and Acrobat is sooooo close to the solution for me.  Can anyone help??  If so, will attachments be converted?  If not, is there a separate software program or add-in that I can buy that will do this??  I use MS Office 2010, Adobe Acrobat X Pro, Windows 7 64 BIT.  Thanks for your help!!

    I am a retired person and did'nt realize I already have a Adobe account, so you can scrap the entire information. Thanks for the trial anyway and have a great week.
    Frederick

  • How do I convert a Jpeg file to a PDF file

    How do I convert a jpeg file to a pdf file?

    Hi Rick
    With a paid subscription to Adobe CreatePDF you can covert a jpeg to PDF
    See https://www.acrobat.com/createpdf/en/home.html for further information and pricing plans

  • How do I convert a MSWord file in a pdf file

    Hello...
    I want to convert a MSWord file in a pdf file automaticly within a Servlet.
    I don't know exactly what library I should use. The word file can contain
    any number of things(images,tables,special characters).... I've seen that with iText I have to consider each situation separatly(I have to know what's in the word file in order to generate the pdf file--this becomes very complicated)... Is there any other solution...other product that that can interpret the content of the word file and then convert it in pdf?
    Can anyone give me a hint?
    Thanks in advance.

    Thanks for the quick repsonse! That is what I thought but in Aperture (V 3.4.5) I do not have a PDF option under Print!! Is it possibly hidden somewhere?
    You first should get a panel with the page layout, and when you press the "Print" button in the panel,  you'll see the Printer settings. Here you should find the "PDF" button in the lower left corner.

  • How can I convert a PDF/A file into a PDF file with Acrobat Pro X?

    How can I convert a PDF/A file into a PDF file with Acrobat Pro X? I'd like to modifiy the file which I have only as a PDF/A.

    There's two answers if you want to modify the file:
    You can temporarily turn off PDF/A Mode in your preferences, so they don't open as read-only. The problem would be if you do something to the file that violated the PDF/A standard, so you should always run a Preflight check afterwards to make sure.
    If you want to remove the PDF/A header tag, use Preflight again - it's on the Print Production Panel in Acrobat X Pro (which may be hidden, use the options menu on the Tools Pane to show it). There's a profile called "Remove PDF/A information" - choose this and press Analyze and Fix. Nothing else about the file will be altered but when you save and reopen it all the editing tools will become active.

  • How do I convert a web based file to a PDF file?

    How do I convert a web based file to a PDF file? I know that you "Print to File" but for some reason that is not working for me.  I have Adobe Reader X, shouldn't that be able to create a PDF like this, or is there another program that I need to do this?  Thanks.

    Hi, gfrerichs.
    Reader X cannot create a PDF file - it can only view and print existing PDF files.
    In order to create a PDF file (for example, print a webpage as a PDF, as you mentioned), you can purchase our CreatePDF service. This service includes a CreatePDF Printer which can print web pages to PDF.
    Or you could purchase Acrobat, which can also convert webpages to PDF.
    Dave, Adobe

  • When converting a dwf file to a pdf file, only 75% of dwf file is there?

    when I try converting a dwf. file to a pdf. file, only 75% of the dwf. appears in the pdf why?

    Anubha,
    I am using Acrobat X Pro, I have also tried several DWF. Files, with the same results.
    Thanks,
    Michael Caron

  • Convert and combine many image files into a pdf file?

    I have about 250 png and jpg files in a directory, and would like to convert and combine them into a pdf file.
    I wonder what steps to do that in Acrobat Adobe 9 in Windows?
    Requirements are:
    They are named in the order of 0000.png, 0001.jpg, ..., 0250.png, in which I would like to create the pages of the resulting pdf file.
    Also there may be some numbers (such as neither 0010.png nor 0010.jpg exists) missing, but still I would like the images be in the same order after creation of a pdf file.
    I would like the pages in the resulting pdf file look to have the same or similar size.
    But the numbers of pixels of the image files are different. Some are about 2000 x 3500 pixels, and some are about 800 x 1200 pixels.
    I also would like to have control of the spatial resolution such as the dpi parameter
    I also would like to OCR the pdf file (the images are scanned raster images).
    I would like the resulting pdf file to take reasonable storage size on my disk.

    You don't say what version of Acrobat you are using, but I expect you could do it with Acrobat XI's Actions feature. Maybe even in 10.0. Since this is an enterprise deployment forum, I suggest you find a better forum and ask about Actions and Batch Processing.
    hth,
    Ben

  • Convert a number spreadsheet to a PDF file

    how can I convert a numbers spreadsheet to a PDF file without scaling?
    (I would like to share it as a PDF not to print it)
    I have tried to do it several ways but I can't figure out how to do it good because automatically will Fit long sheet on one page

    Hi Abraham.G
    If you are looking to make a PDF from a single tab/sheet Apple has you covered. You still want to use the print dialog. Instead of sending it ot the printer choose PDF:
    And Save as PDF.
    Hope this helps.
    quinn

  • How to convert a webpage program into a pdf file?

    how to convert a webpage program into a pdf file?

    Hi Federico,
    ExportPDF is the program to convert PDF into different Formats(Doc, Docx, xlsx, rtf) and not Vice Versa, I would suggest you to use CreatePDF Web application for converting any other format to PDF.
    For more details on CreatePDF
    https://www.acrobat.com/createpdf/en/home.html
    FAQ to be found here:
    http://forums.adobe.com/community/createpdf?view=documents
    ~Pranav

  • How do you convert a tiff file to a pdf file

    How do you convert a tiff file to a pdf file?

    Hi patbeemer335
    Using Acrobat , Please refer : http://www.adobe.com/in/products/acrobat/convert-jpeg-scan-ocr-to-pdf.html
    For CreatePDF, Please refer : https://www.acrobat.com/createpdf/en/home.html

  • How do i convert a word file into a pdf file?

    How do I convert a word document into a .pdf file?

    Hi wertheca,
    If you have Acrobat, (full version), you can convert a file to PDF by choosing File > Create > PDF from File. Then you choose your Word document, and click Open to convert the file to PDF.
    If you don't have Acrobat, you can use an Acrobat online services subscription to convert almost any format of file to a PDF with just a click or two. For more information, see Acrobat Plus, PDF Pack, Export PDF & More | Acrobat Document Solutions
    I hope this helps.
    Best,
    Sara

  • Embedding files into a .pdf file

    How do I embed files into a .pdf file?  It worked in word but when I converted to .pdf format, I lost the ability to open the embedded file with a click...

    Challenge no. 2 below Pat.  Thanks!
    Dave Janzow
    Director, Business Development, Life Sciences
    UNITRANS INTERNATIONAL CORPORATION
    peace of mind > every time
    [private information removed by moderator]
    All business transactions are based on Unitrans Intl Corporation's terms and conditions, available on request.
    Unitrans Intl Corp. is a certified member of C-TPAT (Customs Trade Partnership against Terrorism).
    Our SVI number for Customs House Brokerage is: unibro00850.
    Please refer to our website for further information on the C-TPAT program.

Maybe you are looking for