Menu

Password Protected Document

Users
dh-s
2007-12-18
2013-04-25
  • dh-s

    dh-s - 2007-12-18

    Hi,
    I have a template document that has been saved with a password.
    Is there any way to pass a password to createDocument so that I can use this Document Template.  If I try calling createDocument without a password then I get a zip exception, but it works fine if I remove the password from the template.
    Thanks,
    David.

     
    • Mirko Nasato

      Mirko Nasato - 2007-12-18

      Hi David,

      No, opening a password protected template is not supported. What's the use case for protecting a template?

      If what you want is to protect the output document (rather than the template) then you can post-process the document through JODConverter and OpenOffice.org and specify a password at that stage (optionally also converting the document to PDF or another format).

      Cheers

      Mirko

       
    • dh-s

      dh-s - 2007-12-18

      Thanks Mirko,
      I pretty much expected that it was not supported, but just had to make sure.  Unfortunately our client wants the templates protected to guard against unauthorised changes to at least some extent.  They do not perceive the same risk with the output docs since we generate these and then print and delete them all in one user operation.
      David.

       
      • Mirko Nasato

        Mirko Nasato - 2007-12-18

        I see. Well if you really need to, I guess you could use JODConverter to unprotect the template before processing it through JOOReports. Convert the document from ODT to ODT (!) passing the password as an import option. You need OpenOffice.org installed and running on the server for JODConverter to work though.

         
    • dh-s

      dh-s - 2007-12-19

      Thanks. I'll look into the JODConverter option.  Should solve the problem.

       
    • dh-s

      dh-s - 2007-12-19

      ok,
      I tried using JODConverter to convert from ODT to ODT, but am getting the following error:
      "unsupported conversion: from OpenDocument Text to OpenDocument Text"

      Bummer.
      I guess that this means it is just not going to work!

      Rgds,
      David

       
    • Mirko Nasato

      Mirko Nasato - 2007-12-19

      No, it should work. An ODT can certainly be saved as ODT, so the error message doesn't make sense. Are you using a custom DocumentFormat?

       
    • dh-s

      dh-s - 2007-12-19

      I've pasted the bit of code I am using below:

          DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
          DocumentFormat informat = new DocumentFormat("OpenDocument Text",
                   DocumentFamily.TEXT, "application/vnd.oasis.opendocument.text", "odt");
          DocumentFormat outformat = new DocumentFormat("OpenDocument Text",
                   DocumentFamily.TEXT, "application/vnd.oasis.opendocument.text", "odt");
          informat.setImportOption("Password", "testpwd");
          File inFile = new File(getDocumentsPath() + "\\" + templateName);
          File outFile = new File(getDocumentsPath() + "\\temp.odt");
          converter.convert(inFile, informat, outFile, outformat);

      The error I am getting is:
      java.lang.IllegalArgumentException: unsupported conversion: from OpenDocument Text to OpenDocument Text
          at  com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:102)

      I'm fairly new to this, but the only thing I knew I was not too sure about was the actual name of the password import option, but I would not have expected an incorrect value here to cause the error I got ?.
      I've had a bit of a look at the source and it seems like the message I am getting should happen based on DocumentFamily.  I assume that I must be doing something wrong, so any advice would be appreciated.

      Thanks,
      David

       
    • Mirko Nasato

      Mirko Nasato - 2007-12-20

      It's almost correct, you just need this additional line:

          outformat.setExportFilter(DocumentFamily.TEXT, "writer8");

      to specify which filter should be used when exporting to 'outformat' - otherwise it'll say "unsupported conversion".

      Alternatively (slightly easier?) you could use the registry to get the default ODT format:

          DocumentFormatRegistry registry = new DefaultDocumentFormatRegistry();
          DocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry);

          DocumentFormat odt = registry.getFormatByFileExtension("odt");
             
          DocumentFormat odtWithPassword = new DocumentFormat(odt.getName(), odt.getFamily(), odt.getMimeType(), odt.getFileExtension());
          odtWithPassword.setImportOption("Password", "secret");

          converter.convert(inputFile, odtWithPassword, outputFile, odt);

       

Log in to post a comment.