Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfContentByte


    {
      final Phrase p = createPhrase(node);
      final ColumnConfig cc = createColumnText(node);

      final PdfGraphics2D pg2 = (PdfGraphics2D) getGraphics();
      final PdfContentByte cb = pg2.getRawContentByte();
      ColumnText ct = cc.reconfigure(cb, p);
      ct.setText(p);
      if (ct.go(false) == ColumnText.NO_MORE_COLUMN)
      {
        throw new InvalidReportStateException
View Full Code Here


  private PdfTextSpec computeFont(final RichTextSpec.StyledChunk c)
  {
    final StyleSheet layoutContext = c.getStyleSheet();

    final PdfGraphics2D g2 = (PdfGraphics2D) getGraphics();
    final PdfContentByte cb = g2.getRawContentByte();

    final TypedMapWrapper<Attribute, Object> attributes = new TypedMapWrapper<Attribute, Object>(c.getAttributes());
    final String fontName = attributes.get(TextAttribute.FAMILY, String.class);
    final Number fontSize = attributes.get(TextAttribute.SIZE, 10f, Number.class);
    final String encoding = (String) layoutContext.getStyleProperty(TextStyleKeys.FONTENCODING);
View Full Code Here

    {
      document.open();
      awaitOpenDocument = false;
    }

    final PdfContentByte directContent = writer.getDirectContent();
    final Graphics2D graphics = new PdfGraphics2D(directContent, width, height, metaData);
    final PdfLogicalPageDrawable logicalPageDrawable = createLogicalPageDrawable(logicalPage, page);
    final PhysicalPageDrawable drawable = createPhysicalPageDrawable(logicalPageDrawable, page);
    drawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height));
View Full Code Here

      // step 4: we create a template and a Graphics2D object that
      // corresponds with it
      int w = printPageSize.width;
      int h = printPageSize.height;
      PdfContentByte cb = writer.getDirectContent();
      PdfTemplate tp = cb.createTemplate(w, h);
      Graphics2D g2 = tp.createGraphics(w, h);
      tp.setWidth(w);
      tp.setHeight(h);

      g2.drawImage(image, null, widthBorder, heightBorder);

      g2.dispose();
      cb.addTemplate(tp, 0, 0);

    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
View Full Code Here

            do {
               
                //sets the active page
                template.setActivePage(i);
               
                PdfContentByte cb = writer.getDirectContent();    
               
                Page page = makePage(pageSize, document, template);
               
                graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight());
                        
                //instantiate a PrinterEngine (pass in the Page instance)
                PrintingEngine engine = new PrintingEngine(page);
               
                //make page format
View Full Code Here

            String text = (String) getValue("watermark");
            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(
                    (File) getValue("destfile")));
            float txtwidth = bf.getWidthPoint(text, fontsize);
            for (int i = 1; i <= pagecount; i++) {
                PdfContentByte seitex = stamp.getOverContent(i);
                LwgRectangle recc = reader.getCropBox(i);
                float winkel = (float) Math.atan(recc.getHeight() /
                                                 recc.getWidth());
                float m1 = (float) Math.cos(winkel);
                float m2 = (float) - Math.sin(winkel);
                float m3 = (float) Math.sin(winkel);
                float m4 = (float) Math.cos(winkel);
                float xoff = (float) ( -Math.cos(winkel) * txtwidth / 2 - Math
                                      .sin(winkel)
                                      * fontsize / 2);
                float yoff = (float) (Math.sin(winkel) * txtwidth / 2 - Math
                                      .cos(winkel)
                                      * fontsize / 2);
                seitex.saveState();
                seitex.setGState(gs1);
                seitex.beginText();
                seitex.setFontAndSize(bf, fontsize);
                seitex.setTextMatrix(m1, m2, m3, m4, xoff + recc.getWidth() / 2,
                                     yoff + recc.getHeight() / 2);
                seitex.showText(text);
                seitex.endText();
                seitex.restoreState();
            }
            stamp.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(internalFrame, e.getMessage(), e
                                          .getClass().getName(),
View Full Code Here

      LwgDocument document = new LwgDocument(LwgPageSize.A4);
      // step 2: we create a writer that listens to the document
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
      // step 3: we open the document
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      int rotation;
      int i = 0;
      int p = 0;
      // step 4: we add content
      while (i < n) {
        i++;
        LwgRectangle rect = reader.getPageSizeWithRotation(i);
        float factorx = (x2 - x1) / rect.getWidth();
        float factory = (y1[p] - y2[p]) / rect.getHeight();
        float factor = (factorx < factory ? factorx : factory);
        float dx = (factorx == factor ? 0f : ((x2 - x1) - rect.getWidth() * factor) / 2f);
        float dy = (factory == factor ? 0f : ((y1[p] - y2[p]) - rect.getHeight() * factor) / 2f);
        page = writer.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb.addTemplate(page, 0, -factor, factor, 0, x1 + dx, y2[p] + dy + rect.getHeight() * factor);
        }
        else {
          cb.addTemplate(page, factor, 0, 0, factor, x1 + dx, y2[p] + dy);
        }
        cb.setRGBColorStroke(0xC0, 0xC0, 0xC0);
        cb.rectangle(x3 - 5f, y2[p] - 5f, x4 - x3 + 10f, y1[p] - y2[p] + 10f);
        for (float l = y1[p] - 19; l > y2[p]; l -= 16) {
          cb.moveTo(x3, l);
          cb.lineTo(x4, l);
        }
        cb.rectangle(x1 + dx, y2[p] + dy, rect.getWidth() * factor, rect.getHeight() * factor);
        cb.stroke();
        System.out.println("Processed page " + i);
        p++;
        if (p == pages) {
          p = 0;
          document.newPage();
View Full Code Here

                    BaseFont bf = BaseFont.createFont("Helvetica",
                            BaseFont.WINANSI,
                            false);
                    PdfGState gs1 = new PdfGState();
                    gs1.setBlendMode(PdfGState.BM_OVERLAY);
                    PdfContentByte cb = writer.getDirectContent();
                    cb.saveState();
                    cb.setGState(gs1);
                    cb.beginText();
                    cb.setFontAndSize(bf, 40);
                    cb.setTextMatrix(50, 50);
                    cb.showText(caption);
                    cb.endText();
                    cb.restoreState();

                    label = image.getName();
                    if (label.lastIndexOf('.') > 0) {
                        label = label.substring(0, label.lastIndexOf('.'));
                    }
View Full Code Here

   * @throws BadElementException
   *             on error
   * @throws IOException
   */
  public static LwgImage getInstance(PdfWriter writer, java.awt.Image awtImage, float quality) throws BadElementException, IOException {
    return getInstance(new PdfContentByte(writer), awtImage, quality);
  }
View Full Code Here

                width = LwgPageSize.LETTER.getWidth() - 40;
                height = LwgPageSize.LETTER.getHeight() - 120;
      }
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
            for (int c = 0; c < comps; ++c) {
                LwgImage img = TiffImage.getTiffImage(ra, c + 1);
                if (img != null) {
                    if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                        img.scalePercent(7200f / img.getDpiX(), 7200f / img.getDpiY());
                    }
                  if (adjustSize) {
              document.setPageSize(new LwgRectangle(img.getScaledWidth(),
                  img.getScaledHeight()));
                        document.newPage();
                    img.setAbsolutePosition(0, 0);
                  }
                  else {
                    if (img.getScaledWidth() > width || img.getScaledHeight() > height) {
                            if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                                float adjx = width / img.getScaledWidth();
                                float adjy = height / img.getScaledHeight();
                                float adj = Math.min(adjx, adjy);
                                img.scalePercent(7200f / img.getDpiX() * adj, 7200f / img.getDpiY() * adj);
                            }
                            else
                                img.scaleToFit(width, height);
                    }
                    img.setAbsolutePosition(20, 20);
                        document.newPage();
                        document.add(new Paragraph(tiff_file + " - page " + (c + 1)));
                  }
                    cb.addImage(img);
                    System.out.println("Finished page " + (c + 1));
                }
            }
            ra.close();
            document.close();
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfContentByte

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.