Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gilmaxter opened this issue Dec 27, 2016 · 0 comments
Open

Comments

@gilmaxter
Copy link

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant