Skip to content

No information on making the code work on a standalone application. #5

@gilmaxter

Description

@gilmaxter

Had to fire this out on my own on making the library work without using servlet , making this work on a standard jframe netbeans application.

Here is what I used, I would like to see this on the main page to help others or atleast make a note of it somewhere so it could be of help to others.

    //Create the word document
    IDocument myDoc = new Document2004();
    
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(".CorrectiveActionForm.doc"));
    chooser.setDialogTitle("Save Doc to Where.");
    chooser.setFileFilter(new FileNameExtensionFilter("Word Document (.doc)", "doc"));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setAcceptAllFileFilterUsed(false);
    
    
    String path = null;

    if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) 
    {
        
      System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
      System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
    } 
    else 
    {
      System.out.println("No Selection ");
      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      JOptionPane.showMessageDialog(this, "File Save Canceled.");
      return;
    }
    
    if(!chooser.getSelectedFile().toString().isEmpty())
    {
        if(!chooser.getSelectedFile().toString().endsWith(".doc"))
        {
            path = chooser.getSelectedFile().toString() + ".doc";
        }
        else 
        {
            path = chooser.getSelectedFile().toString();
        }
    }
    else
    {
      System.out.println("No Selection made");  
      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      JOptionPane.showMessageDialog(this, "File Save Canceled.");
      return; 
    }
    
    
    PrintWriter writer = null;
    try {
    writer = new PrintWriter(path);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
     
    
    SimpleDateFormat format1 = new SimpleDateFormat("MM-dd-yyyy");
    String dateOneFrom = format1.format(new Date());
    
    // sets up creating the document
    myDoc.encoding(Encoding.UTF_8); //or ISO8859-1. Default is UTF-8cvbcv
    myDoc.getHeader().addEle(Paragraph.withPieces(ParagraphPiece.with("Corrective Action Form ").withStyle().bold().create()));
    addTitlePage(myDoc);
    addContent(myDoc);
    
    String myWord = myDoc.getContent(); 

    writer.println(myWord); 
    
    writer.close();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions