List of usage examples for com.lowagie.text.pdf PdfPCell setRotation
public void setRotation(int rotation)
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf headers./*w ww . j a v a 2 s . c om*/ * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfHeaders(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { font = getFont(); final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; final PdfPCell headersCells = new PdfPCell(new Phrase(getHeader(), font)); headersCells.setHorizontalAlignment(Element.ALIGN_CENTER); headersCells.setColspan(headerWidth); headersCells.setUseDescender(true); headersCells.setBorder(0); pdfPTable.addCell(headersCells); for (int i = 0; i < this.model.getColumnCount(); i++) { if (this.model.isVisible(i)) { final PdfPCell cell = new PdfPCell(new Phrase(Lables.get(this.model.getActualColumnName(i)), font)); cell.setRotation(getRotationDegree()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cell); } } // Please explain pdfPTable.setHeaderRows(3); createPdfFooter(pdfPTable, font); }
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPCell buildHeaderCell(String text, int rotation, boolean first, boolean last) { PdfPCell cell = new PdfPCell(new Phrase(text)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); setBorder(cell, first, last);/* w w w . j a va 2 s .c o m*/ cell.setRotation(rotation); return cell; }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = Math.round((float) Units.PT.setYPixels((int) rect.getHeight())); float w = Math.round((float) Units.PT.setXPixels((int) rect.getWidth())); PdfPCell pdfCell = null; if (srcCell.getPicture() != null) { java.awt.Image awtImage = srcCell.getPicture().getImage(); com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else {/*w w w. j a v a 2 s . c om*/ String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { pdfCell = new PdfPCell(); writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (pdfCell == null) { pdfCell = new PdfPCell(); } if (text != null && text.length() > 0) { com.lowagie.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); pdfCell.setPadding(1); pdfCell.setLeading(0f, 1.1f); } else { pdfCell.setPadding(0); } } pdfCell.setFixedHeight(h); pdfCell.setBackgroundColor(style.getBackground()); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:net.bull.javamelody.internal.web.pdf.PdfRuntimeDependenciesReport.java
License:Apache License
private void writeHeader() throws DocumentException { final List<String> headers = new ArrayList<String>(); headers.add("Beans"); headers.addAll(calledBeans);/*ww w .jav a 2 s. c o m*/ final int[] relativeWidths = new int[headers.size()]; Arrays.fill(relativeWidths, 0, headers.size(), 1); relativeWidths[0] = 4; final PdfPTable table = new PdfPTable(headers.size()); table.setWidthPercentage(100); table.setWidths(relativeWidths); table.setHeaderRows(1); final PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setGrayFill(0.9f); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); defaultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); defaultCell.setPaddingLeft(0); defaultCell.setPaddingRight(0); for (final String header : headers) { table.addCell(new Phrase(header, boldCellFont)); // pas la premire entte de colonne defaultCell.setRotation(90); } defaultCell.setRotation(0); defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); currentTable = table; }
From source file:questions.tables.RotateCell.java
public static void main(String[] args) { Document document = new Document(PageSize.A4); try {//from w w w . j a v a 2 s . c om PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph paragraphA = new Paragraph(); paragraphA.add(new Phrase("TestA")); Paragraph paragraphB = new Paragraph(); paragraphB.add(new Phrase("\u00a0")); Paragraph paragraphC = new Paragraph(); paragraphC.add(new Phrase("TestB")); PdfPTable table = new PdfPTable(1); PdfPCell cell = new PdfPCell(); cell.addElement(paragraphA); cell.addElement(paragraphB); cell.addElement(paragraphC); cell.setRotation(90); table.addCell(cell); document.add(table); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:questions.tables.RotatedCells.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww .j a va2s .c o m*/ PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); float[] widths = { 1, 4 }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(40); PdfPCell cell; cell = new PdfPCell(new Paragraph("test 1")); cell.setPadding(4); cell.setBackgroundColor(Color.YELLOW); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.addCell("Cell without any rotation."); cell = new PdfPCell(new Paragraph("test 2")); cell.setPadding(4); cell.setBackgroundColor(Color.YELLOW); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setRotation(90); table.addCell(cell); table.addCell("Cell rotated 90 degrees."); cell = new PdfPCell(new Paragraph("test 3")); cell.setPadding(4); cell.setBackgroundColor(Color.YELLOW); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setRotation(180); table.addCell(cell); table.addCell("Cell upside down."); cell = new PdfPCell(new Paragraph("test 4")); cell.setPadding(4); cell.setBackgroundColor(Color.YELLOW); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setRotation(270); table.addCell(cell); table.addCell("Cell rotated 270 degrees."); document.add(table); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
From source file:s2s.luna.reports.Stampa_documento.java
License:GNU General Public License
@SuppressWarnings("CallToThreadDumpStack") private boolean addPDF(String titolo, byte[] fileContent, Document document, PdfWriter writer) { try {/*from w ww . jav a2 s . c om*/ // Inizializzo il contenitore del pdf da importare. PdfContentByte cb = writer.getDirectContent(); // Inizializzo la variabile dove appogger (una alla volta) // le pagine del pdf da importare. PdfImportedPage page; // Apro in lettura il pdf da importare. PdfReader pdfReader = new PdfReader(fileContent); // Ne determino il numero di pagine totali. int pdfPageNumber = pdfReader.getNumberOfPages(); // Inzializzo il contatore delle pagine. int pageOfCurrentReaderPDF = 1; // Per ogni pagina... while (pageOfCurrentReaderPDF <= pdfPageNumber) { // Creo una nuova pagina vuota sul pdf di destinazione. document.newPage(); // Estraggo la pagina dal pdf da importare. page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF); // Coverto la pagina in un immagine. Image pageImg = Image.getInstance(page); // Aggiungo la pagina estratta al pdf di destinazione, ruotandola se necessario. PdfPTable table = new PdfPTable(1); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setRotation(-pdfReader.getPageRotation(pageOfCurrentReaderPDF)); defaultCell.setBorder(Rectangle.NO_BORDER); table.addCell(pageImg); document.add(table); // Incremento il contatore delle pagine pageOfCurrentReaderPDF++; } return true; } catch (Exception ex) { // Eccezione silenziosa. // Gestisce il caso in cui si verifica un errore non previsto ex.printStackTrace(); return false; } }