Examples of PrimitiveComposer


Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

    // 1. Add the page to the document!
    Page page = new Page(document); // Instantiates the page inside the document context.
    document.getPages().add(page); // Puts the page in the pages collection.

    // 2.1. Create a content composer for the page!
    PrimitiveComposer composer = new PrimitiveComposer(page);

    // 2.2. Create a block composer!
    BlockComposer blockComposer = new BlockComposer(composer);

    // 3. Inserting contents...
    // Define the font to use!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "GenR102.TTF"
      );
    // Define the paragraph break size!
    Dimension breakSize = new Dimension(0,10);
    // Define the text to show!
    String[] titles = new String[]
      {
        "ΑΡΘΡΟ 1",
        "ASARIYA SINTE (1)",
        "Article 1",
        "Article premier",
        "Статья 1",
        "Artículo 1",
        "Artikel 1",
        "Madde 1",
        "Artikel 1",
        "Articolo 1",
        "Artykuł 1",
        "Bend 1",
        "Abala kìíní."
      };
    String[] bodies = new String[]
      {
        "'Ολοι οι άνθρωποι γεννιούνται ελεύθεροι και ίσοι στην αξιοπρέπεια και τα δικαιώματα. Είναι προικισμένοι με λογική και συνείδηση, και οφείλουν να συμπεριφέρονται μεταξύ τους με πνεύμα αδελφοσύνης.",
        "Aduniya kuna n gu ibuna damayo hɛi nɔ dei-dei nn daama nna n burucinitɛrɛ fɔ, n lasabu nna laakari ya nam nn mɔ huro cɛrɛ kuna nyanze tɛrɛ bɔŋɔɔ.",
        "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.",
        "Tous les êtres humains naissent libres et égaux en dignité et en droits. Ils sont doués de raison et de conscience et doivent agir les uns envers les autres dans un esprit de fraternité.",
        "Все люди рождаются свободными и равными в своем достоинстве и правах. Они наделены разумом и совестью и должны поступать в отношении друг друга в духе братства.",
        "Todos los seres humanos nacen libres e iguales en dignidad y derechos y, dotados como están de razón y conciencia, deben comportarse fraternalmente los unos con los otros.",
        "Alle Menschen sind frei und gleich an Würde und Rechten geboren. Sie sind mit Vernunft und Gewissen begabt und sollen einander im Geist der Brüderlichkeit begegnen.",
        "Bütün insanlar hür, haysiyet ve haklar bakımından eşit doğarlar. Akıl ve vicdana sahiptirler ve birbirlerine karşı kardeşlik zihniyeti ile hareket etmelidirler.",
        "Alla människor är födda fria och lika i värde och rättigheter. De har utrustats med förnuft och samvete och bör handla gentemot varandra i en anda av gemenskap.",
        "Tutti gli esseri umani nascono liberi ed eguali in dignità e diritti. Essi sono dotati di ragione e di coscienza e devono agire gli uni verso gli altri in spirito di fratellanza.",
        "Wszyscy ludzie rodzą się wolni i równi pod względem swej godności i swych praw. Są oni obdarzeni rozumem i sumieniem i powinni postępować wobec innych w duchu braterstwa.",
        "Hemû mirov azad û di weqar û mafan de wekhev tên dinyayê. Ew xwedî hiş û şuûr in û divê li hember hev bi zihniyeteke bratiyê bilivin.",
        "Gbogbo ènìyàn ni a bí ní òmìnira; iyì àti è̟tó̟ kò̟ò̟kan sì dó̟gba. Wó̟n ní è̟bùn ti làákàyè àti ti è̟rí-o̟kàn, ó sì ye̟ kí wo̟n ó máa hùwà sí ara wo̟n gé̟gé̟ bí o̟mo̟ ìyá."
      };
    String[] sources = new String[]
      {
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=grk",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=den",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=eng",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=frn",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=rus",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=spn",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=ger",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=trk",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=swd",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=itn",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=pql",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=kdb1",
        "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=yor"
      };
    // Begin the content block!
    blockComposer.begin(
      new Rectangle2D.Double(
        Margin,
        Margin,
        page.getSize().getWidth() - Margin * 2,
        page.getSize().getHeight() - Margin * 2
        ),
      AlignmentXEnum.Justify,
      AlignmentYEnum.Top
      );
    for(
      int index = 0,
        length = titles.length;
      index < length;
      index++
      )
    {
      composer.setFont(font,12);
      blockComposer.showText(titles[index]);
      blockComposer.showBreak();

      composer.setFont(font,11);
      blockComposer.showText(bodies[index]);
      blockComposer.showBreak(AlignmentXEnum.Right);

      composer.setFont(font,8);
      blockComposer.showText("[Source: " + sources[index] + "]");
      blockComposer.showBreak(breakSize,AlignmentXEnum.Justify);
    }
    // End the content block!
    blockComposer.end();

    // 4. Flush the contents into the page!
    composer.flush();
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

    // 3. Define the appearance style to apply to the fields!
    DefaultStyle fieldStyle = new DefaultStyle();
    fieldStyle.setFontSize(12);

    PrimitiveComposer composer = new PrimitiveComposer(page);
    composer.setFont(
      new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Courier,
        true,
        false
        ),
      14
      );

    // 4. Field creation.
    // 4.a. Push button.
    {
      composer.showText(
        "PushButton:",
        new Point2D.Double(140, 68),
        AlignmentXEnum.Right,
        AlignmentYEnum.Middle,
        0
        );

      Widget fieldWidget = new Widget(
        page,
        new Rectangle(150, 50, 136, 36)
        );
      WidgetActions fieldWidgetActions = new WidgetActions(fieldWidget);
      fieldWidget.setActions(fieldWidgetActions);
      fieldWidgetActions.setOnActivate(
        new JavaScript(
          document,
          "app.alert(\"Radio button currently selected: '\" + this.getField(\"myRadio\").value + \"'.\",3,0,\"Activation event\");"
          )
        );
      PushButton field = new PushButton(
        "okButton",
        fieldWidget,
        "Push" // Current value.
        ); // 4.1. Field instantiation.
      fields.add(field); // 4.2. Field insertion into the fields collection.
      fieldStyle.apply(field); // 4.3. Appearance style applied.

      {
        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(new Rectangle2D.Double(296,50,page.getSize().getWidth()-336,36),AlignmentXEnum.Left,AlignmentYEnum.Middle);
        composer.setFont(composer.getState().getFont(),7);
        blockComposer.showText("If you click this push button, a javascript action should prompt you an alert box responding to the activation event triggered by your PDF viewer.");
        blockComposer.end();
      }
    }

    // 4.b. Check box.
    {
      composer.showText(
        "CheckBox:",
        new Point2D.Double(140, 118),
        AlignmentXEnum.Right,
        AlignmentYEnum.Middle,
        0
        );
      CheckBox field = new CheckBox(
        "myCheck",
        new Widget(
          page,
          new Rectangle(150, 100, 36, 36)
          ),
        true // Current value.
        ); // 4.1. Field instantiation.
      fieldStyle.apply(field);
      fields.add(field);
      field = new CheckBox(
        "myCheck2",
        new Widget(
          page,
          new Rectangle(200, 100, 36, 36)
          ),
        true // Current value.
        ); // 4.1. Field instantiation.
      fieldStyle.apply(field);
      fields.add(field);
      field = new CheckBox(
        "myCheck3",
        new Widget(
          page,
          new Rectangle(250, 100, 36, 36)
          ),
        false // Current value.
        ); // 4.1. Field instantiation.
      fields.add(field); // 4.2. Field insertion into the fields collection.
      fieldStyle.apply(field); // 4.3. Appearance style applied.
    }

    // 4.c. Radio button.
    {
      composer.showText(
        "RadioButton:",
        new Point2D.Double(140, 168),
        AlignmentXEnum.Right,
        AlignmentYEnum.Middle,
        0
        );
      RadioButton field = new RadioButton(
        "myRadio",
        /*
          NOTE: A radio button field typically combines multiple alternative widgets.
        */
        new DualWidget[]
        {
          new DualWidget(
            page,
            new Rectangle(150, 150, 36, 36),
            "first"
            ),
          new DualWidget(
            page,
            new Rectangle(200, 150, 36, 36),
            "second"
            ),
          new DualWidget(
            page,
            new Rectangle(250, 150, 36, 36),
            "third"
            )
        },
        "second" // Selected item (it MUST correspond to one of the available widgets' names).
        ); // 4.1. Field instantiation.
      fields.add(field); // 4.2. Field insertion into the fields collection.
      fieldStyle.apply(field); // 4.3. Appearance style applied.
    }

    // 4.d. Text field.
    {
      composer.showText(
        "TextField:",
        new Point2D.Double(140, 218),
        AlignmentXEnum.Right,
        AlignmentYEnum.Middle,
        0
        );
      TextField field = new TextField(
        "myText",
        new Widget(
          page,
          new Rectangle(150, 200, 200, 36)
          ),
        "Carmen Consoli" // Current value.
        ); // 4.1. Field instantiation.
      field.setSpellChecked(false); // Avoids text spell check.
      FieldActions fieldActions = new FieldActions(document);
      field.setActions(fieldActions);
      fieldActions.setOnValidate(
        new JavaScript(
          document,
          "app.alert(\"Text '\" + this.getField(\"myText\").value + \"' has changed!\",3,0,\"Validation event\");"
          )
        );
      fields.add(field); // 4.2. Field insertion into the fields collection.
      fieldStyle.apply(field); // 4.3. Appearance style applied.

      {
        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(new Rectangle2D.Double(360,200,page.getSize().getWidth()-400,36),AlignmentXEnum.Left,AlignmentYEnum.Middle);
        composer.setFont(composer.getState().getFont(),7);
        blockComposer.showText("If you leave this text field after changing its content, a javascript action should prompt you an alert box responding to the validation event triggered by your PDF viewer.");
        blockComposer.end();
      }
    }

    // 4.e. Choice fields.
    {
      // Preparing the item list that we'll use for choice fields (a list box and a combo box (see below))...
      ChoiceItems items = new ChoiceItems(document);
      items.add(new ChoiceItem("Joan Baez")); // NOTE: Explicitly-created item.
      items.add("Tracy Chapman"); // NOTE: Implicitly-created item (syntactic sugar for lazy guys...).
      items.add("Carmen Consoli");
      items.add("Cristina Dona'");
      items.add("PJ Harvey");
      items.add("Billie Holiday");
      items.add("Janis Joplin");
      items.add("Angelique Kidjo");
      items.add("Joni Mitchell");
      items.add("Alanis Morissette");
      items.add("Yael Naim");
      items.add("Sinead O'Connor");
      items.add("Brisa Roche'");
      items.add("Nina Simone");
      items.add("Skin");
      items.add("Fatima Spar");
      items.add("Paola Turci");
      items.add("Sarah Vaughan");

      // 4.e1. List box.
      {
        composer.showText(
          "ListBox:",
          new Point2D.Double(140, 268),
          AlignmentXEnum.Right,
          AlignmentYEnum.Middle,
          0
          );
        ListBox field = new ListBox(
          "myList",
          new Widget(
            page,
            new Rectangle(150, 250, 200, 70)
            )
          ); // 4.1. Field instantiation.
        field.setItems(items); // List items assignment.
        field.setMultiSelect(false); // Multiple items may not be selected simultaneously.
        field.setValue("Carmen Consoli"); // Selected item.
        fields.add(field); // 4.2. Field insertion into the fields collection.
        fieldStyle.apply(field); // 4.3. Appearance style applied.
      }

      // 4.e2. Combo box.
      {
        composer.showText(
          "ComboBox:",
          new Point2D.Double(140, 350),
          AlignmentXEnum.Right,
          AlignmentYEnum.Middle,
          0
          );
        ComboBox field = new ComboBox(
          "myCombo",
          new Widget(
            page,
            new Rectangle(150, 334, 200, 36)
            )
          ); // 4.1. Field instantiation.
        field.setItems(items); // Combo items assignment.
        field.setEditable(true); // Text may be edited.
        field.setSpellChecked(false); // Avoids text spell check.
        field.setValue("Carmen Consoli"); // Selected item.
        fields.add(field); // 4.2. Field insertion into the fields collection.
        fieldStyle.apply(field); // 4.3. Appearance style applied.
      }
    }

    composer.flush();
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

      // 2.1. Associate the page to the stamper!
      stamper.setPage(page);

      // 2.2. Stamping the page number on the foreground...
      {
        PrimitiveComposer foreground = stamper.getForeground();

        foreground.setFont(font,16);
        foreground.setFillColor(redColor);

        Dimension2D pageSize = page.getSize();
        int pageNumber = page.getIndex() + 1;
        boolean pageIsEven = (pageNumber % 2 == 0);
        foreground.showText(
          Integer.toString(pageNumber),
          new Point2D.Double(
            (pageIsEven
              ? margin
              : pageSize.getWidth() - margin),
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

    // Add the page to the document!
    Page page = new Page(document); // Instantiates the page inside the document context.
    document.getPages().add(page); // Puts the page in the pages collection.

    // Create a content composer for the page content stream!
    PrimitiveComposer composer = new PrimitiveComposer(page);

    String[] steps = new String[5];
    Color<?>[] colors = new Color<?>[5];
    Dimension2D pageSize = page.getSize();

    buildSteps(composer, steps, colors, pageSize);

    buildLegend(composer, steps, colors, pageSize);

    composer.flush();
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

    )
  {
    Page page = new Page(document);
    document.getPages().add(page);

    PrimitiveComposer composer = new PrimitiveComposer(page);
    StandardType1Font font = new StandardType1Font(
      document,
      StandardType1Font.FamilyEnum.Courier,
      true,
      false
      );
    composer.setFont(font,12);

    // Note.
    composer.showText("Note annotation:", new Point(35,35));
    Note note = new Note(
      page,
      new Point(50, 50),
      "Note annotation"
      );
    note.setIconType(Note.IconTypeEnum.Help);
    note.setModificationDate(new Date());
    note.setOpen(true);

    // Callout.
    composer.showText("Callout note annotation:", new Point(35,85));
    CalloutNote calloutNote = new CalloutNote(
      page,
      new Rectangle(50, 100, 200, 24),
      "Callout note annotation"
      );
    calloutNote.setJustification(CalloutNote.JustificationEnum.Right);
    calloutNote.setLine(
      new CalloutNote.LineObject(
        page,
        new Point(150,650),
        new Point(100,600),
        new Point(50,100)
        )
      );

    // File attachment.
    composer.showText("File attachment annotation:", new Point(35,135));
    FileAttachment attachment = new FileAttachment(
      page,
      new Rectangle(50, 150, 12, 12),
      new FileSpec(
        EmbeddedFile.get(
          document,
          getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "gnu.jpg"
          ),
        "happyGNU.jpg"
        )
      );
    attachment.setText("File attachment annotation");
    attachment.setIconType(FileAttachment.IconTypeEnum.PaperClip);

    composer.beginLocalState();
   
    // Arrow line.
    composer.showText("Line annotation:", new Point(35,185));
    composer.setFont(font,10);
    composer.showText("Arrow:", new Point(50,200));
    Line line = new Line(
      page,
      new Point(50, 260),
      new Point(200,210)
      );
    line.setFillColor(new DeviceRGBColor(1,0,0));
    line.setStartStyle(Line.LineEndStyleEnum.Circle);
    line.setEndStyle(Line.LineEndStyleEnum.ClosedArrow);
    line.setText("Arrow line annotation");
    line.setCaptionVisible(true);

    // Dimension line.
    composer.showText("Dimension:", new Point(300,200));
    line = new Line(
      page,
      new Point(300,220),
      new Point(500,220)
      );
    line.setLeaderLineLength(20);
    line.setLeaderLineExtensionLength(10);
    line.setText("Dimension line annotation");
    line.setCaptionVisible(true);
   
    composer.end();

    // Scribble.
    composer.showText("Scribble annotation:", new Point(35,285));
    Scribble scribble = new Scribble(
      page,
      new Rectangle(50, 300, 100, 30),
      Arrays.asList(
        Arrays.asList(
          (Point2D)new Point(50,300),
          (Point2D)new Point(70,310),
          (Point2D)new Point(100,320)
          )
        )
      );
    scribble.setText("Scribble annotation");

    // Rectangle.
    composer.showText("Rectangle annotation:", new Point(35,335));
    org.pdfclown.documents.interaction.annotations.Rectangle rectangle = new org.pdfclown.documents.interaction.annotations.Rectangle(
      page,
      new Rectangle(50, 350, 100, 30)
      );
    rectangle.setFillColor(new DeviceRGBColor(1,0,0));
    rectangle.setText("Rectangle annotation");

    // Ellipse.
    composer.showText("Ellipse annotation:", new Point(35,385));
    Ellipse ellipse = new Ellipse(
      page,
      new Rectangle(50, 400, 100, 30)
      );
    ellipse.setFillColor(new DeviceRGBColor(0,0,1));
    ellipse.setText("Ellipse annotation");

    // Rubber stamp.
    composer.showText("Rubber stamp annotation:", new Point(35,435));
    RubberStamp rubberStamp = new RubberStamp(
      page,
      new Rectangle(50, 450, 100, 30),
      RubberStamp.IconTypeEnum.Approved
      );
    rubberStamp.setText("Rubber stamp annotation");

    // Caret.
    composer.showText("Caret annotation:", new Point(35,485));
    Caret caret = new Caret(
      page,
      new Rectangle(50, 500, 100, 30)
      );
    caret.setText("Caret annotation");
    caret.setSymbolType(Caret.SymbolTypeEnum.NewParagraph);

    composer.flush();
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

    // 1. Add a page to the document!
    Page page = new Page(document); // Instantiates the page inside the document context.
    document.getPages().add(page); // Puts the page in the pages collection.

    // 2. Create a content composer for the content stream!
    PrimitiveComposer composer = new PrimitiveComposer(page);

    // 3. Inserting contents...
    Dimension2D pageSize = page.getSize();
    // 3.1. Showing the form on the page...
    {
      // Form 1.
      composer.showXObject(
        form,
        new Point2D.Double(pageSize.getWidth()/2,pageSize.getHeight()/2),
        new Dimension(300,0),
        AlignmentXEnum.Center,
        AlignmentYEnum.Middle,
        45
        );
      // Form 2.
      composer.showXObject(
        form,
        new Point2D.Double(0,pageSize.getHeight()),
        new Dimension(0,300),
        AlignmentXEnum.Left,
        AlignmentYEnum.Bottom,
        0
        );
      // Form 3.
      composer.showXObject(
        form,
        new Point2D.Double(pageSize.getWidth(),pageSize.getHeight()),
        new Dimension(80,200),
        AlignmentXEnum.Right,
        AlignmentYEnum.Bottom,
        0
        );
    }
    // 3.2. Showing the comments on the page...
    {
      BlockComposer blockComposer = new BlockComposer(composer);
      blockComposer.begin(
        new Rectangle2D.Double(
          18,
          18,
          pageSize.getWidth() * .5,
          pageSize.getHeight() * .5
          ),
        AlignmentXEnum.Justify,
        AlignmentYEnum.Top
        );
      StandardType1Font bodyFont = new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Courier,
        true,
        false
        );
      composer.setFont(bodyFont,24);
      blockComposer.showText("Page-to-form sample");
      Dimension2D breakSize = new Dimension(0,8);
      blockComposer.showBreak(breakSize);
      composer.setFont(bodyFont,8);
      blockComposer.showText("This sample shows how to convert a page to a reusable form that can be placed multiple times on other pages scaling, rotating, anchoring and aligning it.");
      blockComposer.showBreak(breakSize);
      blockComposer.showText("On this page you can see some of the above-mentioned transformations:");
      breakSize.setSize(8,8);
      blockComposer.showBreak(breakSize);
      blockComposer.showText("1. anchored to the center of the page, rotated by 45 degrees counterclockwise, 300 point wide (preserved proportions);"); blockComposer.showBreak(breakSize);
      blockComposer.showText("2. anchored to the bottom-left corner of the page, 300 point high (preserved proportions);"); blockComposer.showBreak(breakSize);
      blockComposer.showText("3. anchored to the bottom-right corner of the page, 80 point wide and 200 point high (altered proportions).");
      blockComposer.end();
    }

    // 4. Flush the contents into the content stream!
    composer.flush();
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

            )
          );

        // Drawing the text label on the page...
        Dimension2D pageSize = page.getSize();
        PrimitiveComposer composer = new PrimitiveComposer(page);
        composer.setFont(bodyFont,32);
        composer.showText(
          pageFormat + " (" + pageOrientation + ")"// Text.
          new Point2D.Double(
            pageSize.getWidth() / 2,
            pageSize.getHeight() / 2
            ), // Location: page center.
          AlignmentXEnum.Center, // Place the text on horizontal center of the location.
          AlignmentYEnum.Middle, // Place the text on vertical middle of the location.
          45 // Rotate the text 45 degrees counterclockwise.
          );
        composer.flush();
      }
    }
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

  private PrimitiveComposer createFilter(
    )
  {
    PdfReference reference = page.getFile().register(new PdfStream());

    return new PrimitiveComposer(
      new ContentScanner(
        new Contents(
          reference,
          reference.getIndirectObject(),
          page
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

        );
    }
    catch(Exception e)
    {}

    PrimitiveComposer composer = new PrimitiveComposer(page);
    BlockComposer blockComposer = new BlockComposer(composer);

    /*
      2.1. Goto-URI link.
    */
    {
      blockComposer.begin(new Rectangle2D.Double(30,100,200,50),AlignmentXEnum.Left,AlignmentYEnum.Middle);
      composer.setFont(font,12);
      blockComposer.showText("Goto-URI link");
      composer.setFont(font,8);
      blockComposer.showText("\nIt allows you to navigate to a network resource.");
      composer.setFont(font,5);
      blockComposer.showText("\n\nClick on the box to go to the project's SourceForge.net repository.");
      blockComposer.end();

      try
      {
        /*
          NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked.
        */
        Link link = new Link(
          page,
          new Rectangle(240,100,100,50),
          new GoToURI(
            document,
            new URI("http://www.sourceforge.net/projects/clown")
            )
          );
        link.setBorder(
          new Border(
            document,
            3,
            Border.StyleEnum.Beveled,
            null
            )
          );
      }
      catch(Exception exception)
      {throw new RuntimeException(exception);}
    }

    /*
      2.2. Embedded-goto link.
    */
    {
      // Get the path of the PDF file to attach!
      String filePath = promptPdfFileChoice("Please select a PDF file to attach");

      /*
        NOTE: These statements instruct PDF Clown to attach a PDF file to the current document.
        This is necessary in order to test the embedded-goto functionality,
        as you can see in the following link creation (see below).
      */
      int fileAttachmentPageIndex = page.getIndex();
      String fileAttachmentName = "attachedSamplePDF";
      String fileName = new java.io.File(filePath).getName();
      FileAttachment attachment = new FileAttachment(
        page,
        new Rectangle(0, -20, 10, 10),
        new FileSpec(
          EmbeddedFile.get(
            document,
            filePath
            ),
          fileName
          )
        );
      attachment.setName(fileAttachmentName);
      attachment.setText("File attachment annotation");
      attachment.setIconType(FileAttachment.IconTypeEnum.PaperClip);

      blockComposer.begin(new Rectangle2D.Double(30,170,200,50),AlignmentXEnum.Left,AlignmentYEnum.Middle);
      composer.setFont(font,12);
      blockComposer.showText("Embedded-goto link");
      composer.setFont(font,8);
      blockComposer.showText("\nIt allows you to navigate to a destination within an embedded PDF file.");
      composer.setFont(font,5);
      blockComposer.showText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ").");
      blockComposer.end();

      /*
        NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file
        attached inside the current document as described by the FileAttachment annotation on page 1 of the current document.
      */
      Link link = new Link(
        page,
        new Rectangle(240,170,100,50),
        new GoToEmbedded(
          document,
          new GoToEmbedded.TargetObject(
            document,
            fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document.
            fileAttachmentName, // Name of the file attachment annotation corresponding to the target document.
            null // No sub-target.
            ), // Target represents the document to go to.
          new RemoteDestination(
            document,
            1, // Show the page 2 of the target document.
            Destination.ModeEnum.Fit, // Show the target document page entirely on the screen.
            null // No view parameters.
            ) // The destination must be within the target document.
          )
        );
      link.setBorder(
        new Border(
          document,
          1,
          Border.StyleEnum.Dashed,
          new LineDash(new float[]{8,5,2,5})
          )
        );
    }

    /*
      2.3. Textual link.
    */
    {
      blockComposer.begin(new Rectangle2D.Double(30,240,200,50),AlignmentXEnum.Left,AlignmentYEnum.Middle);
      composer.setFont(font,12);
      blockComposer.showText("Textual link");
      composer.setFont(font,8);
      blockComposer.showText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text.");
      composer.setFont(font,5);
      blockComposer.showText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page.");
      blockComposer.end();

      try
      {
        composer.beginLocalState();
        composer.setFont(font,10);
        composer.setFillColor(new DeviceRGBColor(0,0,1));
        composer.showText(
          "PDF Clown Project's repository at SourceForge.net",
          new Point2D.Double(240,265),
          AlignmentXEnum.Left,
          AlignmentYEnum.Middle,
          0,
          new GoToURI(
            document,
            new URI("http://www.sourceforge.net/projects/clown")
            )
          );
        composer.showText(
          "PDF Clown Project's home page",
          new Point2D.Double(240,285),
          AlignmentXEnum.Left,
          AlignmentYEnum.Bottom,
          -90,
          new GoToURI(
            document,
            new URI("http://www.pdfclown.org")
            )
          );
        composer.end();
      }
      catch(Exception e)
      {}
    }

    composer.flush();
  }
View Full Code Here

Examples of org.pdfclown.documents.contents.composition.PrimitiveComposer

    document.getPages().add(page); // Puts the page in the pages collection.

    Dimension2D pageSize = page.getSize();

    // 2. Create a content composer for the page!
    PrimitiveComposer composer = new PrimitiveComposer(page);

    // 3. Drawing the page contents...
    try
    {
      composer.setFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Courier,
          true,
          false
          ),
        32
        );
    }
    catch(Exception e)
    {throw new RuntimeException(e);}

    {
      BlockComposer blockComposer = new BlockComposer(composer);
      blockComposer.begin(new Rectangle2D.Double(30,0,pageSize.getWidth()-60,50),AlignmentXEnum.Center,AlignmentYEnum.Middle);
      blockComposer.showText("Curves");
      blockComposer.end();
    }

    // 3.1. Arcs.
    {
      float y = 100;
      for(
        int rowIndex = 0;
        rowIndex < 4;
        rowIndex++
        )
      {
        int angleStep = 45;
        int startAngle = 0;
        int endAngle = angleStep;
        float x = 100;
        float diameterX;
        float diameterY;
        switch(rowIndex)
        {
          case 0: default:
            diameterX = 40;
            diameterY = 40;
            break;
          case 1:
            diameterX = 40;
            diameterY = 20;
            break;
          case 2:
            diameterX = 20;
            diameterY = 40;
            break;
          case 3:
            diameterX = 40;
            diameterY = 40;
            break;
        }
        for(
          int index = 0,
            length = 360/angleStep;
          index < length;
          index++
          )
        {
          Rectangle2D arcFrame = new Rectangle2D.Double(x,y,diameterX,diameterY);

          // Drawing the arc frame...
          composer.beginLocalState();
          composer.setLineWidth(.25f);
          composer.setLineDash(3,5,5);
          composer.drawRectangle(arcFrame);
          composer.stroke();
          composer.end();

          // Draw the arc!
          composer.drawArc(arcFrame,startAngle,endAngle);
          composer.stroke();

          endAngle += angleStep;
          switch(rowIndex)
          {
            case 3:
              startAngle += angleStep;
              break;
          }

          x += 50;
        }

        y += diameterY + 10;
      }
    }

    // 3.2. Circle.
    {
      Rectangle2D arcFrame = new Rectangle2D.Double(
        100,
        300,
        100,
        100
        );

      // Drawing the circle frame...
      composer.beginLocalState();
      composer.setLineWidth(.25f);
      composer.setLineDash(3,5,5);
      composer.drawRectangle(arcFrame);
      composer.stroke();
      composer.end();

      // Drawing the circle...
      composer.setFillColor(new DeviceRGBColor(1,0,0));
      composer.drawEllipse(arcFrame);
      composer.fillStroke();
    }

    // 3.3. Horizontal ellipse.
    {
      Rectangle2D arcFrame = new Rectangle2D.Double(
        210,
        300,
        100,
        50
        );

      // Drawing the ellipse frame...
      composer.beginLocalState();
      composer.setLineWidth(.25f);
      composer.setLineDash(3,5,5);
      composer.drawRectangle(arcFrame);
      composer.stroke();
      composer.end();

      // Drawing the ellipse...
      composer.setFillColor(new DeviceRGBColor(0,1,0));
      composer.drawEllipse(arcFrame);
      composer.fillStroke();
    }

    // 3.4. Vertical ellipse.
    {
      Rectangle2D arcFrame = new Rectangle2D.Double(
        320,
        300,
        50,
        100
        );

      // Drawing the ellipse frame...
      composer.beginLocalState();
      composer.setLineWidth(.25f);
      composer.setLineDash(3,5,5);
      composer.drawRectangle(arcFrame);
      composer.stroke();
      composer.end();

      // Drawing the ellipse...
      composer.setFillColor(new DeviceRGBColor(0,0,1));
      composer.drawEllipse(arcFrame);
      composer.fillStroke();
    }

    // 3.5. Spirals.
    {
      float y = 500;
      float spiralWidth = 100;
      composer.setLineWidth(.5f);
      for(
        int rowIndex = 0;
        rowIndex < 3;
        rowIndex++
        )
      {
        float x = 150;
        float branchWidth = .5f;
        float branchRatio = 1;
        for(
          int spiralIndex = 0;
          spiralIndex < 4;
          spiralIndex++
          )
        {
          float spiralTurnsCount;
          switch(rowIndex)
          {
            case 0: default:
              spiralTurnsCount = spiralWidth/(branchWidth*8);
              break;
            case 1:
              spiralTurnsCount = spiralWidth/(branchWidth*8*(spiralIndex*1.15f+1));
              break;
          }
          switch(rowIndex)
          {
            case 2:
              composer.setLineDash(0,10,5);
              composer.setLineCap(LineCapEnum.Round);
              break;
            default:
              break;
          }

          composer.drawSpiral(
            new Point2D.Double(x,y),
            0,
            360*spiralTurnsCount,
            branchWidth,
            branchRatio
            );
          composer.stroke();

          x += spiralWidth + 10;

          switch(rowIndex)
          {
            case 0: default:
              branchWidth += 1;
              break;
            case 1:
              branchRatio += .035;
              break;
          }
          switch(rowIndex)
          {
            case 2:
              composer.setLineWidth(composer.getState().getLineWidth() + .5f);
              break;
          }
        }

        y += spiralWidth + 10;
      }
    }

    // 4. Flush the contents into the page!
    composer.flush();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.