title: Merging PDF using PDFBOX give scratch file size of 65536 error on AWS lambda only
body: <p>We are using PDFBOX to merge two PDFs</p>
  
  <ol>
  <li>File 1 : 35 KB</li>
  <li>File 2 : 32 KB</li>
  </ol>
  
  <p>While merging, I am getting the error  <code>Expected scratch file size of 65536 but found 61440</code></p>
  
  <p>I am using <code>MemoryUsuageSetting</code> using <code>tempfile</code> for  the merge, as in</p>
  
  <pre><code>pdfMerger.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());
  </code></pre>
  
  <p>Below is the code in my merge routine </p>
  
  <pre><code>List&lt;InputStream&gt; sources (inputsteam of my files to merge)
  mergedPDFOutputStream = new ByteArrayOutputStream();
  cosStream = new COSStream();
  PDFMergerUtility pdfMerger = new PDFMergerUtility();
  pdfMerger.addSources(sources);
  pdfMerger.setDestinationStream(mergedPDFOutputStream);
  pdfMerger.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());
  </code></pre>
  
  <p>While calling the above merge routine in AWS lambda, we are getting the same error (<code>Expected scratch file size of 65536 but found 61440</code>)</p>
  
  <p>However, if I call our PDF merge routine in a Java main program in my local machine, the files are generated successfully. </p>
  
  <p>Below is the stack trace of the error </p>
  
  <pre><code>java.io.IOException: Expected scratch file size of 65536 but found 61440r   at org.apache.pdfbox.io.ScratchFile.enlarge(ScratchFile.java:237)r  at org.apache.pdfbox.io.ScratchFile.getNewPage(ScratchFile.java:167)r   at org.apache.pdfbox.io.ScratchFileBuffer.addPage(ScratchFileBuffer.java:126)r  at org.apache.pdfbox.io.ScratchFileBuffer.&lt;init&gt;(ScratchFileBuffer.java:84)r    at org.apache.pdfbox.io.ScratchFile.createBuffer(ScratchFile.java:403)r at org.apache.pdfbox.cos.COSStream.createRawOutputStream(COSStream.java:271)r   at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:119)r    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:101)r    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:140)r    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:101)r    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:110)r    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:101)r    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneMerge(PDFCloneUtility.java:194)r at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneMerge(PDFCloneUtility.java:225)r at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneMerge(PDFCloneUtility.java:185)r at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneMerge(PDFCloneUtility.java:225)r at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneMerge(PDFCloneUtility.java:174)r at org.apache.pdfbox.multipdf.PDFMergerUtility.appendDocument(PDFMergerUtility.java:558)r   at org.apache.pdfbox.multipdf.PDFMergerUtility.legacyMergeDocuments(PDFMergerUtility.java:391)r at org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:277)r
  </code></pre>
  
  <p>We are using <code>PDFBox</code> version <code>2.0.12</code></p>
  
  <p>Can someone please guide on resolving this issue?</p>
  
  <p>Thanks,
  Anjana</p>