Package org.pdfclown.documents.contents.composition

Examples of org.pdfclown.documents.contents.composition.BlockComposer$Row


        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


    }
    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);
View Full Code Here

    }
    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;
View Full Code Here

    }
    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("Miscellaneous");
      blockComposer.end();
    }

    composer.beginLocalState();
    composer.setLineJoin(LineJoinEnum.Round);
    composer.setLineCap(LineCapEnum.Round);
View Full Code Here

    EnumSet<AlignmentXEnum> xAlignments = EnumSet.allOf(AlignmentXEnum.class);
    EnumSet<AlignmentYEnum> yAlignments = EnumSet.allOf(AlignmentYEnum.class);
    int step = (int)(pageSize.getHeight()) / ((xAlignments.size()-1) * yAlignments.size()+1);

    BlockComposer blockComposer = new BlockComposer(composer);
    Rectangle2D frame = new Rectangle2D.Double(
      30,
      0,
      pageSize.getWidth()-60,
      step/2
      );
    blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
    blockComposer.showText(
      "Simple text alignment"
      );
    blockComposer.end();

    frame = new Rectangle2D.Double(
      30,
      pageSize.getHeight()-step/2,
      pageSize.getWidth()-60,
      step/2 -10
      );
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Bottom);
    composer.setFont(composer.getState().getFont(),10);
    blockComposer.showText(
      "NOTE: showText(...) methods return the actual bounding box of the text shown.\n"
        + "NOTE: The rotation parameter can be freely defined as a floating point value."
      );
    blockComposer.end();

    composer.setFont(composer.getState().getFont(),12);
    int x = 30;
    int y = step;
    int alignmentIndex = 0;
View Full Code Here

    EnumSet<AlignmentXEnum> xAlignments = EnumSet.allOf(AlignmentXEnum.class);
    EnumSet<AlignmentYEnum> yAlignments = EnumSet.allOf(AlignmentYEnum.class);
    int step = (int)(pageSize.getHeight()) / (xAlignments.size() * yAlignments.size()+1);

    BlockComposer blockComposer = new BlockComposer(composer);
    {
      blockComposer.begin(
        new Rectangle2D.Double(
          30,
          0,
          pageSize.getWidth()-60,
          step*.8
          ),
        AlignmentXEnum.Center,
        AlignmentYEnum.Middle
        );
      blockComposer.showText(
        "Text block alignment"
        );
      blockComposer.end();
    }

    // Drawing the text blocks...
    int x = 30;
    int y = (int)(step*1.2);
    for(AlignmentXEnum alignmentX
      : EnumSet.allOf(AlignmentXEnum.class))
    {
      for(AlignmentYEnum alignmentY
        : EnumSet.allOf(AlignmentYEnum.class))
      {
        composer.setFont(
          composer.getState().getFont(),
          12
          );
        composer.showText(
          alignmentX + " " + alignmentY + ":",
          new Point2D.Double(x,y),
          AlignmentXEnum.Left,
          AlignmentYEnum.Middle,
          0
          );

        composer.setFont(
          composer.getState().getFont(),
          8
          );
        for(
          int index = 0;
          index < 2;
          index++
          )
        {
          int frameX;
          switch(index)
          {
            case 0:
              frameX = 150;
              blockComposer.setHyphenation(false);
              break;
            case 1:
              frameX = 360;
              blockComposer.setHyphenation(true);
              break;
            default:
              throw new RuntimeException();
          }

          Rectangle2D frame = new Rectangle2D.Double(
            frameX,
            y-step*.4,
            200,
            step*.8
            );
          blockComposer.begin(frame,alignmentX,alignmentY);
          blockComposer.showText(
            "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details."
            );
          blockComposer.end();

          composer.beginLocalState();
          composer.setLineWidth(.2f);
          composer.setLineDash(5,5,5);
          composer.drawRectangle(frame);
View Full Code Here

    catch(Exception e)
    {throw new RuntimeException(e);}
   
    int stepCount = 5;
    int step = (int)(pageSize.getHeight()) / (stepCount + 1);
    BlockComposer blockComposer = new BlockComposer(composer);
    {
      blockComposer.begin(
        new Rectangle2D.Double(
          30,
          0,
          pageSize.getWidth()-60,
          step*.8
          ),
        AlignmentXEnum.Center,
        AlignmentYEnum.Middle
        );
      blockComposer.showText(
        "Text block line space"
        );
      blockComposer.end();
    }

    // Drawing the text blocks...
    int x = 30;
    int y = (int)(step*1.1);
    blockComposer.getLineSpace().setUnitMode(UnitModeEnum.Relative);
    for(int index = 0; index < stepCount; index++)
    {
      float relativeLineSpace = 0.5f * index;
      blockComposer.getLineSpace().setValue(relativeLineSpace);
     
      composer.setFont(
        composer.getState().getFont(),
        10
        );
      composer.showText(
        relativeLineSpace + ":",
        new Point2D.Double(x,y),
        AlignmentXEnum.Left,
        AlignmentYEnum.Middle,
        0
        );

      composer.setFont(
        composer.getState().getFont(),
        9
        );
      Rectangle2D frame = new Rectangle2D.Double(
        150,
        y-step*.4,
        350,
        step*.9
        );
      blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
      blockComposer.showText(
        "Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (as a floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's double the line height\")."
        );
      blockComposer.end();
     
      composer.beginLocalState();
      composer.setLineWidth(0.2f);
      composer.setLineDash(5,5,5);
      composer.drawRectangle(frame);
View Full Code Here

      pages.add(page);
      Dimension2D pageSize = page.getSize();

      PrimitiveComposer composer = new PrimitiveComposer(page);
      {
        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.setHyphenation(true);
        blockComposer.begin(
          new Rectangle2D.Double(
            Margin,
            Margin,
            (float)pageSize.getWidth() - Margin * 2,
            (float)pageSize.getHeight() - Margin * 2
            ),
          AlignmentXEnum.Left,
          AlignmentYEnum.Top
          );
        StandardType1Font bodyFont = new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Courier,
          true,
          false
          );
        composer.setFont(bodyFont,32);
        blockComposer.showText("Barcode sample"); blockComposer.showBreak();
        composer.setFont(bodyFont,16);
        blockComposer.showText("Showing the EAN-13 Bar Code on different compositions:"); blockComposer.showBreak();
        blockComposer.showText("- page 1: on the lower right corner of the page, 100pt wide;"); blockComposer.showBreak();
        blockComposer.showText("- page 2: on the middle of the page, 1/3-page wide, 25 degree counterclockwise rotated;"); blockComposer.showBreak();
        blockComposer.showText("- page 3: filled page, 90 degree clockwise rotated."); blockComposer.showBreak();
        blockComposer.end();
      }

      // Show the barcode!
      composer.showXObject(
        barcodeXObject,
View Full Code Here

TOP

Related Classes of org.pdfclown.documents.contents.composition.BlockComposer$Row

Copyright © 2018 www.massapicom. 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.