title: Save text pdf direct to s3 without having to save it locally
body: <p>I am generating pdf files using itext 5 and Java, and saving them locally then saving these local saved files on AWS S3. Is there a way to just send them straight to S3 without having to save them locally. I have seen a few examples but none is working for me.</p>
  <p>This is how am generating the pdf file</p>
  <pre><code> String path = //local directory on my computer
   Document document = new Document();
   PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(path));
   document.open();
   
   // add text to document
   document.close();
  </code></pre>
  <p>This is how I save it on s3</p>
  <pre><code>public void saveFileToS3(String pathLocal, String pathAws) {
     
      // init aws 
  
      PutObjectRequest objectRequest = PutObjectRequest.builder()
          .bucket(bucketName)
          .key(folderName + &quot;/&quot; + pathAws)
          .build();
      
      CompletableFuture&lt;PutObjectResponse&gt; future = s3Client.putObject(objectRequest,
          AsyncRequestBody.fromFile(Paths.get(pathLocal))
      );
      
      future.whenComplete((resp, err) -&gt; {
        try {
          if (resp != null) {
            System.out.println(&quot;Object uploaded. Details: &quot; + resp);
          } else {
            err.printStackTrace();
          }
        } finally {
          s3Client.close();
        }
      });
      
      future.join();
    }
  </code></pre>
  <p><em><strong>String pathLocal</strong></em> is the path where am saving the file locally, while <em><strong>String pathAws</strong></em> is the path on S3 where the file is saved.</p>