Package org.pdfclown.documents.contents.composition

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


    composer.showXObject(
      SampleHelper.createTemplate(document)
      );

    // Wrap the content composer inside a block filter in order to achieve higher-level typographic control!
    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.setHyphenation(true);

    Rectangle2D.Double frame = new Rectangle2D.Double(
      30,
      150,
      pageSize.getWidth() - 110,
      pageSize.getHeight() - 250
      );

    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    StandardType1Font titleFont = new StandardType1Font(
      document,
      StandardType1Font.FamilyEnum.Times,
      true,
      false
      );
    composer.setFont(titleFont,48);
    blockComposer.showText("Welcome"); blockComposer.showBreak();
    StandardType1Font bodyFont = new StandardType1Font(
      document,
      StandardType1Font.FamilyEnum.Times,
      false,
      false
      );
    composer.setFont(bodyFont,16);
    blockComposer.showText("This is an on-the-fly servlet-driven PDF sample document generated by PDF Clown for Java.");
    blockComposer.end();

    // Move past the closed block!
    frame.y = blockComposer.getBoundBox().getMaxY() + 30;
    frame.height -= (blockComposer.getBoundBox().getHeight() + 30);

    // Showing the posted image...
    // Instantiate a jpeg image object!
    Image image = null;
    try
    {
      image = Image.get(
        new Buffer(imageFileFormField.get())
        ); // Abstract image (entity).
    }
    catch(Exception e)
    {/* NOOP. */}
    if(image == null)
    {
      blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
      composer.setFont(bodyFont,12);
      composer.setFillColor(new DeviceRGBColor(1,0,0));
      blockComposer.showText("The file you uploaded wasn't a valid JPEG image!");
      blockComposer.end();

      // Move past the closed block!
      frame.y = blockComposer.getBoundBox().getMaxY() + 20;
      frame.height -= (blockComposer.getBoundBox().getHeight() + 20);
    }
    else
    {
      blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
      composer.setFont(bodyFont,12);
      blockComposer.showText("Here it is the image you uploaded: ");
      blockComposer.end();

      // Move past the closed block!
      frame.y = blockComposer.getBoundBox().getMaxY() + 20;
      frame.height -= (blockComposer.getBoundBox().getHeight() + 20);

      double width = image.getWidth(), height = image.getHeight();
      if(width > frame.getWidth())
      {
        height *= frame.getWidth() / width;
        width = frame.getWidth();
      }
      if(height > frame.getHeight() / 2)
      {
        width *= frame.getHeight() / 2 / height;
        height = frame.getHeight() / 2;
      }
      // Show the image!
      composer.showXObject(
        image.toXObject(document),
        new Point2D.Double(
          (pageSize.getWidth() - 90 - width) / 2 + 20,
          blockComposer.getBoundBox().getMaxY() + 20
          ),
        new Dimension(width,height)
        );
      // Move past the image closed block!
      frame.x = (pageSize.getWidth() - 90 - width) / 2 + 20;
      frame.y += (height + 7);
      frame.height -= (height + 7);
      frame.width = width;
    }

    if (comment != null)
    {
      blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Top);
      composer.setFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Courier,
          false,
          false
          ),
        7
        );
      blockComposer.showText(comment);
      blockComposer.end();
    }

    composer.flush();
  }
View Full Code Here


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

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

    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.begin(new Rectangle2D.Double(300,400,200,100),AlignmentXEnum.Left,AlignmentYEnum.Middle);
    try
    {
      composer.setFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Times,
          false,
          true
          ),
        12
        );
    }
    catch(Exception e)
    {}
    composer.setFillColor(new DeviceRGBColor(115f/255,164f/255,232f/255));
    blockComposer.showText("showText() methods return the actual bounding box of the shown text, allowing to precisely determine its location on the page.");
    blockComposer.end();

    composer.setStrokeColor(new DeviceRGBColor(115f/255,164f/255,232f/255));

    // 3. Inserting contents...
    // Set the font to use!
View Full Code Here

      typographic entities like titles, paragraphs, columns, tables, headers, footers etc.
      When such further abstract levels are available, the final user (developer of consuming
      applications) won't care any more of the details you can see here in the following code lines
      (such as bothering to select the first-letter font...).
    */
    BlockComposer blockComposer = new BlockComposer(composer);

    composer.beginLocalState();

    // Define the block frame that will encompass our contents on the page canvas!
    Rectangle2D frame = new Rectangle2D.Double(
      Margin_X,
      Margin_Y,
      pageSize.getWidth() - Margin_X * 2,
      pageSize.getHeight() - Margin_Y * 2
      );
    // Begin the title block!
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    Font decorativeFont = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "Ruritania-Outline.ttf"
      );
    composer.setFont(decorativeFont,56);
    blockComposer.showText("Chapter 1");
    blockComposer.showBreak();
    composer.setFont(decorativeFont,32);
    blockComposer.showText("Down the Rabbit-Hole");
    // End the title block!
    blockComposer.end();

    // Update the block frame to begin after the title!
    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight(),
      blockComposer.getBoundBox().getWidth(),
      pageSize.getHeight() - Margin_Y - (blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight())
      );
    // Begin the body block!
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    Font bodyFont = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "TravelingTypewriter.otf"
      );
    composer.setFont(bodyFont,14);
    composer.beginLocalState();
    composer.setFont(decorativeFont,28);
    blockComposer.showText("A");
    composer.end();
    blockComposer.showText("lice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'");
    // Define new-paragraph first-line offset!
    Dimension breakSize = new Dimension(24,8); // Indentation (24pt) and top margin (8pt).
    // Begin a new paragraph!
    blockComposer.showBreak(breakSize);
    blockComposer.showText("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.");
    // Begin a new paragraph!
    blockComposer.showBreak(breakSize);
    blockComposer.showText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.");
    // End the body block!
    blockComposer.end();

    composer.end();

    composer.beginLocalState();
    composer.rotate(
      90,
      new Point2D.Double(
        pageSize.getWidth() - 50,
        pageSize.getHeight() - 25
        )
      );
    blockComposer = new BlockComposer(composer);
    blockComposer.begin(
      new Rectangle2D.Double(0,0,300,50),
      AlignmentXEnum.Left,
      AlignmentYEnum.Middle
      );
    composer.setFont(bodyFont,8);
    blockComposer.showText("Generated by PDF Clown on " + new java.util.Date());
    blockComposer.showBreak();
    blockComposer.showText("For more info, visit http://www.pdfclown.org");
    blockComposer.end();
    composer.end();

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

        composer.setStrokeColor(getForeColor());
        composer.drawRectangle(frame);
        composer.fillStroke();
        composer.end();

        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
        composer.setFillColor(getForeColor());
        composer.setFont(
          new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.ZapfDingbats,
            true,
            false
            ),
          (float)(size.getHeight() * 0.8)
          );
        blockComposer.showText(new String(new char[]{getCheckSymbol()}));
        blockComposer.end();

        composer.flush();
      }

      FormXObject offState = new FormXObject(document);
View Full Code Here

        composer.setStrokeColor(getForeColor());
        composer.drawEllipse(frame);
        composer.fillStroke();
        composer.end();

        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
        composer.setFillColor(getForeColor());
        composer.setFont(
          new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.ZapfDingbats,
            true,
            false
            ),
          (float)(size.getHeight() * 0.8)
          );
        blockComposer.showText(new String(new char[]{getRadioSymbol()}));
        blockComposer.end();

        composer.flush();
      }

      FormXObject offState = new FormXObject(document);
View Full Code Here

      composer.end();

      String caption = (String)field.getValue();
      if(caption != null)
      {
        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
        composer.setFillColor(getForeColor());
        composer.setFont(
          new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            true,
            false
            ),
          (float)(size.getHeight() * 0.5)
          );
        blockComposer.showText(caption);
        blockComposer.end();
      }

      composer.flush();
    }
    appearance.getNormal().put(null,normalAppearanceState);
View Full Code Here

    /*
      NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
      Flow-level typographic features are currently not supported: block-level typographic features
      are the foundations upon which flow-level typographic features will sit.
    */
    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.setHyphenation(true);

    Dimension breakSize = new Dimension(0,10);
    // Add the font to the document!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "TravelingTypewriter.otf"
      );

    Rectangle2D frame = new Rectangle2D.Double(
      20,
      150,
      (pageSize.getWidth() - 90 - 20) / 2,
      pageSize.getHeight() - 250
      );
    // NOTE: If you wanna see the block frame that constrains the text, uncomment this line:
    /*
    composer.setStrokeColor(
      new DeviceRGBColor(115f/255,164f/255,232f/255)
      );
    composer.drawRectangle(frame);
    composer.stroke();
    */

    // Showing the 'GNU' image...
    // Instantiate a jpeg image object!
    Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "gnu.jpg"); // Abstract image (entity).
    // Show the image!
    composer.showXObject(
      image.toXObject(document),
      new Point2D.Double(
        (pageSize.getWidth() - 90 - image.getWidth()) / 2 + 20,
        pageSize.getHeight() - 100 - image.getHeight()
        ),
      new Dimension(0,0)
      );

    // Showing the title...
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    composer.setFont(font,24);
    blockComposer.showText("The Free Software Definition");
    blockComposer.end();

    // Showing the copyright note...
    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight() + 32,
      blockComposer.getBoundBox().getWidth(),
      (pageSize.getHeight() - 100 - image.getHeight() - 10) - (blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight() + 32)
      );
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    composer.setFont(font,6);
    blockComposer.showText("Copyright 2004, 2005, 2006 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice is preserved.");

    // Showing the body...
    blockComposer.showBreak(breakSize);
    composer.setFont(font,8.25f);
    Rectangle2D[] frames = new Rectangle2D[]
      {
        new Rectangle2D.Double(
          blockComposer.getBoundBox().getX(),
          pageSize.getHeight() - 100 - image.getHeight() - 10,
          blockComposer.getBoundBox().getWidth()-image.getWidth()/2,
          image.getHeight() + 10
          ),
        new Rectangle2D.Double(
          20 + 20 + (pageSize.getWidth() - 90 - 20) / 2,
          150,
          (pageSize.getWidth() - 90 - 20) / 2,
          (pageSize.getHeight() - 100 - image.getHeight() - 10) - 150
          ),
        new Rectangle2D.Double(
          20 + 20 + (pageSize.getWidth() - 90 - 20) / 2 + image.getWidth()/2,
          pageSize.getHeight() - 100 - image.getHeight() - 10,
          blockComposer.getBoundBox().getWidth()-image.getWidth()/2,
          image.getHeight() + 10
          ),
        new Rectangle2D.Double(
          20,
          150,
          (pageSize.getWidth() - 90 - 20) / 2,
          (pageSize.getHeight() - 100) - 150
          ),
        new Rectangle2D.Double(
          20 + 20 + (pageSize.getWidth() - 90 - 20) / 2,
          150,
          (pageSize.getWidth() - 90 - 20) / 2,
          (pageSize.getHeight() - 100) - 150
          )
      };
    AlignmentYEnum[] alignmentYs = new AlignmentYEnum[]
      {
        AlignmentYEnum.Top,
        AlignmentYEnum.Bottom,
        AlignmentYEnum.Top,
        AlignmentYEnum.Top,
        AlignmentYEnum.Top
      };
    String[] paragraphs = new String[]
      {
        "We maintain this free software definition to show clearly what must be true about a particular software program for it to be considered free software.",
        "\"Free software\" is a matter of liberty, not price. To understand the concept, you should think of \"free\" as in \"free speech\", not as in \"free beer\".",
        "Free software is a matter of the users' freedom to run, copy, distribute, study, change and improve the software. More precisely, it refers to four kinds of freedom, for the users of the software:",
        "* The freedom to run the program, for any purpose (freedom 0).",
        "* The freedom to study how the program works, and adapt it to your needs (freedom 1). Access to the source code is a precondition for this.",
        "* The freedom to redistribute copies so you can help your neighbor (freedom 2).",
        "* The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this.",
        "A program is free software if users have all of these freedoms. Thus, you should be free to redistribute copies, either with or without modifications, either gratis or charging a fee for distribution, to anyone anywhere. Being free to do these things means (among other things) that you do not have to ask or pay for permission.",
        "You should also have the freedom to make modifications and use them privately in your own work or play, without even mentioning that they exist. If you do publish your changes, you should not be required to notify anyone in particular, or in any particular way.",
        "The freedom to use a program means the freedom for any kind of person or organization to use it on any kind of computer system, for any kind of overall job, and without being required to communicate subsequently with the developer or any other specific entity.",
        "The freedom to redistribute copies must include binary or executable forms of the program, as well as source code, for both modified and unmodified versions. (Distributing programs in runnable form is necessary for conveniently installable free operating systems.) It is ok if there is no way to produce a binary or executable form for a certain program (since some languages don't support that feature), but you must have the freedom to redistribute such forms should you find or develop a way to make them.",
        "In order for the freedoms to make changes, and to publish improved versions, to be meaningful, you must have access to the source code of the program. Therefore, accessibility of source code is a necessary condition for free software.",
        "In order for these freedoms to be real, they must be irrevocable as long as you do nothing wrong; if the developer of the software has the power to revoke the license, without your doing anything to give cause, the software is not free.",
        "However, certain kinds of rules about the manner of distributing free software are acceptable, when they don't conflict with the central freedoms. For example, copyleft (very simply stated) is the rule that when redistributing the program, you cannot add restrictions to deny other people the central freedoms. This rule does not conflict with the central freedoms; rather it protects them.",
        "You may have paid money to get copies of free software, or you may have obtained copies at no charge. But regardless of how you got your copies, you always have the freedom to copy and change the software, even to sell copies.",
        "\"Free software\" does not mean \"non-commercial\". A free program must be available for commercial use, commercial development, and commercial distribution. Commercial development of free software is no longer unusual; such free commercial software is very important.",
        "Rules about how to package a modified version are acceptable, if they don't substantively block your freedom to release modified versions. Rules that \"if you make the program available in this way, you must make it available in that way also\" can be acceptable too, on the same condition. (Note that such a rule still leaves you the choice of whether to publish the program or not.) It is also acceptable for the license to require that, if you have distributed a modified version and a previous developer asks for a copy of it, you must send one, or that you identify yourself on your modifications.",
        "In the GNU project, we use \"copyleft\" to protect these freedoms legally for everyone. But non-copylefted free software also exists. We believe there are important reasons why it is better to use copyleft, but if your program is non-copylefted free software, we can still use it.",
        "See Categories of Free Software for a description of how \"free software,\" \"copylefted software\" and other categories of software relate to each other.",
        "Sometimes government export control regulations and trade sanctions can constrain your freedom to distribute copies of programs internationally. Software developers do not have the power to eliminate or override these restrictions, but what they can and must do is refuse to impose them as conditions of use of the program. In this way, the restrictions will not affect activities and people outside the jurisdictions of these governments.",
        "Most free software licenses are based on copyright, and there are limits on what kinds of requirements can be imposed through copyright. If a copyright-based license respects freedom in the ways described above, it is unlikely to have some other sort of problem that we never anticipated (though this does happen occasionally). However, some free software licenses are based on contracts, and contracts can impose a much larger range of possible restrictions. That means there are many possible ways such a license could be unacceptably restrictive and non-free.",
        "We can't possibly list all the possible contract restrictions that would be unacceptable. If a contract-based license restricts the user in an unusual way that copyright-based licenses cannot, and which isn't mentioned here as legitimate, we will have to think about it, and we will probably decide it is non-free.",
        "When talking about free software, it is best to avoid using terms like \"give away\" or \"for free\", because those terms imply that the issue is about price, not freedom. Some common terms such as \"piracy\" embody opinions we hope you won't endorse. See Confusing Words and Phrases that are Worth Avoiding for a discussion of these terms. We also have a list of translations of \"free software\" into various languages.",
        "Finally, note that criteria such as those stated in this free software definition require careful thought for their interpretation. To decide whether a specific software license qualifies as a free software license, we judge it based on these criteria to determine whether it fits their spirit as well as the precise words. If a license includes unconscionable restrictions, we reject it, even if we did not anticipate the issue in these criteria. Sometimes a license requirement raises an issue that calls for extensive thought, including discussions with a lawyer, before we can decide if the requirement is acceptable. When we reach a conclusion about a new issue, we often update these criteria to make it easier to see why certain licenses do or don't qualify.",
        "If you are interested in whether a specific license qualifies as a free software license, see our list of licenses. If the license you are concerned with is not listed there, you can ask us about it by sending us email at <licensing@fsf.org>.",
        "If you are contemplating writing a new license, please contact the FSF by writing to that address. The proliferation of different free software licenses means increased work for users in understanding the licenses; we may be able to help you find an existing Free Software license that meets your needs.",
        "If that isn't possible, if you really need a new license, with our help you can ensure that the license really is a Free Software license and avoid various practical problems.",
        "Another group has started using the term \"open source\" to mean something close (but not identical) to \"free software\". We prefer the term \"free software\" because, once you have heard it refers to freedom rather than price, it calls to mind freedom. The word \"open\" never does that."
      };
    int paragraphIndex = 0;
    int paragraphTextIndex = 0;
    int frameIndex = -1;
    for(
      int paragraphCount = paragraphs.length;
      paragraphIndex < paragraphCount;
      paragraphIndex++
      )
    {
      String paragraph = paragraphs[paragraphIndex];

      paragraphTextIndex = blockComposer.showText(paragraph.substring(paragraphTextIndex)) + paragraphTextIndex;
      if(paragraphTextIndex < paragraph.length())
      {
        if(++frameIndex < frames.length)
        {
          blockComposer.end();

          // New page?
          if(frameIndex == 3)
          {
            // Close current page!
            composer.flush();

            // Create a new page!
            page = new Page(document);
            document.getPages().add(page);
            composer = new PrimitiveComposer(page);
            // Add the background template!
            composer.showXObject(template);
            blockComposer = new BlockComposer(composer);
            blockComposer.setHyphenation(true);
          }

          blockComposer.begin(frames[frameIndex],AlignmentXEnum.Justify,alignmentYs[frameIndex]);
          composer.setFont(font,8.25f);

          // Come back to complete the interrupted paragraph!
          paragraphIndex--;
        }
        else
        {break;}
      }
      else
      {
        paragraphTextIndex = 0;

        blockComposer.showBreak(breakSize);
      }
    }
    blockComposer.end();

    blockComposer.begin(frames[frames.length-1],AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    composer.setFont(font,6);
    blockComposer.showText("This article was crafted with the nice Traveling_Typewriter font (by Carl Krull, www.carlkrull.dk).");
    blockComposer.end();

    composer.flush();
  }
View Full Code Here

    /*
      NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
      Flow-level typographic features are currently not supported: block-level typographic features
      are the foundations upon which flow-level typographic features will sit.
    */
    BlockComposer blockComposer = new BlockComposer(composer);

    Dimension breakSize = new Dimension(0,20); // Size of a paragraph break.
    // Instantiate the page body's font!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "lazyDog.ttf"
      );

    // Showing the page title...
    // Define the box frame to force the page title within!
    Rectangle2D frame = new Rectangle2D.Double(
      20,
      150,
      pageSize.getWidth() - 90,
      pageSize.getHeight() - 250
      );
    // Begin the block!
    blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Top);
    // Set the font to use!
    composer.setFont(font,56);
    // Set the text rendering mode (outline only)!
    composer.setTextRenderMode(TextRenderModeEnum.Stroke);
    // Show the page title!
    blockComposer.showText("Welcome");
    // End the block!
    blockComposer.end();

    // Showing the clown photo...
    // Instantiate a jpeg image object!
    Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "Clown.jpg"); // Abstract image (entity).

    Point2D imageLocation = new Point2D.Double(
      blockComposer.getBoundBox().getX() + blockComposer.getBoundBox().getWidth() - image.getWidth(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight() + 25
      );
    // Show the image!
    composer.showXObject(
      image.toXObject(document),
      imageLocation,
      new Dimension(0,0)
      );

    Rectangle2D descriptionFrame = new Rectangle2D.Double(
      imageLocation.getX(),
      imageLocation.getY() + image.getHeight() + 5,
      image.getWidth(),
      20
      );

    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      imageLocation.getY(),
      blockComposer.getBoundBox().getWidth() - image.getWidth() - 20,
      image.getHeight()
      );
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Middle);
    composer.setFont(font,30);
    blockComposer.showText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
    blockComposer.showBreak(AlignmentXEnum.Center);
    blockComposer.showText("Enjoy!");
    blockComposer.end();

    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY()+blockComposer.getBoundBox().getHeight(),
      pageSize.getWidth() - 90,
      pageSize.getHeight() - 100 - (blockComposer.getBoundBox().getY()+blockComposer.getBoundBox().getHeight())
      );
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    composer.setFont(font,14);
    blockComposer.showText("PS: As promised, since version 0.0.3 PDF Clown has supported");
    // Begin local state!
    /*
      NOTE: Local state is a powerful feature of PDF format as it lets you nest
      multiple graphics contexts on the graphics state stack.
    */
    composer.beginLocalState();
    composer.setFillColor(TextColor_Highlight);
    blockComposer.showText(" embedded latin OpenFont/TrueType and non-embedded Type 1 fonts");
    // End the innermost local state!
    composer.end();
    blockComposer.showText(" along with");
    composer.beginLocalState();
    composer.setFillColor(TextColor_Highlight);
    blockComposer.showText(" paragraph construction facilities");
    composer.end();
    blockComposer.showText(" through the BlockComposer class."); blockComposer.showBreak(breakSize);
    blockComposer.showText("Since version 0.0.4 the content stream stack has been completed, providing ");
    composer.beginLocalState();
    composer.setFillColor(TextColor_Highlight);
    blockComposer.showText("fully object-oriented access to the graphics objects that describe the contents on a page.");
    composer.end();
    blockComposer.showText(" It's a great step towards a whole bunch of possibilities, such as text extraction/replacement, that next releases will progressively exploit."); blockComposer.showBreak(breakSize);
    blockComposer.showText("Since version 0.0.6 it has supported ");
    composer.beginLocalState();
    composer.setFillColor(TextColor_Highlight);
    blockComposer.showText("Unicode");
    composer.end();
    blockComposer.showText(" for OpenFont/TrueType fonts."); blockComposer.showBreak(breakSize);
    composer.setFont(font,8);
    blockComposer.showText("This page was crafted with the nice");
    composer.beginLocalState();
    composer.setFont(font,10);
    blockComposer.showText(" LazyDog font");
    composer.end();
    blockComposer.showText(" (by Paul Neave, www.neave.com)");
    blockComposer.end();

    blockComposer.begin(descriptionFrame,AlignmentXEnum.Right,AlignmentYEnum.Top);
    composer.setFont(font,8);
    blockComposer.showText("Source: http://www.wikipedia.org/");
    blockComposer.end();

    composer.flush();
  }
View Full Code Here

      new Point2D.Double(
        templateSize.getWidth() - 50,
        templateSize.getHeight() - 25
        )
      );
    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.begin(
      new Rectangle2D.Double(0,0,300,50),
      AlignmentXEnum.Left,
      AlignmentYEnum.Middle
      );
    blockComposer.showText("Generated by PDF Clown on " + creationDate);
    blockComposer.showBreak();
    blockComposer.showText("For more info, visit http://www.pdfclown.org");
    blockComposer.end();
    composer.end();

    // End the graphics state!
    composer.end();
View Full Code Here

    document.getPages().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.Justify,
        AlignmentYEnum.Top
        );
      StandardType1Font bodyFont = new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Courier,
        true,
        false
        );
      composer.setFont(bodyFont,32);
      blockComposer.showText("Transformation sample"); blockComposer.showBreak();
      composer.setFont(bodyFont,16);
      blockComposer.showText("Showing the GNU logo placed on the page center, rotated by 25 degrees clockwise.");
      blockComposer.end();
    }
    // Showing the 'GNU' image...
    {
      // Instantiate a jpeg image object!
      Image image = Image.get(
View Full Code Here

TOP

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

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.