title: Trying to attach a file to a pdf using PdfStamper
body: <p>I have a String that i want to attach either to the pdf raw code somehow or, what i'm trying here is adding the string as a text file to the pdf, this is what i've come up with but it does not work.</p>
  <pre><code>Document document = new Document();
  
  String directoryPath = &quot;/storage/emulated/0/Download&quot;;
  
  PdfWriter.getInstance(document, new FileOutputStream(directoryPath+&quot;/Aa.pdf&quot;));
  String data = PaintView.full_string_return();
  System.out.println(data);
  PdfReader reader = new PdfReader(directoryPath+&quot;/Aa.pdf&quot;);
  PdfStamper stamper = new PdfStamper(reader,new FileOutputStream(directoryPath+&quot;/Aa.pdf&quot;) );
  PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(stamper.getWriter(), null, String.format(&quot;data.txt&quot;,data),String.format(&quot;data&quot;,data).getBytes(StandardCharsets.UTF_8));
  stamper.addFileAttachment(String.format(&quot;data&quot;,data),fs);
  stamper.close();
  </code></pre>
  <p>I know i'm not using the pdfWriter here but i use it elsewhere, just added it in case it is messing up something.</p>