title: PDFBox bloated PDF file size
body: <p>Using PDFBox can read Dynamic PDF created by livecycle.  The code below reads then writes back the xml file that used to create the dynamic PDF.  I bit concerned as the resulting file is quite large start out with 647kb pdf.  The new pdf 14000kb.  Anybody know how can reduce the size of the new file produced.  Can set some type of compression when writing back to pdf file?  </p>
  
  <pre><code> PDDocument doc = PDDocument.load("filename");
   doc.setAllSecurityToBeRemoved(true);
   PDDocumentCatalog docCatalog = doc.getDocumentCatalog();
   PDAcroForm form = docCatalog.getAcroForm();
   PDXFA xfa = form.getXFA();
   COSBase cos = xfa.getCOSObject();
   COSStream coss = (COSStream) cos;
   InputStream cosin = coss.getUnfilteredStream();
   Document document = documentBuilder.parse(cosin);
   COSStream cosout = new COSStream(new RandomAccessBuffer());
   OutputStream out = cosout.createUnfilteredStream();
   TransformerFactory tFactory = TransformerFactory.newInstance();
   Transformer transformer = tFactory.newTransformer();
   DOMSource source = new DOMSource(xmlDoc);
   StreamResult result = new StreamResult(out);
   transformer.transform(source, result);
   PDXFA xfaout = new PDXFA(cosout);
   form.setXFA(xfaout);
  </code></pre>