title: How do I embed fonts in an existing PDF?
body: <p><strong>Background:</strong></p>
  <p>I have PDF's I am programmatically generating. I need to be able to send the PDF directly to a printer from the server (not through an intermediate application). At the moment I can do all of the above (generate PDF, send to printer), but because the fonts aren't embedded in the PDF the printer is doing font substitution.</p>
  <p><strong>Why the fonts aren't embedded when generated:</strong></p>
  <p>I am creating PDF's using SQL Reporting Services 2008. There is a known issue with SQL Reporting Services in that it will not embed fonts (unless a series of requirements are met - <a href="http://technet.microsoft.com/en-us/library/ms159713%28SQL.100%29.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/library/ms159713%28SQL.100%29.aspx</a>). Don't ask me why, the PDF meets all of MS's listed requirements and the fonts still show up as not embedded - there is no real control over whether the fonts are embedded, so I have accepted that this isn't working and moved on. The suggested workaround from Microsoft (<a href="https://docs.microsoft.com/en-us/archive/blogs/donovans/reporting-services-pdf-renderer-faq" rel="nofollow noreferrer">Link</a> under 'When will Reporting Services do font embedding') is to post process the PDF to manually embed the fonts.</p>
  <p><strong>Goal</strong>
  Take an already generated PDF document, programmatically 'open' it and embed the fonts, resave the PDF.</p>
  <p><strong>Approach</strong>
  I was pointed towards iTextSharp, but most of the examples are for the Java version and I'm having trouble translating to the iTextSharp version (I can't find any documentation for iTextSharp).</p>
  <p>I am working on this post for what I need to do: <a href="https://stackoverflow.com/questions/626632/itext-embed-font-in-a-pdf">Itext embed font in a PDF</a>.</p>
  <p>However for the life of me, I cannot seem to use the ByteArrayOutputStream object. It can't seem to find it. I've researched and researched but nobody seems to say what class it's in or where I find it so I can include it in the using statements. I've even cracked open Reflector and can't seem to find it anywhere.</p>
  <p>This is what I have so far and it compiles etc. etc.
  (result is my byte[] of the generated PDF).</p>
  <pre><code>PdfReader pdf = new PdfReader(result);            
  BaseFont unicode = BaseFont.CreateFont(&quot;Georgia&quot;, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
  // the next line doesn't work as I need a ByteArrayOutputStream variable to pass in
  PdfStamper stamper = new PdfStamper(pdf, MISSINGBYTEARRAYOUTPUTSTREAMVARIABLE);
  stamper.AcroFields.SetFieldProperty(&quot;test&quot;, &quot;textfont&quot;, unicode, null); 
  stamper.Close();
  pdf.Close();
  </code></pre>
  <p>So can anybody either help me with using iTextSharp to embed fonts into a PDF or point me in the right direction?</p>
  <p>I'm more than happy to use any other solutions other than iTextSharp to complete this goal, but it needs to be free and able to be used by a business for an internal application (i.e. Affero GPL).</p>