Exemplo n.º 1
0
    public Example_72()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_72.pdf", FileMode.Create)),
                          Compliance.PDF_UA);

        Font f1 = new Font(pdf, new FileStream(
                               "fonts/Droid/DroidSans.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        Font f2 = new Font(pdf, new FileStream(
                               "fonts/Droid/DroidSansFallback.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        pdf.SetTitle("Hello, World!");
        pdf.SetAuthor("你好,世界!");

        Page page = new Page(pdf, Letter.PORTRAIT);

        Bookmark toc = new Bookmark(pdf);

        float x      = 70f;
        float y      = 50f;
        float offset = 20f;

        y += 30f;
        Title title = new Title(f1, "This is a test!", x, y);

        toc.AddBookmark(page, title);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "你好,世界!", x, y);
        title.textLine.SetFallbackFont(f2);
        title.SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "File Header", x, y);
        title.SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

/*
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "File Body");
 *      text.SetLocation(x + offset, y);
 *      toc.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "Cross-Reference Table");
 *      text.SetLocation(x + offset, y);
 *      toc.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      page = new Page(pdf, Letter.PORTRAIT);
 *
 *      y = 50f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "File Trailer");
 *      text.SetLocation(x + offset, y);
 *      toc.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "Incremental Updates");
 *      text.SetLocation(x + offset, y);
 *      Bookmark bm = toc.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "Hello");
 *      text.SetLocation(x + offset, y);
 *      bm = bm.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "World");
 *      text.SetLocation(x + offset, y);
 *      bm = bm.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "Yahoo!!");
 *      text.SetLocation(x + offset, y);
 *      bm.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "Test Test Test ...");
 *      text.SetLocation(x + offset, y);
 *      bm.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      bm = bm.GetParent();
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "Let's see ...");
 *      text.SetLocation(x + offset, y);
 *      bm.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "One more item.");
 *      text.SetLocation(x + offset, y);
 *      toc.AddBookmark(page, text.GetDestinationY(), text.GetText()).AutoNumber(pref);
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 *
 *      y += 30f;
 *      pref = new TextLine(f1);
 *      pref.SetLocation(x, y);
 *      text = new TextLine(f1, "The End :)");
 *      text.SetLocation(x, y);
 *      toc.AddBookmark(page, text.GetDestinationY(), text.GetText());
 *      pref.DrawOn(page);
 *      text.DrawOn(page);
 */
        pdf.Complete();
    }
Exemplo n.º 2
0
    public Example_48()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_48.pdf", FileMode.Create)),
                          Compliance.PDF_UA);

        Font f1 = new Font(pdf, new FileStream(
                               "fonts/OpenSans/OpenSans-Regular.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        Page page = new Page(pdf, Letter.PORTRAIT);

        Bookmark toc   = new Bookmark(pdf);
        Title    title = null;

        float x      = 70f;
        float y      = 50f;
        float offset = 50f;

        y    += 30f;
        title = new Title(f1, "This is a test!", x, y);
        toc.AddBookmark(page, title);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "General", x, y).SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "File Header", x, y).SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "File Body", x, y).SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "Cross-Reference Table", x, y).SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        page = new Page(pdf, Letter.PORTRAIT);

        y     = 50f;
        title = new Title(f1, "File Trailer", x, y).SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "Incremental Updates", x, y).SetOffset(offset);
        Bookmark bm = toc.AddBookmark(page, title).AutoNumber(title.prefix);

        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "Hello", x, y).SetOffset(offset);
        bm    = bm.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "World", x, y).SetOffset(offset);
        bm    = bm.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "Yahoo!!", x, y).SetOffset(offset);
        bm.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "Test Test Test ...", x, y).SetOffset(offset);
        bm.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        bm    = bm.GetParent();
        title = new Title(f1, "Let's see ...", x, y).SetOffset(offset);
        bm.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "One more item.", x, y).SetOffset(offset);
        toc.AddBookmark(page, title).AutoNumber(title.prefix);
        title.DrawOn(page);

        y    += 30f;
        title = new Title(f1, "The End :)", x, y);
        toc.AddBookmark(page, title);
        title.DrawOn(page);

        pdf.Complete();
    }