No mistery. As you have a single glyph the subset will be the same and 
PdfSmartCopy will include a single instance of the file. The difference comes 
from the width table that has a single element in the case of the subset and 
256 entries for the full embed.

Paulo
  ----- Original Message ----- 
  From: Jason Berk 
  To: Post all your questions about iText here 
  Sent: Saturday, April 24, 2010 4:31 PM
  Subject: Re: [iText-questions] iText 5.0.1 embedded fonts and smartcopy



  anybody know why this happens?  Seems "wrong" to see the same font embedded 
multiple times yet end up with a smaller document.  Short of Document Props > 
Fonts scrolling forever, is there any harm in letting it embed the subset.  My 
main goal was to reduce file size after concat'ing several (~30,000) PDFs.

  Jason


  -----Original Message-----
  From: Jason Berk [mailto:jb...@purdueefcu.com]
  Sent: Fri 4/23/2010 5:14 PM
  To: Post all your questions about iText here
  Subject: [iText-questions] iText 5.0.1 embedded fonts and smartcopy

  I have three fonts which each contain 1 glyph.



  I created 100 identical pdfs that uses this font and then used smartcopy
  to merge all 100 pages.



  The resulting PDF is 184KB and when I look at the document properties,
  it shows the font 100 times (presumably because it was an embedded
  subset).



  I added "myFont.setSubset(false);" and reran the test.



  Now when I view the properties of the merged pdf, I only see my font
  once (as expected), yet the size of my merged PDF grew to 327KB! (not
  expected)



  As I understood it, SmartCopy didn't reuse fonts that were subsets.



  public class Fonts {



        public static final Font VISA;

        public static final Font SCORECARD;

        public static final Font MICR;



        static {

              BaseFont _visa = null;

              BaseFont _scorecard = null;

              BaseFont _micr = null;

              try {

                    _visa = BaseFont.createFont("/fonts/CREDITCARD.ttf",
  BaseFont.WINANSI, BaseFont.EMBEDDED);

                    _visa.setSubset(false); // INCREASES FILE SIZE?!?!

                    _scorecard =
  BaseFont.createFont("/fonts/SCORECARD.ttf", BaseFont.WINANSI,
  BaseFont.EMBEDDED);

                    _scorecard.setSubset(false); // INCREASES FILE
  SIZE?!?!

                    _micr = BaseFont.createFont("/fonts/OCRAEXT.ttf",
  BaseFont.WINANSI, BaseFont.EMBEDDED);

                    _micr.setSubset(false); // INCREASES FILE SIZE?!?!

              } catch (Exception e) {

                    e.printStackTrace();

                    System.exit(1);

              }

              VISA = new Font(_visa, 12);

              SCORECARD = new Font(_scorecard, 12);

              MICR = new Font(_micr, 12);

        }

  }



  private void generateStatements() {

              try {

                    log.info("begin generating statements");

                    Document d = new Document();

                    PdfSmartCopy copy = new PdfSmartCopy(d, new
  FileOutputStream("C:/temp/aMerged.pdf"));

                    d.open();

                    for (int i = 1; i <= 100; i++) {



                          Document document = new Document();

                          PdfWriter.getInstance(document, new
  FileOutputStream("C:/temp/test" + i + ".pdf"));

                          document.open();



                          document.add(new Paragraph("LARGE FONTS",
  Fonts.NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.LARGE_NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.LARGE_BOLD));

                          document.add(new Paragraph("testing our font
  class", Fonts.LARGE_UNDERLINE));

                          document.add(new Paragraph("testing our font
  class", Fonts.LARGE_ITALIC));



                          document.add(new Paragraph("\n\nNORMAL FONTS",
  Fonts.NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.BOLD));

                          document.add(new Paragraph("testing our font
  class", Fonts.UNDERLINE));

                          document.add(new Paragraph("testing our font
  class", Fonts.ITALIC));



                          document.add(new Paragraph("\n\nSMALL FONTS",
  Fonts.NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.SMALL_NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.SMALL_BOLD));

                          document.add(new Paragraph("testing our font
  class", Fonts.SMALL_UNDERLINE));

                          document.add(new Paragraph("testing our font
  class", Fonts.SMALL_ITALIC));



                          document.add(new Paragraph("\n\nCOLORED FONTS",
  Fonts.NORMAL));

                          document.add(new Paragraph("testing our font
  class", Fonts.PEFCU_RED_NORMAL));



                          document.add(new Paragraph("\n\nWHITE FONTS",
  Fonts.NORMAL));

                          Chunk chunk = new Chunk("testing our font
  class", Fonts.WHITE_NORMAL);

                          chunk.setBackground(Colors.BLACK);

                          document.add(new Paragraph(chunk));



                          Chunk chunk2 = new Chunk("testing our font
  class", Fonts.WHITE_BOLD);

                          chunk2.setBackground(Colors.BLACK);

                          document.add(new Paragraph(chunk2));



                          document.add(new Paragraph("\n\nSPECIAL FONTS",
  Fonts.NORMAL));

                          document.add(new Paragraph("A", Fonts.VISA));

                          document.add(new Paragraph("A",
  Fonts.SCORECARD));

                          document.add(new Paragraph("1 2 3 4 5 6 7 8 9
  0", Fonts.MICR));



                          document.close();



                          log.info("merging C:/temp/test" + i + ".pdf");

                          PdfReader reader = new PdfReader("C:/temp/test"
  + i + ".pdf");

                          ByteArrayOutputStream baos = new
  ByteArrayOutputStream();

                          PdfStamper stamper = new PdfStamper(reader,
  baos);

                          stamper.close();

                          reader = new PdfReader(baos.toByteArray());

                          copy.addPage(copy.getImportedPage(reader, 1));



                    }

                    d.close();

                    log.info("finished generating statements");

              } catch (Exception e) {

                    log.fatal(e.getMessage(), e);

              }

        }
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to