title: DOCX to PDF conversion in Alfresco - size limitation
body: <p>I have written a custom Alfresco scheduler to convert DOCX files to PDF. PS: Alfresco 5.2.3 Enterprise Edition
  I have noticed that Alfresco's OOTB configuration allows only those DOCX files to be converted to PDF whose size is 768 KB. DOCX files above 768 KB are not converted to PDF and exception is thrown in logs.</p>
  
  <p>To overcome this, I have tried setting the following property in alfresco-global to increase the limit to 5 MB.</p>
  
  <pre><code> content.transformer.JodConverter.extensions.docx.pdf.maxSourceSizeKBytes=5120
  </code></pre>
  
  <p>But when I test by uploading a 1.5 MB DOCX file, the following exceptions are thrown in logs.</p>
  
  <pre><code> Caused by: java.lang.StackOverflowError
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:77)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      at org.apache.pdfbox.util.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:153)
  </code></pre>
  
  <p>Code used to transform documents to pdf:</p>
  
  <pre><code>   String mimeType = contentService.getReader(doc, ContentModel.PROP_CONTENT).getMimetype().trim();
     ContentReader docReader = contentService.getReader(doc, ContentModel.PROP_CONTENT);
  
          String pdfName = nodeService.getProperty(doc, ContentModel.PROP_NAME).toString();
  
          String fileExtension = Files.getFileExtension(pdfName);
  
          pdfName = pdfName.replace(fileExtension, "pdf");
  
          String targetMimetype = "application/pdf";
  
          ContentWriter writer = contentService.getWriter(doc, ContentModel.PROP_CONTENT, true);
          writer.setMimetype(targetMimetype); // new mimetype
          writer.setEncoding(docReader.getEncoding()); // original encoding
          nodeService.setProperty(doc,ContentModel.PROP_NAME,pdfName);
  
          // Try and transform the content using the supplied delegate
          ContentTransformer pdfTransformer = contentService.getTransformer(mimeType, MimetypeMap.MIMETYPE_PDF);
  
          pdfTransformer.transform(docReader, writer);
  </code></pre>
  
  <p>Also, I tried configuring OOTB rule on a folder to convert incoming files to PDF. So, the below property is already configured in alfresco-global.</p>
  
  <pre><code>content.transformer.JodConverter.extensions.docx.pdf.maxSourceSizeKBytes=5120
  </code></pre>
  
  <p>And now when I upload a 1.5 MB DOCX file to that folder, the file is not able to upload. I get Failure:504 message.</p>
  
  <p>Any idea what can be the issue ?</p>
  
  <p>Thanks in advance.</p>