コード例 #1
0
    public Example_73()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_73.pdf", FileMode.Create)));

        BufferedStream bis = new BufferedStream(
            new FileStream("data/testPDFs/PDF32000_2008.pdf", FileMode.Open));
        List <PDFobj> objects1 = pdf.Read(bis);

        bis.Close();

        bis = new BufferedStream(
            new FileStream("data/testPDFs/50008-RON.pdf", FileMode.Open));
        List <PDFobj> objects2 = pdf.Read(bis);

        bis.Close();

        pdf.AddObjects(objects1);
        pdf.AddObjects(objects2);

        pdf.Complete();
    }
コード例 #2
0
    public Example_79(String fileNumber, String fileName)
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_79_" + fileNumber + ".pdf", FileMode.Create)));

        BufferedStream bis = new BufferedStream(
            new FileStream("data/testPDFs/" + fileName, FileMode.Open));
        List <PDFobj> objects = pdf.Read(bis);

        bis.Close();

        Image image = new Image(
            objects,
            new BufferedStream(new FileStream(
                                   "images/qrcode.png", FileMode.Open, FileAccess.Read)),
            ImageType.PNG);

        image.SetLocation(100f, 300f);

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

        f1.SetSize(12f);


        List <PDFobj> pages = pdf.GetPageObjects(objects);

        Page page = null;

        for (int i = 0; i < pages.Count; i++)
        {
            page = new Page(pdf, pages[i]);

            page.AddResource(image, objects);
            image.DrawOn(page);

            page.AddResource(f1, objects);
            page.SetBrushColor(Color.blue);
            page.DrawString(f1, "John Smith", 100f, 270f);

            page.Complete(objects);
        }

        pdf.AddObjects(objects);

        pdf.Complete();
    }
コード例 #3
0
    public Example_37()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_37.pdf", FileMode.Create)));

        FileStream fis = new FileStream("data/testPDFs/wirth.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Smalltalk-and-OO.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/InsideSmalltalk1.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/InsideSmalltalk2.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Greenbook.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Bluebook.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Orangebook.pdf", FileMode.Open);

        List <PDFobj> objects = pdf.Read(fis);

        fis.Close();

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

        f1.SetSize(72f);

        TextLine line = new TextLine(f1, "This is a test!");

        line.SetLocation(50f, 350f);
        line.SetColor(Color.peru);

        List <PDFobj> pages = pdf.GetPageObjects(objects);

        foreach (PDFobj pageObj in pages)
        {
            GraphicsState gs = new GraphicsState();
            gs.SetAlphaStroking(0.75f);         // Set alpha for stroking operations
            gs.SetAlphaNonStroking(0.75f);      // Set alpha for nonstroking operations
            pageObj.SetGraphicsState(gs, objects);

            Page page = new Page(pdf, pageObj);
            page.AddResource(f1, objects);
            page.SetBrushColor(Color.blue);
            page.DrawString(f1, "Hello, World!", 50f, 200f);

            line.DrawOn(page);

            page.Complete(objects); // The graphics stack is unwinded automatically
        }
        pdf.AddObjects(objects);

/*
 *      List<Image> images = new List<Image>();
 *      foreach (PDFobj obj in objects.Values) {
 *          if (obj.GetValue("/Subtype").Equals("/Image")) {
 *              float w = float.Parse(obj.GetValue("/Width"));
 *              float h = float.Parse(obj.GetValue("/Height"));
 *              if (w > 500f && h > 500f) {
 *                  images.Add(new Image(pdf, obj));
 *              }
 *          }
 *      }
 *
 *      Font f1 = new Font(pdf, CoreFont.HELVETICA);
 *      f1.SetSize(72f);
 *
 *      Page page = null;
 *      foreach (Image image in images) {
 *          page = new Page(pdf, A4.PORTRAIT);
 *
 *          GraphicsState gs = new GraphicsState();
 *          gs.Set_CA(0.7f);    // Stroking alpha
 *          gs.Set_ca(0.7f);    // Nonstroking alpha
 *          page.SetGraphicsState(gs);
 *
 *          image.ResizeToFit(page, true);
 *
 *          // image.FlipUpsideDown(true);
 *          // image.SetLocation(0f, -image.GetHeight());
 *
 *          // image.SetRotate(ClockWise._180_degrees);
 *          // image.SetLocation(0f, 0f);
 *
 *          image.DrawOn(page);
 *
 *          TextLine text = new TextLine(f1, "Hello, World!");
 *          text.SetColor(Color.blue);
 *          text.SetLocation(150f, 150f);
 *          text.DrawOn(page);
 *
 *          page.SetGraphicsState(new GraphicsState());
 *      }
 */
        pdf.Complete();
    }
コード例 #4
0
    public Example_50(String fileNumber, String fileName)
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_" + fileNumber + ".pdf", FileMode.Create)));

        BufferedStream bis = new BufferedStream(
            new FileStream("data/testPDFs/" + fileName, FileMode.Open));
        List <PDFobj> objects = pdf.Read(bis);

        bis.Close();

        Image image = new Image(
            objects,
            new BufferedStream(new FileStream(
                                   "images/qrcode.png", FileMode.Open, FileAccess.Read)),
            ImageType.PNG);

        image.SetLocation(495f, 65f);
        image.ScaleBy(0.40f);

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

        f1.SetSize(12f);

        Font f2 = new Font(
            objects,
            new FileStream("fonts/Droid/DroidSans-Bold.ttf.stream",
                           FileMode.Open,
                           FileAccess.Read), Font.STREAM);

        f2.SetSize(12f);

        List <PDFobj> pages = pdf.GetPageObjects(objects);
        Page          page  = new Page(pdf, pages[0]);

        // page.InvertYAxis();

        page.AddResource(image, objects);
        page.AddResource(f1, objects);
        page.AddResource(f2, objects);
        Font f3 = page.AddResource(CoreFont.HELVETICA, objects).SetSize(12f);

        image.DrawOn(page);

        float x  = 23f;
        float y  = 185f;
        float dx = 15f;
        float dy = 24f;

        page.SetBrushColor(Color.blue);

        // First Name and Initial
        page.DrawString(f2, "Иван", x, y);

        // Last Name
        page.DrawString(f3, "Jones", x + 258f, y);

        // Social Insurance Number
        page.DrawString(f1, StripSpacesAndDashes("243-590-129"), x + 437f, y, dx);

        // Last Name at Birth
        page.DrawString(f1, "Culverton", x, y += dy);

        // Mailing Address
        page.DrawString(f1, "10 Elm Street", x, y += dy);

        // City
        page.DrawString(f1, "Toronto", x, y + dy);

        // Province or Territory
        page.DrawString(f1, "Ontario", x + 365f, y += dy);

        // Postal Code
        page.DrawString(f1, StripSpacesAndDashes("L7B 2E9"), x + 482f, y, dx);

        // Home Address
        page.DrawString(f1, "10 Oak Road", x, y += dy);

        // City
        y += dy;
        page.DrawString(f1, "Toronto", x, y);

        // Previous Province or Territory
        page.DrawString(f1, "Ontario", x + 365f, y);

        // Postal Code
        page.DrawString(f1, StripSpacesAndDashes("L7B 2E9"), x + 482f, y, dx);

        // Home telephone number
        page.DrawString(f1, "905-222-3333", x, y + dy);
        // Work telephone number
        page.DrawString(f1, "416-567-9903", x + 279f, y += dy);

        // Previous province or territory
        page.DrawString(f1, "British Columbia", x + 452f, y += dy);

        // Move date from previous province or territory
        y += dy;
        page.DrawString(f1, StripSpacesAndDashes("2016-04-12"), x + 452f, y, dx);

        // Date new marital status began
        page.DrawString(f1, StripSpacesAndDashes("2014-11-02"), x + 452f, 467f, dx);

        // First name of spouse
        y = 521f;
        page.DrawString(f1, "Melanie", x, y);
        // Last name of spouse
        page.DrawString(f1, "Jones", x + 258f, y);

        // Social Insurance number of spouse
        page.DrawString(f1, StripSpacesAndDashes("192-760-427"), x + 437f, y, dx);

        // Spouse or common-law partner's address
        page.DrawString(f1, "12 Smithfield Drive", x, 554f);

        // Signature Date
        page.DrawString(f1, "2016-08-07", x + 475f, 615f);

        // Signature Date of spouse
        page.DrawString(f1, "2016-08-07", x + 475f, 651f);

        // Female Checkbox 1
        // xMarkCheckBox(page, 477.5f, 197.5f, 7f);

        // Male Checkbox 1
        XMarkCheckBox(page, 534.5f, 197.5f, 7f);

        // Married
        XMarkCheckBox(page, 34.5f, 424f, 7f);

        // Living common-law
        // XMarkCheckBox(page, 121.5f, 424f, 7f);

        // Widowed
        // XMarkCheckBox(page, 235.5f, 424f, 7f);

        // Divorced
        // XMarkCheckBox(page, 325.5f, 424f, 7f);

        // Separated
        // XMarkCheckBox(page, 415.5f, 424f, 7f);

        // Single
        // XMarkCheckBox(page, 505.5f, 424f, 7f);

        // Female Checkbox 2
        XMarkCheckBox(page, 478.5f, 536.5f, 7f);

        // Male Checkbox 2
        // XMarkCheckBox(page, 535.5f, 536.5f, 7f);

        page.Complete(objects);

        pdf.AddObjects(objects);

        pdf.Complete();
    }