Beispiel #1
0
  public void setHeader(Document document, String clientName)
      throws DocumentException, IOException {

    LineSeparator line = new LineSeparator(1, 80, null, Element.ALIGN_CENTER, -5);

    Image img = Image.getInstance(getClass().getResource("img/LISLogo.png"));
    // Image img = Image.getInstance("img/LISLogo.png");
    img.scaleAbsoluteHeight(80);
    img.scaleAbsoluteWidth(200);
    img.setAlignment(Element.ALIGN_CENTER);

    Paragraph clientNameParagraph = new Paragraph();
    clientNameParagraph.setAlignment(Element.ALIGN_CENTER);
    clientNameParagraph.add(clientName);
    clientNameParagraph.setSpacingAfter(12);

    Paragraph investmentRecommendations = new Paragraph("Your Legacy Investment Income Portfolio");
    investmentRecommendations.setAlignment(Element.ALIGN_CENTER);
    investmentRecommendations.add(line);
    investmentRecommendations.setSpacingAfter(4);

    document.add(clientNameParagraph);
    document.add(investmentRecommendations);
    document.add(img);
  }
  // --- GET GROWTH GRAPHS -----------------------------------------------------------------------
  protected PdfPTable getGrowthGraphs() throws Exception {
    PdfPTable growthTable = new PdfPTable(1);
    growthTable.setWidthPercentage(pageWidth);

    // *** height graph ****************************************************
    ByteArrayOutputStream osHeight = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsPNG(osHeight, getHeightGraph(), 680, 350);

    // put image in cell
    cell = new PdfPCell();
    cell.setImage(com.itextpdf.text.Image.getInstance(osHeight.toByteArray()));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingRight(10);
    growthTable.addCell(cell);

    // spacer
    growthTable.addCell(createBorderlessCell("", 30, 1));

    // *** weight graph ****************************************************
    ByteArrayOutputStream osWeight = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsPNG(osWeight, getWeightGraph(), 680, 350);

    // put image in cell
    cell = new PdfPCell();
    cell.setImage(com.itextpdf.text.Image.getInstance(osWeight.toByteArray()));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingRight(10);
    growthTable.addCell(cell);

    return growthTable;
  }
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter.getInstance(document, new FileOutputStream("ImageRotation.pdf"));
      document.open();

      //
      // Rotate image in radian using the setRotation method.
      //
      String filename = "other-sample/src/main/resources/java.gif";
      Image image = Image.getInstance(filename);
      image.setRotation(90f);
      document.add(image);

      //
      // Rotate image in degree using the setRotationDegree method
      //
      String url = "http://localhost/xampp/img/xampp-logo-new.gif";
      image = Image.getInstance(url);
      image.setRotationDegrees(90);
      document.add(image);
    } catch (DocumentException | IOException e) {
      e.printStackTrace();
    } finally {
      document.close();
    }
  }
Beispiel #4
0
 public void addImage(
     Image image, float a, float b, float c, float d, float e, float f, boolean inlineImage)
     throws DocumentException {
   if (!colorized && (!image.isMask() || !(image.getBpc() == 1 || image.getBpc() > 0xff)))
     throw new DocumentException(
         MessageLocalization.getComposedMessage(
             "not.colorized.typed3.fonts.only.accept.mask.images"));
   super.addImage(image, a, b, c, d, e, f, inlineImage);
 }
  public void pintaCodigoBarras() {

    Image imageLogo;
    Image imageBarc = null;
    String imageUrl;

    Font fuente = new Font(FontFamily.HELVETICA, 8, Font.NORMAL, new BaseColor(64, 64, 64));
    BaseColor bkcolor = new BaseColor(255, 255, 255);

    try {

      PdfPTable table = new PdfPTable(new float[] {1, 1, 1, 1, 1});
      // table.setTotalWidth(900);
      table.getDefaultCell().setBorder(0);
      //	imageUrl = PropiedadesJLet.getInstance().getProperty("path.img.logos") +
      // "logo_recibos.png";

      // imageLogo = Image.getInstance(imageUrl);

      int yinic = 805;
      int xinic = 0;

      int posicion = 0; // posicion donde comenzara a imprimir

      // for (int i = 0; i < listcode.size(); i++){

      String codeunic = codvalue;

      // System.out.println(codeunic.substring(0,5) +"-"+ codeunic.substring(6,7));

      imageBarc = getBarcode(documento, writer, codeunic);

      PdfPTable tablein = new PdfPTable(new float[] {1f, 3f, 1f});

      tablein.getDefaultCell().setBorder(0);
      tablein.setTotalWidth(documento.getPageSize().getWidth());

      tablein.addCell(FRAparen.getCelda(" ", fuente, bkcolor, "center")).setBorder(0);
      // tablein.addCell(imageLogo);
      tablein.addCell(FRAparen.getCelda(" ", fuente, bkcolor, "center")).setBorder(0);

      tablein.addCell(FRAparen.getCelda(" ", fuente, bkcolor, "center")).setBorder(0);
      tablein.addCell(imageBarc);
      tablein.addCell(FRAparen.getCelda(" ", fuente, bkcolor, "center")).setBorder(0);

      table.addCell(tablein);

      imageBarc.scaleAbsolute(anchcdba, altocdba);
      imageBarc.setAbsolutePosition(xposicio, yposicio);

      documento.add(imageBarc);

    } catch (Exception e) {

    }
  }
  private PdfPTable buildHeader(String date) throws BadElementException, IOException {
    PdfPCell cell;
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);

    Resource r = appContex.getResource("/img/logo_mairie.png");
    Image img = Image.getInstance(r.getFile().getAbsolutePath());
    cell = new PdfPCell();
    cell.addElement(new Chunk(img, 60, 0));
    cell.setFixedHeight(70);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setPaddingTop(23);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setRowspan(2);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("FICHE EVENEMENTIELLE", FONT_TITLE));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    Resource r2 = appContex.getResource("/img/logo_police_nc.jpg");
    Image img2 = Image.getInstance(r2.getFile().getAbsolutePath());
    cell = new PdfPCell();
    cell.addElement(new Chunk(img2, 130, 0));
    cell.setFixedHeight(70);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setPaddingTop(23);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setRowspan(2);
    table.addCell(cell);

    cell =
        new PdfPCell(
            new Phrase(
                "Fiche éditée le "
                    + date
                    + "\npar "
                    + authHelper.getCurrentUser().getAgent().getNom()
                    + " "
                    + authHelper.getCurrentUser().getAgent().getPrenom(),
                FONT_TITLE_LIGHT));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    table.setSpacingBefore(5);
    table.setSpacingAfter(5);

    return table;
  }
Beispiel #7
0
 /**
  * Adds the different pages inside a single TIFF file to a document.
  *
  * @param document the document to which the pages have to be added
  * @param path the path to the TIFF file
  * @throws DocumentException
  * @throws IOException
  */
 public static void addTif(Document document, String path) throws DocumentException, IOException {
   RandomAccessFileOrArray ra = new RandomAccessFileOrArray(path);
   int n = TiffImage.getNumberOfPages(ra);
   Image img;
   for (int i = 1; i <= n; i++) {
     img = TiffImage.getTiffImage(ra, i);
     img.scaleToFit(523, 350);
     document.add(img);
   }
 }
 private static Element createCleanBarcode(
     PdfContentByte cb, String numero, float width, float height) {
   Barcode128 code128 = new Barcode128();
   code128.setCode(numero);
   Image barcodeImage = code128.createImageWithBarcode(cb, null, null);
   barcodeImage.setAlignment(Image.ALIGN_CENTER);
   // barcodeImage.setWidthPercentage(75f);
   barcodeImage.scaleToFit(width, height);
   return barcodeImage;
 }
Beispiel #9
0
  private static void imageToPDF(String folder, Collection<Path> all) {

    for (Path path : all) {

      Document document = new Document();

      String absolutePathInput = path.toFile().getAbsolutePath();
      String absolutePathOutput = folder + "/" + path.getFileName() + ".pdf";

      if (absolutePathInput.endsWith(".gif")
          ||
          //
          absolutePathInput.endsWith(".GIF")
          ||
          //
          absolutePathInput.endsWith(".jpg")
          ||
          //
          absolutePathInput.endsWith(".JPG")
          ||
          //
          absolutePathInput.endsWith(".png")
          ||
          //
          absolutePathInput.endsWith(".PNG")) {

        try {
          FileOutputStream fos = new FileOutputStream(absolutePathOutput);
          PdfWriter writer = PdfWriter.getInstance(document, fos);
          writer.open();
          document.open();

          int indentation = 0;

          Image image = Image.getInstance(absolutePathInput);
          float scaler =
              ((document.getPageSize().getWidth()
                          - document.leftMargin()
                          - document.rightMargin()
                          - indentation)
                      / image.getWidth())
                  * 100;

          image.scalePercent(scaler);

          document.add(image);
          document.close();
          writer.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Beispiel #10
0
 private void addToLine(PdfChunk chunk) {
   if (chunk.changeLeading && chunk.isImage()) {
     Image img = chunk.getImage();
     float f =
         img.getScaledHeight()
             + chunk.getImageOffsetY()
             + img.getBorderWidthTop()
             + img.getSpacingBefore();
     if (f > height) height = f;
   }
   line.add(chunk);
 }
Beispiel #11
0
 /**
  * Reads a BMP from a stream. The stream is not closed. The BMP may not have a header and be
  * considered as a plain DIB.
  *
  * @param is the stream
  * @param noHeader true to process a plain DIB
  * @param size the size of the DIB. Not used for a BMP
  * @throws IOException on error
  * @return the image
  */
 public static Image getImage(InputStream is, boolean noHeader, int size) throws IOException {
   BmpImage bmp = new BmpImage(is, noHeader, size);
   try {
     Image img = bmp.getImage();
     img.setDpi(
         (int) (bmp.xPelsPerMeter * 0.0254d + 0.5d), (int) (bmp.yPelsPerMeter * 0.0254d + 0.5d));
     img.setOriginalType(Image.ORIGINAL_BMP);
     return img;
   } catch (BadElementException be) {
     throw new ExceptionConverter(be);
   }
 }
Beispiel #12
0
 /**
  * Reads a BMP from an url.
  *
  * @param url the url
  * @throws IOException on error
  * @return the image
  */
 public static Image getImage(URL url) throws IOException {
   InputStream is = null;
   try {
     is = url.openStream();
     Image img = getImage(is);
     img.setUrl(url);
     return img;
   } finally {
     if (is != null) {
       is.close();
     }
   }
 }
Beispiel #13
0
  public void addTitlePage(Document document, CustomerOrder customerOrder)
      throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);
    Image image = null;
    try {
      image = Image.getInstance("img/gfcLogo.jpg");
      image.scaleAbsolute(100f, 100f);
      image.setAlignment(Image.ALIGN_LEFT);
    } catch (IOException e) {
      e.printStackTrace();
    }
    document.add(image);
    // Lets write a big header
    Phrase invoice = new Phrase();
    invoice.add(new Chunk("Generation For Christ", companyName));
    invoice.add(new Chunk("                                   Invoice", companyName));
    preface.add(new Paragraph(invoice));
    // preface.add(new Paragraph( "));

    preface.add(new Paragraph("                      We Make Disciples", companySlogan));
    // preface.add(new Paragraph( "                Invoice", companyName));
    // addEmptyLine(preface, 1);
    Date date = new Date();
    String dateFormat = new SimpleDateFormat("dd/MM/yyyy").format(date);
    preface.add(
        new Paragraph(
            "                                                                                                                                         DATE:   "
                + dateFormat,
            details));
    preface.add(
        new Paragraph(
            "25 James Street, Dandenong                                                                                   ORDER ID:    "
                + customerOrder.getOrderId(),
            details));
    preface.add(new Paragraph("Melbourne, Victoria, 3175", details));
    preface.add(new Paragraph("Phone # ", details));

    // Will create: Report generated by: _name, _date
    // preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " +
    // new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    //         smallBold));
    // addEmptyLine(preface, 3);
    // preface.add(new Paragraph("This document contains confidential information of GFC's member",
    //         smallBold));

    document.add(preface);
    // Start a new page
    // document.newPage();
  }
Beispiel #14
0
 private Image indexedModel(byte bdata[], int bpc, int paletteEntries) throws BadElementException {
   Image img = new ImgRaw(width, height, 1, bpc, bdata);
   PdfArray colorspace = new PdfArray();
   colorspace.add(PdfName.INDEXED);
   colorspace.add(PdfName.DEVICERGB);
   byte np[] = getPalette(paletteEntries);
   int len = np.length;
   colorspace.add(new PdfNumber(len / 3 - 1));
   colorspace.add(new PdfString(np));
   PdfDictionary ad = new PdfDictionary();
   ad.put(PdfName.COLORSPACE, colorspace);
   img.setAdditional(ad);
   return img;
 }
 private Image loadDrawable(int resId, float scale) {
   Drawable d = mContext.getResources().getDrawable(resId);
   BitmapDrawable bitDw = ((BitmapDrawable) d);
   Bitmap bmp = bitDw.getBitmap();
   ByteArrayOutputStream stream = new ByteArrayOutputStream();
   bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
   Image image = null;
   try {
     image = Image.getInstance(stream.toByteArray());
     image.scaleAbsolute(scale, scale);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return image;
 }
Beispiel #16
0
  private PdfPTable getHeader() throws DocumentException, IOException {

    PdfPTable table = new PdfPTable(1);

    table.setWidthPercentage(100);

    Image image = Image.getInstance(getClass().getResource("/images/SLA_header.png"));
    image.scalePercent(42);
    PdfPCell cell = new PdfPCell(image);
    cell.setBorder(0);
    cell.setPadding(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    return table;
  }
 /**
  * Main method.
  *
  * @param args no arguments needed
  * @throws DocumentException
  * @throws IOException
  */
 public static void main(String[] args) throws IOException, DocumentException {
   // step 1
   Document document = new Document(PageSize.POSTCARD, 30, 30, 30, 30);
   // step 2
   PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
   // step 3
   document.open();
   // step 4
   // Create and add a Paragraph
   Paragraph p = new Paragraph("Foobar Film Festival", new Font(FontFamily.HELVETICA, 22));
   p.setAlignment(Element.ALIGN_CENTER);
   document.add(p);
   // Create and add an Image
   Image img = Image.getInstance(RESOURCE);
   img.setAbsolutePosition(
       (PageSize.POSTCARD.getWidth() - img.getScaledWidth()) / 2,
       (PageSize.POSTCARD.getHeight() - img.getScaledHeight()) / 2);
   document.add(img);
   // Now we go to the next page
   document.newPage();
   document.add(p);
   document.add(img);
   // Add text on top of the image
   PdfContentByte over = writer.getDirectContent();
   over.saveState();
   float sinus = (float) Math.sin(Math.PI / 60);
   float cosinus = (float) Math.cos(Math.PI / 60);
   BaseFont bf = BaseFont.createFont();
   over.beginText();
   over.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
   over.setLineWidth(1.5f);
   over.setRGBColorStroke(0xFF, 0x00, 0x00);
   over.setRGBColorFill(0xFF, 0xFF, 0xFF);
   over.setFontAndSize(bf, 36);
   over.setTextMatrix(cosinus, sinus, -sinus, cosinus, 50, 324);
   over.showText("SOLD OUT");
   over.endText();
   over.restoreState();
   // Add a rectangle under the image
   PdfContentByte under = writer.getDirectContentUnder();
   under.saveState();
   under.setRGBColorFill(0xFF, 0xD7, 0x00);
   under.rectangle(5, 5, PageSize.POSTCARD.getWidth() - 10, PageSize.POSTCARD.getHeight() - 10);
   under.fill();
   under.restoreState();
   // step 4
   document.close();
 }
  public static void exportImg() {
    Document document = null;
    try {
      //            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
      // BaseFont.NOT_EMBEDDED);// 设置中文字体
      //            Font headFont = new Font(bfChinese, 10, Font.NORMAL);// 设置字体大小

      document = new Document();
      PdfWriter.getInstance(document, new FileOutputStream("D:/test/img.pdf"));
      // 设定文档的作者
      document.addAuthor("林计钦"); // 测试无效
      document.open();
      document.add(new Paragraph("你好,Img!"));
      // 读取一个图片
      Image image = Image.getInstance("D:/test/1.jpg");
      // 插入一个图片
      document.add(image);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (DocumentException e) {
      e.printStackTrace();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (document != null) {
        document.close();
      }
    }
  }
Beispiel #19
0
 /**
  * Constructs a deep copy of a <CODE>PdfPCell</CODE>.
  *
  * @param cell the <CODE>PdfPCell</CODE> to duplicate
  */
 public PdfPCell(PdfPCell cell) {
   super(cell.llx, cell.lly, cell.urx, cell.ury);
   cloneNonPositionParameters(cell);
   verticalAlignment = cell.verticalAlignment;
   paddingLeft = cell.paddingLeft;
   paddingRight = cell.paddingRight;
   paddingTop = cell.paddingTop;
   paddingBottom = cell.paddingBottom;
   phrase = cell.phrase;
   fixedHeight = cell.fixedHeight;
   minimumHeight = cell.minimumHeight;
   noWrap = cell.noWrap;
   colspan = cell.colspan;
   rowspan = cell.rowspan;
   if (cell.table != null) table = new PdfPTable(cell.table);
   image = Image.getInstance(cell.image);
   cellEvent = cell.cellEvent;
   useDescender = cell.useDescender;
   column = ColumnText.duplicate(cell.column);
   useBorderPadding = cell.useBorderPadding;
   rotation = cell.rotation;
   id = cell.id;
   role = cell.role;
   if (cell.accessibleAttributes != null)
     accessibleAttributes = new HashMap<PdfName, PdfObject>(cell.accessibleAttributes);
   headers = cell.headers;
 }
 /**
  * Gets the X value for centering the watermark image
  *
  * @param r rectangle
  * @param img image
  * @return
  */
 protected static float getCenterX(final Rectangle r, final Image img) {
   float x = 0;
   final float pdfwidth = r.getWidth();
   final float imgwidth = img.getWidth();
   x = (pdfwidth - imgwidth) / 2;
   return x;
 }
 /**
  * Gets the Y value for centering the watermark image
  *
  * @param r rectangle
  * @param img image
  * @return
  */
 protected static float getCenterY(final Rectangle r, final Image img) {
   float y = 0;
   final float pdfheight = r.getHeight();
   final float imgheight = img.getHeight();
   y = (pdfheight - imgheight) / 2;
   return y;
 }
 public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
   try {
     PdfContentByte cb = canvases[PdfPTable.BACKGROUNDCANVAS];
     PdfPatternPainter patternPainter =
         cb.createPattern(image.getScaledWidth(), image.getScaledHeight());
     image.setAbsolutePosition(0, 0);
     patternPainter.addImage(image);
     cb.saveState();
     cb.setPatternFill(patternPainter);
     cb.rectangle(
         position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
     cb.fill();
     cb.restoreState();
   } catch (DocumentException e) {
     throw new ExceptionConverter(e);
   }
 }
Beispiel #23
0
 public static void main(String[] args) {
   Document document = new Document();
   try {
     PdfWriter.getInstance(document, new FileOutputStream("Image.pdf"));
     document.open();
     Image image1 =
         Image.getInstance(GuideImage.class.getResource("/itextpdf_image_watermark.png"));
     document.add(image1);
     String imageUrl =
         "http://jenkov.com/images/" + "20081123-20081123-3E1W7902-small-portrait.jpg";
     Image image2 = Image.getInstance(new URL(imageUrl));
     document.add(image2);
     document.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Beispiel #24
0
 /**
  * Gets the difference between the "normal" leading and the maximum size (for instance when there
  * are images in the chunk and the leading has to be taken into account).
  *
  * @return an extra leading for images
  * @since 2.1.5
  */
 float[] getMaxSize() {
   float normal_leading = 0;
   float image_leading = -10000;
   PdfChunk chunk;
   for (int k = 0; k < line.size(); ++k) {
     chunk = line.get(k);
     if (!chunk.isImage()) {
       normal_leading = Math.max(chunk.font().size(), normal_leading);
     } else {
       Image img = chunk.getImage();
       if (chunk.changeLeading()) {
         float height = img.getScaledHeight() + chunk.getImageOffsetY() + img.getSpacingBefore();
         image_leading = Math.max(height, image_leading);
       }
     }
   }
   return new float[] {normal_leading, image_leading};
 }
 public void createPdf(String dest) throws IOException, DocumentException {
   Document document = new Document();
   PdfWriter.getInstance(document, new FileOutputStream(dest));
   document.open();
   PdfPTable table = new PdfPTable(2);
   PdfPCell cell = new PdfPCell();
   Image image = Image.getInstance(IMG1);
   cell.setCellEvent(new TiledImageBackground(image));
   cell.setFixedHeight(770);
   table.addCell(cell);
   cell = new PdfPCell();
   image = Image.getInstance(IMG2);
   cell.setCellEvent(new TiledImageBackground(image));
   cell.setFixedHeight(770);
   table.addCell(cell);
   document.add(table);
   document.close();
 }
  @Override
  public void addText(PdfPCell cell, String text) {
    String[] parts = text.split("->");

    super.addText(cell, parts[0] + "\n\n");

    try {
      Image image = Image.getInstance("icons/arrow.png");
      image.scalePercent(30F);
      image.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(image);
    } catch (BadElementException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    super.addText(cell, "\n" + parts[1]);
  }
 private static void createCheckbox(
     PdfWriter writer,
     Document accountingDocument,
     Font font,
     String[] label,
     int xPosition,
     int yPosition,
     boolean[] checked,
     int pageNr) {
   PdfContentByte canvas = writer.getDirectContent();
   //    Rectangle rect;
   //    PdfFormField field;
   //    RadioCheckField checkbox;
   try {
     Image checkbox_checked =
         Image.getInstance(MainWindow.class.getResource("checkbox_checked.jpg"));
     checkbox_checked.scaleAbsolute(10f, 10f);
     Image checkbox = Image.getInstance(MainWindow.class.getResource("checkbox.jpg"));
     checkbox.scaleAbsolute(10f, 10f);
     for (int i = 0; i < label.length; i++) {
       Image checkboxImage;
       if (checked[i]) {
         checkboxImage = Image.getInstance(checkbox_checked);
       } else {
         checkboxImage = Image.getInstance(checkbox);
       }
       checkboxImage.setAbsolutePosition(xPosition, (yPosition - 10 - i * 15));
       accountingDocument.add(checkboxImage);
       ColumnText.showTextAligned(
           canvas,
           Element.ALIGN_LEFT,
           new Phrase(label[i], font),
           (xPosition + 16),
           (yPosition - 8 - i * 15),
           0);
     }
     // TODO: for JDK7 use Multicatch
   } catch (Exception e) { // com.itextpdf.text.DocumentException | java.io.IOException e) {
     UtilityBox.getInstance()
         .displayErrorPopup(
             "Abrechnung", "Fehler beim Erstellen der Abrechnung: " + e.getMessage());
   }
 }
 private void applyAttributes(Element e, Attributes attributes) {
   String align = attributes.getString("align");
   if ("center".equalsIgnoreCase(align)) {
     if (e instanceof Image) {
       ((Image) e).setAlignment(Image.MIDDLE);
     } else if (e instanceof Paragraph) {
       ((Paragraph) e).setAlignment(Element.ALIGN_CENTER);
     }
   }
 }
  /**
   * Creates a PDF with information about the movies
   *
   * @param filename the name of the PDF file that will be created.
   * @throws DocumentException
   * @throws IOException
   * @throws SQLException
   */
  public void createPdf(String filename) throws IOException, DocumentException, SQLException {

    // step 1
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    Rectangle rect = new Rectangle(0, 806, 36, 842);
    rect.setBackgroundColor(BaseColor.RED);
    document.add(rect);
    document.add(new Paragraph("Hello World!"));
    Image image = Image.getInstance(RESOURCE);
    image.scaleToFit(500, 500);
    // step 4
    document.add(image);
    // step 5
    document.close();
  }
Beispiel #30
0
 /**
  * Returns the height of the cell.
  *
  * @return the height of the cell
  * @since 3.0.0
  */
 public float getMaxHeight() {
   boolean pivoted = getRotation() == 90 || getRotation() == 270;
   Image img = getImage();
   if (img != null) {
     img.scalePercent(100);
     float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth();
     float scale =
         (getRight() - getEffectivePaddingRight() - getEffectivePaddingLeft() - getLeft())
             / refWidth;
     img.scalePercent(scale * 100);
     float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight();
     setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight);
   } else {
     if ((pivoted && hasFixedHeight()) || getColumn() == null)
       setBottom(getTop() - getFixedHeight());
     else {
       ColumnText ct = ColumnText.duplicate(getColumn());
       float right, top, left, bottom;
       if (pivoted) {
         right = PdfPRow.RIGHT_LIMIT;
         top = getRight() - getEffectivePaddingRight();
         left = 0;
         bottom = getLeft() + getEffectivePaddingLeft();
       } else {
         right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight();
         top = getTop() - getEffectivePaddingTop();
         left = getLeft() + getEffectivePaddingLeft();
         bottom =
             hasFixedHeight()
                 ? getTop() + getEffectivePaddingBottom() - getFixedHeight()
                 : PdfPRow.BOTTOM_LIMIT;
       }
       PdfPRow.setColumn(ct, left, bottom, right, top);
       try {
         ct.go(true);
       } catch (DocumentException e) {
         throw new ExceptionConverter(e);
       }
       if (pivoted)
         setBottom(
             getTop()
                 - getEffectivePaddingTop()
                 - getEffectivePaddingBottom()
                 - ct.getFilledWidth());
       else {
         float yLine = ct.getYLine();
         if (isUseDescender()) yLine += ct.getDescender();
         setBottom(yLine - getEffectivePaddingBottom());
       }
     }
   }
   float height = getHeight();
   if (height == getEffectivePaddingTop() + getEffectivePaddingBottom()) height = 0;
   if (hasFixedHeight()) height = getFixedHeight();
   else if (hasMinimumHeight() && height < getMinimumHeight()) height = getMinimumHeight();
   return height;
 }