Tabnine Logo
com.itextpdf.text
Code IndexAdd Tabnine to your IDE (free)

How to use com.itextpdf.text

Best Java code snippets using com.itextpdf.text (Showing top 20 results out of 450)

origin: stackoverflow.com

 Font font = FontFactory.getFont("/fonts/Sansation_Regular.ttf",
  BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.NORMAL, BaseColor.BLACK);
BaseFont baseFont = font.getBaseFont();
origin: youseries/ureport

Font font=null;
if(baseFont!=null){
  font=new Font(baseFont);
}else{
  font=FontFactory.getFont(fontName);
font.setSize(fontSize);
int fontStyle=Font.NORMAL;
if(fontBold && fontItalic && underLine){
  fontStyle=Font.UNDERLINE;
font.setStyle(fontStyle);
return font;
origin: stackoverflow.com

 Phrase content = new Phrase("Blah blah blah", Font);

Float fontSize = content.getFont().getSize();
Float capHeight = content.getFont().getBaseFont().getFontDescriptor(BaseFont.CAPHEIGHT, fontSize);

Float padding = 5f;    

PdfPCell cell = new PdfPCell(content);
cell.setPadding(padding);
cell.setPaddingTop(capHeight - fontSize + padding);
origin: youseries/ureport

int width=paper.getWidth();
int height=paper.getHeight();
Rectangle pageSize=new RectangleReadOnly(width,height);
if(paper.getOrientation().equals(Orientation.landscape)){
  pageSize=pageSize.rotate();			
int topMargin=paper.getTopMargin();
int bottomMargin=paper.getBottomMargin();
Document document=new Document(pageSize,leftMargin,rightMargin,topMargin,bottomMargin);
try{
  PdfWriter writer=PdfWriter.getInstance(document,outputStream);
  PageHeaderFooterEvent headerFooterEvent=new PageHeaderFooterEvent(report);
  writer.setPageEvent(headerFooterEvent);
  document.open();
  List<Column> columns=report.getColumns();
  List<Integer> columnsWidthList=new ArrayList<Integer>();
    float tableHeight=pageSize.getHeight()-paper.getTopMargin()-paper.getBottomMargin();
    Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
    for(List<Page> pages:list){
      PdfPTable table=new PdfPTable(size);
      table.setLockedWidth(true);
      table.setTotalWidth(w);
      table.setWidths(widths);
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
      int ps=pages.size();
      for(int i=0;i<ps;i++){
        if(i>0){
          PdfPCell pdfMarginCell=new PdfPCell();
origin: shopizer-ecommerce/shopizer

Document document = new Document(PageSize.A4);
PdfDocument pdf = new PdfDocument();
document.addDocListener(pdf);
PdfWriter writer = PdfWriter.getInstance(pdf, outputStream);
pdf.addWriter(writer);
document.open();
Rectangle pageSize = document.getPageSize();
int w = (int) (pageSize.getWidth() * 0.9);
int h = (int) (pageSize.getHeight() * 0.95);
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(w, h);
Graphics2D g2 = tp.createPrinterGraphics(w, h, null);
tp.setWidth(w);
tp.setHeight(h);
float offsetX = (float) ((pageSize.getWidth() - w) / 2);
float offsetY = (float) ((pageSize.getHeight() - h) / 2);
cb.addTemplate(tp, offsetX, offsetY);
document.close();
origin: nodebox/nodebox

public static void render(Drawable drawable, Rectangle2D bounds, File file) {
  initialize();
  Rectangle size = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight());
  Document document = new Document(size);
  FileOutputStream fos;
  try {
    fos = new FileOutputStream(file);
  } catch (FileNotFoundException e) {
    throw new RuntimeException("The file " + file + "could not be created", e);
  }
  PdfWriter writer;
  try {
    writer = PdfWriter.getInstance(document, fos);
  } catch (DocumentException e) {
    throw new RuntimeException("An error occurred while creating a PdfWriter object.", e);
  }
  document.open();
  PdfContentByte contentByte = writer.getDirectContent();
  Graphics2D g = new PdfGraphics2D(contentByte, (float) bounds.getWidth(), (float) bounds.getHeight(), fontMapper);
  g.translate(-bounds.getX(), -bounds.getY());
  drawable.draw(g);
  g.dispose();
  document.close();
}
origin: youseries/ureport

  private PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){
    PdfPCell cell=new PdfPCell();
    cell.setPadding(0);
    cell.setBorder(Rectangle.NO_BORDER);
    Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline());
    String fontColor=phf.getForecolor();
    if(StringUtils.isNotEmpty(fontColor)){
      String[] color=fontColor.split(",");
      font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2]));			
    }
    Paragraph graph=new Paragraph(text,font);
    cell.setPhrase(graph);
    switch(type){
    case 1:
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
      break;
    case 2:
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
      break;
    case 3:
      cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
      break;
    }
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    return cell;
  }
}
origin: youseries/ureport

CellStyle colStyle=cellInfo.getColumn().getCustomCellStyle();
PdfPCell cell=newPdfCell(cellInfo,cellHeight);
cell.setPadding(0);
cell.setBorder(PdfPCell.NO_BORDER);
cell.setCellEvent(new CellBorderEvent(style,customStyle));
int rowSpan=cellInfo.getPageRowSpan();
if(rowSpan>0){
  cell.setRowspan(rowSpan);
  cell.setColspan(colSpan);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
  }else if(align.equals(Alignment.center)){
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
  }else if(align.equals(Alignment.right)){
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
  }else if(valign.equals(Alignment.middle)){
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
  }else if(valign.equals(Alignment.bottom)){
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
  cell.setBackgroundColor(new BaseColor(Integer.valueOf(colors[0]),Integer.valueOf(colors[1]),Integer.valueOf(colors[2])));
origin: youseries/ureport

cb.moveTo(position.getLeft(), position.getTop());
cb.lineTo(position.getLeft(), position.getBottom());
cb.stroke();
if(leftBorder.getStyle().equals(BorderStyle.doublesolid)){
  cb.moveTo(position.getLeft()+2, position.getTop()-2);
  cb.lineTo(position.getLeft()+2, position.getBottom()+2);
  cb.stroke();
cb.restoreState();
cb.moveTo(position.getLeft(), position.getTop());
cb.lineTo(position.getRight(), position.getTop());
cb.stroke();
if(topBorder.getStyle().equals(BorderStyle.doublesolid)){
  cb.moveTo(position.getLeft()+2, position.getTop()-2);
  cb.lineTo(position.getRight()-2, position.getTop()-2);
  cb.stroke();
cb.restoreState();
cb.moveTo(position.getRight(), position.getTop());
cb.lineTo(position.getRight(), position.getBottom());
cb.stroke();
if(rightBorder.getStyle().equals(BorderStyle.doublesolid)){
  cb.moveTo(position.getRight()-2, position.getTop()-2);
  cb.lineTo(position.getRight()-2, position.getBottom()+2);
  cb.stroke();
cb.restoreState();
origin: com.itextpdf/itextpdf

/**
 * Sets the dingbat's color.
 *
 * @param zapfDingbatColor color for the ZapfDingbat
 */
public void setDingbatColor(BaseColor zapfDingbatColor) {
  float fontsize = symbol.getFont().getSize();
  symbol.setFont(FontFactory.getFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL, zapfDingbatColor));
}
origin: com.itextpdf/itextpdf

 /**
* Adds the producer to a Document.
*
* @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
*/
 public boolean addProducer() {
   try {
     return add(new Meta(Element.PRODUCER, Version.getInstance().getVersion()));
   } catch (DocumentException de) {
     throw new ExceptionConverter(de);
   }
 }
origin: youseries/ureport

  private PdfContentByte bulidCellBorder(PdfContentByte[] canvases,Border border){
    PdfContentByte cb=canvases[PdfPTable.LINECANVAS];
    cb.saveState();
    BigDecimal w=new BigDecimal(border.getWidth());
    cb.setLineWidth(w.divide(new BigDecimal(2),10,RoundingMode.HALF_UP).floatValue());
    if(border.getStyle().equals(BorderStyle.dashed)){
      cb.setLineDash(new float[]{2f,3f,1f},2);
    }
    String borderColor[]=border.getColor().split(",");
    cb.setColorStroke(new BaseColor(Integer.valueOf(borderColor[0]),Integer.valueOf(borderColor[1]),Integer.valueOf(borderColor[2])));
    return cb;
  }
}
origin: youseries/ureport

  private com.itextpdf.text.Image buildPdfImage(String base64Data, int width,int height) throws Exception{
    com.itextpdf.text.Image pdfImg=null;
    InputStream input=ImageUtils.base64DataToInputStream(base64Data);
    try{
      byte[] bytes=IOUtils.toByteArray(input);
      pdfImg=com.itextpdf.text.Image.getInstance(bytes);
      float imgWidth=pdfImg.getWidth();
      float imgHeight=pdfImg.getHeight();
      if(width==0){
        width=Float.valueOf(imgWidth).intValue();
      }
      if(height==0){
        height=Float.valueOf(imgHeight).intValue();
      }
      width=UnitUtils.pixelToPoint(width-2);
      height=UnitUtils.pixelToPoint(height-2);
      pdfImg.scaleToFit(width,height);
    }finally{
      IOUtils.closeQuietly(input);
    }
    return pdfImg;
  }
}
origin: youseries/ureport

font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2]));			
origin: com.itextpdf/itextpdf

/**
 * change the font to SYMBOL
 */
protected void setGreekFont() {
  float fontsize = symbol.getFont().getSize();
  symbol.setFont(FontFactory.getFont(FontFactory.SYMBOL, fontsize, Font.NORMAL));
}
origin: com.itextpdf/itextg

 /**
* Adds the producer to a Document.
*
* @return    <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise
*/
 public boolean addProducer() {
   try {
     return add(new Meta(Element.PRODUCER, Version.getInstance().getVersion()));
   } catch (DocumentException de) {
     throw new ExceptionConverter(de);
   }
 }
origin: com.itextpdf/itextpdf

/**
 * Creates a ZapfDingbatsList
 *
 * @param zn a char-number
 */
public ZapfDingbatsList(int zn) {
  super(true);
  this.zn = zn;
  float fontsize = symbol.getFont().getSize();
  symbol.setFont(FontFactory.getFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL));
  postSymbol = " ";
}
origin: com.itextpdf/itextg

/**
 * Creates a ZapfDingbatsList
 *
 * @param zn a char-number
 */
public ZapfDingbatsList(int zn) {
  super(true);
  this.zn = zn;
  float fontsize = symbol.getFont().getSize();
  symbol.setFont(FontFactory.getFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL));
  postSymbol = " ";
}
origin: com.github.hazendaz/displaytag

/**
 * Makes chunk content bold.
 * @param chunk The chunk whose content is to be rendered bold.
 * @param color The font color desired.
 */
private void setBoldStyle(Chunk chunk, BaseColor color)
{
  Font font = chunk.getFont();
  chunk.setFont(FontFactory.getFont(font.getFamilyname(), font.getSize(), Font.BOLD, color));
}
origin: com.itextpdf/itextg

/**
 * Sets the dingbat's color.
 *
 * @param zapfDingbatColor color for the ZapfDingbat
 */
public void setDingbatColor(BaseColor zapfDingbatColor) {
  float fontsize = symbol.getFont().getSize();
  symbol.setFont(FontFactory.getFont(FontFactory.ZAPFDINGBATS, fontsize, Font.NORMAL, zapfDingbatColor));
}
com.itextpdf.text

Most used classes

  • Document
    A generic Document class. All kinds of Text-elements can be added to a HTMLDocument. The Document si
  • PdfWriter
    A DocWriter class for PDF. When this PdfWriter is added to a certain PdfDocument, the PDF representa
  • Rectangle
    A Rectangle is the representation of a geometric figure. Rectangles support constant width borders u
  • PdfContentByte
    PdfContentByte is an object containing the user positioned text and graphic contents of a page. It k
  • Image
    An Image is the representation of a graphic element (JPEG, PNG or GIF) that has to be inserted into
  • Font,
  • Phrase,
  • BaseFont,
  • PdfPCell,
  • PdfPTable,
  • BaseColor,
  • PdfReader,
  • DocumentException,
  • PdfTemplate,
  • FontFactory,
  • Chunk,
  • PdfDictionary,
  • PdfStamper,
  • ColumnText
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now