title: Edit DirectContent of iTextSharp PdfSmartCopy class
body: <p>At my work sometimes I have to merge from few to few hundreds pdf files. All the time I've been using <code>Writer</code> and <code>ImportedPages</code> classes. But when I have merged all files into one, file size becomes enormous, sum of all merged files sizes, because fonts being attached to every page, and not reused (fonts are embedded to every page, not whole document).</p>
  
  <p>Not very long time ago I found out about <code>PdfSmartCopy</code> class, which reuses embedded fonts and images. And here the problem kicks in. Very often, before merging files together, I have to add additional content to them (images, text). For this purpose I usually use <code>PdfContentByte</code> from <code>Writer</code> object. </p>
  
  <pre><code>Document doc = new Document();    
  PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\test.pdf", FileMode.Create));
  PdfContentByte cb = writer.DirectContent;
  cb.Rectangle(100, 100, 100, 100);
  cb.SetColorStroke(BaseColor.RED);
  cb.SetColorFill(BaseColor.RED);
  cb.FillStroke();
  </code></pre>
  
  <p>When I do similar thing with <code>PdfSmartCopy</code> object, pages are merged, but no additional content being added. Full code of my test with <code>PdfSmartCopy</code>:</p>
  
  <pre><code>using (Document doc = new Document())
          {
              using (PdfSmartCopy copy = new PdfSmartCopy(doc, new FileStream(Path.GetDirectoryName(pdfPath[0]) + "\\testas.pdf", FileMode.Create)))
              {
                  doc.Open();
                  PdfContentByte cb = copy.DirectContent;
                  for (int i = 0; i &lt; pdfPath.Length; i++)
                  {
                      PdfReader reader = new PdfReader(pdfPath[i]);
                      for (int ii = 0; ii &lt; reader.NumberOfPages; ii++)
                      {
                          PdfImportedPage import = copy.GetImportedPage(reader, ii + 1);                            
                          copy.AddPage(import);
                          cb.Rectangle(100, 100, 100, 100);
                          cb.SetColorStroke(BaseColor.RED);
                          cb.SetColorFill(BaseColor.RED);
                          cb.FillStroke();
                          doc.NewPage();// net nesessary line
                          //ColumnText col = new ColumnText(cb);
                          //col.SetSimpleColumn(100,100,500,500);
                          //col.AddText(new Chunk("wdasdasd", PdfFontManager.GetFont(@"C:\Windows\Fonts\arial.ttf", 20)));
                          //col.Go();                            
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>Now I have few questions: </p>
  
  <ol>
  <li>Is it possible to edit <code>PdfSmartCopy</code> object's DirectContent?</li>
  <li>If not, is there another way to merge multiple pdf files into one not increasing its size dramatically and still being able to add additional content to pages while merging?</li>
  </ol>