com.itextpdf.text.Paragraph.setAlignment()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(309)

本文整理了Java中com.itextpdf.text.Paragraph.setAlignment()方法的一些代码示例,展示了Paragraph.setAlignment()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Paragraph.setAlignment()方法的具体详情如下:
包路径:com.itextpdf.text.Paragraph
类名称:Paragraph
方法名:setAlignment

Paragraph.setAlignment介绍

[英]Sets the alignment of this paragraph.
[中]设置此段落的对齐方式。

代码示例

代码示例来源:origin: org.technbolts/gutenberg

public static void applyAlign(Paragraph p, Align align) {
  if (align == null) {
    return;
  }
  switch (align) {
    case Center:
      p.setAlignment(Element.ALIGN_CENTER);
      break;
    case Right:
      p.setAlignment(Element.ALIGN_RIGHT);
      break;
    case Left:
    default:
      p.setAlignment(Element.ALIGN_LEFT);
      break;
  }
}

代码示例来源:origin: org.technbolts/gutenberg

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);
    }
  }
}

代码示例来源:origin: Swati4star/Images-to-PDF

/**
 * Read the Text File and put it in document
 *
 * @param uri      URL to create PDF
 * @param document PDF Document
 * @param myfont   Font style in PDF
 */
private void readTextFile(Uri uri, Document document, Font myfont) {
  InputStream inputStream;
  try {
    inputStream = mContext.getContentResolver().openInputStream(uri);
    if (inputStream == null)
      return;
    BufferedReader reader = new BufferedReader(new InputStreamReader(
        inputStream));
    String line;
    while ((line = reader.readLine()) != null) {
      System.out.println("line = " + line);
      Paragraph para = new Paragraph(line + "\n", myfont);
      para.setAlignment(Element.ALIGN_JUSTIFIED);
      document.add(para);
    }
    reader.close();
    inputStream.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.arrahtec/osdq-core

private void addTitlePage(Document document) throws DocumentException {
      addEmptyLine(document, 5);
   
   Paragraph title = new Paragraph("Data Dictionary by Arrah technology");
   title.setAlignment(Element.ALIGN_CENTER);
   document.add(title);
   addEmptyLine(document, 1);
   
   Paragraph url = new Paragraph("http://sourceforge.net/projects/dataquality/");
   url.setAlignment(Element.ALIGN_CENTER);
   document.add(url);
   addEmptyLine(document, 3);
   
   Paragraph rtime = new Paragraph("Report generated on: " +  new Date());
   rtime.setAlignment(Element.ALIGN_CENTER);
   document.add(rtime);
   document.newPage();
  }

代码示例来源:origin: org.technbolts/gutenberg

private void appendSubject(ITextContext context, Paragraph preface) {
  if (StringUtils.isEmpty(subject)) {
    return;
  }
  Styles styles = context.styles();
  Font font = styles.getFont(FIRST_PAGE_SUBJECT_FONT).or(subjectFont(styles));
  for (String titlePart : subject.split("[\n\r]+")) {
    Paragraph paragraph = new Paragraph(titlePart, font);
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    paragraph.setSpacingAfter(15.0f);
    preface.add(paragraph);
  }
}

代码示例来源:origin: timurstrekalov/saga

private Element createFooter() {
  final Paragraph footer = new Paragraph();
  footer.add(new Phrase("Generated using ", FONT_FOOTER));
  final Anchor a = new Anchor(config.getProperty("app.name"), FONT_FOOTER);
  a.setReference("http://timurstrekalov.github.com/saga/");
  footer.add(a);
  footer.add(new Phrase(" version " + config.getProperty("app.version"), FONT_FOOTER));
  footer.setAlignment(Element.ALIGN_RIGHT);
  return footer;
}

代码示例来源:origin: org.technbolts/gutenberg

private void appendTitle(ITextContext context, Paragraph preface) {
  if (StringUtils.isEmpty(title)) {
    return;
  }
  Styles styles = context.styles();
  Font font = styles.getFont(FIRST_PAGE_TITLE_FONT).or(titleFont(styles));
  Paragraph paragraph = null;
  for (String titlePart : title.split("[\n\r]+")) {
    paragraph = new Paragraph(titlePart, font);
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    paragraph.setSpacingAfter(15.0f);
    preface.add(paragraph);
  }
  if (paragraph != null) {
    paragraph.setSpacingAfter(30.0f);
  }
}

代码示例来源:origin: Swati4star/Images-to-PDF

/**
 * Read the .docx file and put it in document
 *
 * @param uri      URL to create PDF
 * @param document PDF Document
 * @param myfont   Font style in PDF
 */
private void readDocxFile(Uri uri, Document document, Font myfont) {
  InputStream inputStream;
  try {
    inputStream = mContext.getContentResolver().openInputStream(uri);
    if (inputStream == null)
      return;
    XWPFDocument doc = new XWPFDocument(inputStream);
    XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
    String fileData = extractor.getText();
    Paragraph documentParagraph = new Paragraph(fileData + "\n", myfont);
    documentParagraph.setAlignment(Element.ALIGN_JUSTIFIED);
    document.add(documentParagraph);
    inputStream.close();
  } catch (IOException | DocumentException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: Swati4star/Images-to-PDF

/**
 * Read the .doc file and put it in document
 *
 * @param uri      URL to create PDF
 * @param document PDF Document
 * @param myfont   Font style in PDF
 */
private void readDocFile(Uri uri, Document document, Font myfont) {
  InputStream inputStream;
  try {
    inputStream = mContext.getContentResolver().openInputStream(uri);
    if (inputStream == null)
      return;
    HWPFDocument doc = new HWPFDocument(inputStream);
    WordExtractor extractor = new WordExtractor(doc);
    String fileData = extractor.getText();
    Paragraph documentParagraph = new Paragraph(fileData + "\n", myfont);
    documentParagraph.setAlignment(Element.ALIGN_JUSTIFIED);
    document.add(documentParagraph);
    inputStream.close();
  } catch (IOException | DocumentException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: com.github.dandelion/datatables-export-itext

private void addTitle(Document document) throws DocumentException {
 Paragraph title = new Paragraph(exportConf.getFileName());
 title.add(new Paragraph(" ")); // empty line
 title.setAlignment(Element.ALIGN_CENTER);
 document.add(title);
}

代码示例来源:origin: dandelion/dandelion-datatables

private void addTitle(Document document) throws DocumentException {
 Paragraph title = new Paragraph(exportConf.getFileName());
 title.add(new Paragraph(" ")); // empty line
 title.setAlignment(Element.ALIGN_CENTER);
 document.add(title);
}

代码示例来源:origin: com.itextpdf/itextg

/**
 * Processes an Image.
 * @param img
 * @param attrs
 * @throws DocumentException
 * @since    5.0.6
 */
public void processImage(final Image img, final Map<String, String> attrs) throws DocumentException {
  ImageProcessor processor = (ImageProcessor)providers.get(HTMLWorker.IMG_PROCESSOR);
  if (processor == null || !processor.process(img, attrs, chain, document)) {
    String align = attrs.get(HtmlTags.ALIGN);
    if (align != null) {
      carriageReturn();
    }
    if (currentParagraph == null) {
      currentParagraph = createParagraph();
    }
    currentParagraph.add(new Chunk(img, 0, 0, true));
    currentParagraph.setAlignment(HtmlUtilities.alignmentValue(align));
    if (align != null) {
      carriageReturn();
    }
  }
}

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * Processes an Image.
 * @param img
 * @param attrs
 * @throws DocumentException
 * @since    5.0.6
 */
public void processImage(final Image img, final Map<String, String> attrs) throws DocumentException {
  ImageProcessor processor = (ImageProcessor)providers.get(HTMLWorker.IMG_PROCESSOR);
  if (processor == null || !processor.process(img, attrs, chain, document)) {
    String align = attrs.get(HtmlTags.ALIGN);
    if (align != null) {
      carriageReturn();
    }
    if (currentParagraph == null) {
      currentParagraph = createParagraph();
    }
    currentParagraph.add(new Chunk(img, 0, 0, true));
    currentParagraph.setAlignment(HtmlUtilities.alignmentValue(align));
    if (align != null) {
      carriageReturn();
    }
  }
}

代码示例来源:origin: com.github.hazendaz/displaytag

/**
 * Writes the table caption according to a set style.
 * @param model The table model containing the caption.
 * @throws DocumentException If an error occurrs while decorating the caption.
 */
private void decorateCaption(TableModel model) throws DocumentException
{
  Paragraph caption = new Paragraph(new Chunk(model.getCaption(), this.getCaptionFont()));
  caption.setAlignment(this.getCaptionHorizontalAlignment());
  this.document.add(caption);
}

代码示例来源:origin: com.itextpdf/itextg

/**
 * Constructs a <CODE>Paragraph</CODE> with a certain <CODE>Phrase</CODE>.
 *
 * @param    phrase        a <CODE>Phrase</CODE>
 */
public Paragraph(Phrase phrase) {
  super(phrase);
  if (phrase instanceof Paragraph) {
    Paragraph p = (Paragraph)phrase;
    setAlignment(p.alignment);
    setIndentationLeft(p.getIndentationLeft());
    setIndentationRight(p.getIndentationRight());
    setFirstLineIndent(p.getFirstLineIndent());
    setSpacingAfter(p.getSpacingAfter());
    setSpacingBefore(p.getSpacingBefore());
    setExtraParagraphSpace(p.getExtraParagraphSpace());
    setRole(p.role);
    id = p.getId();
    if (p.accessibleAttributes != null)
      accessibleAttributes = new HashMap<PdfName, PdfObject>(p.accessibleAttributes);
  }
}

代码示例来源:origin: com.itextpdf/itextpdf

/**
 * Constructs a <CODE>Paragraph</CODE> with a certain <CODE>Phrase</CODE>.
 *
 * @param    phrase        a <CODE>Phrase</CODE>
 */
public Paragraph(Phrase phrase) {
  super(phrase);
  if (phrase instanceof Paragraph) {
    Paragraph p = (Paragraph)phrase;
    setAlignment(p.alignment);
    setIndentationLeft(p.getIndentationLeft());
    setIndentationRight(p.getIndentationRight());
    setFirstLineIndent(p.getFirstLineIndent());
    setSpacingAfter(p.getSpacingAfter());
    setSpacingBefore(p.getSpacingBefore());
    setExtraParagraphSpace(p.getExtraParagraphSpace());
    setRole(p.role);
    id = p.getId();
    if (p.accessibleAttributes != null)
      accessibleAttributes = new HashMap<PdfName, PdfObject>(p.accessibleAttributes);
  }
}

代码示例来源:origin: Texera/texera

private static void createPDF(String path) throws Exception {
  Document pdfDoc = new Document(PageSize.A4);
  PdfWriter.getInstance(pdfDoc, new FileOutputStream(path)).setPdfVersion(PdfWriter.VERSION_1_7);
  pdfDoc.open();
  Font myfont = new Font();
  myfont.setStyle(Font.NORMAL);
  myfont.setSize(11);
  Paragraph para = new Paragraph("test", myfont);
  para.setAlignment(Element.ALIGN_JUSTIFIED);
  pdfDoc.add(para);
  pdfDoc.close();
}

代码示例来源:origin: cn-cerc/summer-mis

@Override
public void output(Document document, PdfWriter writer) throws DocumentException, IOException {
  PdfContentByte cb = writer.getDirectContent();
  BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
  // 设置中文字体和字体样式
  Font f8 = new Font(bfChinese, fontSize, Font.NORMAL);
  DataSet dataSet = this.getDataSet();
  dataSet.first();
  while (dataSet.fetch()) {
    // 条码信息
    Barcode128 code128 = new Barcode128();
    code128.setBarHeight(barHeight);
    String code = dataSet.getString("Code_");
    code128.setCode(code);
    // 反算条码宽度
    int length = code.length();
    float x = 125 / ((length + 2) * 11 + 2f);
    code128.setX(x);
    document.add(code128.createImageWithBarcode(cb, null, null));
    // 描述信息
    Paragraph paragraph = new Paragraph(dataSet.getString("Name_"), f8);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);
  }
}

代码示例来源:origin: com.itextpdf/itextpdf

protected void populateProperties(Paragraph copy, boolean spacingBefore) {
  copy.setFont(getFont());
  copy.setAlignment(getAlignment());
  copy.setLeading(getLeading(), multipliedLeading);
  copy.setIndentationLeft(getIndentationLeft());
  copy.setIndentationRight(getIndentationRight());
  copy.setFirstLineIndent(getFirstLineIndent());
  copy.setSpacingAfter(getSpacingAfter());
  if (spacingBefore)
    copy.setSpacingBefore(getSpacingBefore());
  copy.setExtraParagraphSpace(getExtraParagraphSpace());
  copy.setRole(role);
  copy.id = getId();
  if (accessibleAttributes != null)
    copy.accessibleAttributes = new HashMap<PdfName, PdfObject>(accessibleAttributes);
  copy.setTabSettings(getTabSettings());
  copy.setKeepTogether(getKeepTogether());
}

代码示例来源:origin: com.itextpdf/itextg

protected void populateProperties(Paragraph copy, boolean spacingBefore) {
  copy.setFont(getFont());
  copy.setAlignment(getAlignment());
  copy.setLeading(getLeading(), multipliedLeading);
  copy.setIndentationLeft(getIndentationLeft());
  copy.setIndentationRight(getIndentationRight());
  copy.setFirstLineIndent(getFirstLineIndent());
  copy.setSpacingAfter(getSpacingAfter());
  if (spacingBefore)
    copy.setSpacingBefore(getSpacingBefore());
  copy.setExtraParagraphSpace(getExtraParagraphSpace());
  copy.setRole(role);
  copy.id = getId();
  if (accessibleAttributes != null)
    copy.accessibleAttributes = new HashMap<PdfName, PdfObject>(accessibleAttributes);
  copy.setTabSettings(getTabSettings());
  copy.setKeepTogether(getKeepTogether());
}

相关文章