• Agent to generate PDF from .docx using POI4XPages

    By Baxter Jimuk 8 years ago

    Hi, I have a need to automatically email customized letter in PDF to several people (like Microsoft Word’s mail merge I guess although I never try that) at the end of the month.

    I’ve successfully installed poi4xpages in my server and played with the sample database with no issue. I’ve also successfully created the .docx template for the letter and generate them with the button click method all without any issue.

    But for my requirement above, can poi4xpages cater for that? If it’s doable, can someone post a sample code on how to do it? I believe it’s going to be a java agent which I never wrote before but I think the pseudocode will be like following:

    ~~~

    import com.Poi4XPages;// what should this be?

    import lotus.notes.*;

    public class test extends AgentBase {
    try {
    Session s = getSession();
    AgentContext ac = s.getAgentContext();
    Database db = ac.getCurrentDatabase();
    View vw = db.getView(“AllContacts”);
    Document doc = vw.getFirstDocument();
    Document tmpdoc;
    Poi4XPages p4x = new Poi4XPages();// not sure if this is correct or not
    while (doc != null) {
    tmpdoc = vw.getNextDocument(doc);

    String name, address, telephone;
    /*

    * Retrieve a .docx template from a NotesDocument attachment
    * 
    * That template will have <<name>>, <<address>>, and <<telephone>> (just like the sample database)
    * 
    * Pass the name, address, and telephone from the NotesDocument to the .docx template
    * 
    * Create PDF from the .docx just like the pdfOutput = true property
    * 
    * Send an email with the PDF as attachment
    * 
    */
    

    doc.recycle();
    doc = tmpdoc;
    }

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    ~~~

    • By Marcus Loy 8 years ago

      Did you succeded in the meantime with the way above?
      I'm faced to the same issue right now.