Java 类com.itextpdf.text.Paragraph 实例源码

项目:ureport    文件:PageHeaderFooterEvent.java   
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;
}
项目:testarea-itext5    文件:SimpleRedactionTest.java   
static byte[] createSimpleTextPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 1; i < 20; i++)
    {
        Paragraph paragraph = new Paragraph();
        for (int j = 0; j < i; j++)
            paragraph.add("Hello World! ");
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
项目:iTextTutorial    文件:T05_Image.java   
public void createPdf(String filename) throws DocumentException, IOException {

        Document document = new Document(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

        // TODO: force iText to respect the order in which content is added
        writer.setStrictImageSequence(true);

        document.open();

        // step 4 - add content into document
        String[] imageNames = { "35_Cal_Crutchlow.jpg", "38_Bradley_Smith.jpg", "46_Valentino_Rossi.jpg",
                "99_Jorge_Lorenzo.jpg" };
        for (int i = 0; i < 4; i++) {

            Image image = Image.getInstance("resources/img/" + imageNames[i]);

            // TODO: scale image
            image.scaleToFit(500, 500); // scale size

            document.add(image);
            document.add(new Paragraph(imageNames[i]));
        }

        document.close();
    }
项目:CPI    文件:generarPDF.java   
private static void addTitlePage(Document document,Resolucion res)
    throws DocumentException {
  Paragraph preface = new Paragraph();
  // We add one empty line
  addEmptyLine(preface, 1);
  // Lets write a big header
  preface.add(new Paragraph("Consejo Profesional de Informatica de Santiago del Estero", catFont));

  addEmptyLine(preface, 1);
  // Will create: Report generated by: _name, _date
  preface.add(new Paragraph( "Comision Directiva del Consejo, " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      smallBold));
  addEmptyLine(preface, 2);
  preface.add(new Paragraph("Resolucion N°"+res.getNumero_resolucion()+"",
      smallBold));

  addEmptyLine(preface, 3);

  preface.add(new Paragraph("Esta Resolucion de tipo "+res.getTipo()+" formulada para notificar al socio con legajo: "+res.getLegajo_socio()+" de su actual estado como socio del Consejo.\n"
          + res.getDescripcion_solicitud()+" "+res.getDescripcion_resolucion()+" en la fecha "+res.getFecha(),
      cuerpo));

  document.add(preface);
  // Start a new page
  document.newPage();
}
项目:hotel    文件:ResidenceService.java   
private void createAccomodationTableHeaders(PdfPTable accomodationsTable) {
    PdfPCell numberHeader = new PdfPCell(new Paragraph("Lp."));
    PdfPCell roomNumberHeader = new PdfPCell(new Paragraph("Nr pokoju"));
    PdfPCell dateFromHeader = new PdfPCell(new Paragraph("Od"));
    PdfPCell dateToHeader = new PdfPCell(new Paragraph("Do"));
    PdfPCell placesHeader = new PdfPCell(new Paragraph("Miejsca"));
    PdfPCell roomTypeHeader = new PdfPCell(new Paragraph("Typ"));
    PdfPCell roomPriceHeader = new PdfPCell(new Paragraph("Cena"));
    accomodationsTable.addCell(numberHeader);
    accomodationsTable.addCell(roomNumberHeader);
    accomodationsTable.addCell(dateFromHeader);
    accomodationsTable.addCell(dateToHeader);
    accomodationsTable.addCell(placesHeader);
    accomodationsTable.addCell(roomTypeHeader);
    accomodationsTable.addCell(roomPriceHeader);
}
项目:hotel    文件:ResidenceService.java   
private void addOfferInstances(List<OfferInstance> offerInstances, Document document, BaseFont bf)
        throws DocumentException {

    if(offerInstances.isEmpty()) {
        return;
    }

    document.add(new Paragraph("Wybrane oferty: ", new Font(bf, 12)));

    PdfPTable offerInstancesTable = new PdfPTable(3);
    offerInstancesTable.setWidthPercentage(100);
    offerInstancesTable.setSpacingBefore(18f);
    offerInstancesTable.setSpacingAfter(18f);
    createofferInstancesTableHeaders(offerInstancesTable);
    createofferInstancesTableContent(offerInstances, offerInstancesTable);
    document.add(offerInstancesTable);
}
项目:hotel    文件:ResidenceService.java   
private void createofferInstancesTableContent(List<OfferInstance> offerInstances, PdfPTable offerInstancesTable) {
    DecimalFormat decimalFormat = new DecimalFormat(PRICE_DECIMAL_FORMAT);

    int i = 1;
    for (OfferInstance offerInstance : offerInstances) {
        Offer offer = offerInstance.getOffer();

        PdfPCell numberCell = new PdfPCell(new Paragraph(String.valueOf(i++)));

        String offerName = offer.getName();
        PdfPCell roomNumberCell = new PdfPCell(new Paragraph(offerName));

        String offerPrice = decimalFormat.format(offer.getBaseValue()) + " PLN";
        PdfPCell roomPriceCell = new PdfPCell(new Paragraph(offerPrice));

        offerInstancesTable.addCell(numberCell);
        offerInstancesTable.addCell(roomNumberCell);
        offerInstancesTable.addCell(roomPriceCell);
    }

}
项目:hotel    文件:EmployeeService.java   
private void createTableContent(List<CleaningSchedule> cleaningSchedules, PdfPTable cleaningScheduleTable) {
    int i = 1;
    for (CleaningSchedule cleaningSchedule : cleaningSchedules) {
        PdfPCell numberCell = new PdfPCell(new Paragraph(String.valueOf(i++)));
        String roomNumber = cleaningSchedule.getAccomodation().getAllocationEntity().getNumber();
        PdfPCell roomNumberCell = new PdfPCell(new Paragraph(roomNumber));
        String preferredTime = cleaningSchedule.getDesiredTime() == null ? "-" : cleaningSchedule.getDesiredTime().toString("HH:mm");
        PdfPCell preferredTimeCell = new PdfPCell(new Paragraph(preferredTime));
        String note = cleaningSchedule.getNote() == null ? "-" : cleaningSchedule.getNote();
        PdfPCell noteCell = new PdfPCell(new Paragraph(note));
        cleaningScheduleTable.addCell(numberCell);
        cleaningScheduleTable.addCell(roomNumberCell);
        cleaningScheduleTable.addCell(preferredTimeCell);
        cleaningScheduleTable.addCell(noteCell);
    }
}
项目:coj-web    文件:PDFExportProblem.java   
public Document getPDF() throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(FILE + problem.getPid() + ".pdf"));
    Image image = Image.getInstance(this.logo);
    document.open();
    document.add(image);
    document.addCreationDate();
    document.add(new Paragraph("Title: "+problem.getTitle()));
    document.add(new Paragraph("Code: "+problem.getPid()));
    document.add(new Paragraph(" "));
    document.add(addParagraph("Description",problem.getDescription(), true));
    document.add(addParagraph("Input",problem.getInput(), true));
    document.add(addParagraph("Output",problem.getOutput(), true));
    document.add(addParagraph("Input Example",problem.getInputex().replaceAll("<br/>", ""), true));
    document.add(addParagraph("Output Example",problem.getOutputex(), true));
    document.add(new Paragraph("Time(ms): "+problem.getTime()));
    document.add(new Paragraph("Memory(kb): "+problem.getMemory()));
    document.add(new Paragraph("Source(kb): "+problem.getFontsize()));
    document.addTitle("Challenger Online Judge");
    document.addAuthor("Chjudge");
    document.close();
    return document;
}
项目:ExcelToBarcode    文件:MainController.java   
/** Shows a blank document, in case of a problem in generating the PDF */
private byte[] showBlank() throws DocumentException {
    final Document document = new Document(PageSize.LETTER); // FIXME - get PageSize from label definition
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    final PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();
    document.add(new Paragraph("No data have been uploaded.  The time is: " + new Date()));

    final Barcode128 code128 = new Barcode128();
    code128.setGenerateChecksum(true);
    code128.setCode(new Date().toString());

    document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null));
    document.close();
    return baos.toByteArray();
}
项目:OpenSongTablet    文件:ExportPreparer.java   
private static void makePDF(Bitmap bmp, File file) {
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.addAuthor(FullscreenActivity.mAuthor.toString());
        document.addTitle(FullscreenActivity.mTitle.toString());
        document.addCreator("OpenSongApp");
        if (bmp!=null && bmp.getWidth()>bmp.getHeight()) {
            document.setPageSize(PageSize.A4.rotate());
        } else {
            document.setPageSize(PageSize.A4);
        }
        document.addTitle(FullscreenActivity.mTitle.toString());
        document.open();//document.add(new Header("Song title",FullscreenActivity.mTitle.toString()));
        BaseFont urName = BaseFont.createFont("assets/fonts/Lato-Reg.ttf", "UTF-8",BaseFont.EMBEDDED);
        Font TitleFontName  = new Font(urName, 14);
        Font AuthorFontName = new Font(urName, 10);
        document.add(new Paragraph(FullscreenActivity.mTitle.toString(),TitleFontName));
        document.add(new Paragraph(FullscreenActivity.mAuthor.toString(),AuthorFontName));
        addImage(document,bmp);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:FOXopen    文件:FormListWidgetBuilder.java   
/**
 * Serialises a form row
 * @param pSerialisationContext
 * @param pSerialiser
 * @param pRowNode The form node
 */
private void addFormRow(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedNodeInfo pRowNode) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, LIST_ROW_TAG, getRowClasses(pRowNode), getRowStyles(pRowNode));
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPCell lCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph));
  pSerialiser.getWidgetBuilder(pRowNode.getWidgetBuilderType()).buildWidget(pSerialisationContext, pSerialiser, pRowNode);
  pSerialiser.endContainer();
  pSerialiser.add(lCell);

  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:InputField.java   
/**
 * Serialise the input field div and content
 * @param pSerialisationContext
 * @param pSerialiser
 * @param pEvalNode
 */
public void serialise(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EN pEvalNode) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, INPUT_FIELD_TAG, getInputFieldClasses(), Collections.emptyList());
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPTable lTable = pSerialiser.getElementFactory().getTable(1);
  PdfPCell lCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph));
  mInputFieldContent.addContent(pSerialisationContext, pSerialiser, pEvalNode);
  if (lCellParagraph.isEmpty()) {
    // If there is no cell content in all cells in a table row, the row will be 0 height - add a zero width space to
    // ensure that the input field div isn't collapsed like this (the height will be determined from the cell
    // paragraph font)
    lCellParagraph.add(ZERO_WIDTH_SPACE_CHARACTER);
  }
  pSerialiser.endContainer();

  lTable.addCell(lCell);
  pSerialiser.add(lTable);

  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:ListWidgetBuilder.java   
/**
 * Serialises a column header
 * @param pSerialiser
 * @param pHeaderNode The column header node
 */
private void addColumnHeader(PDFSerialiser pSerialiser, EvaluatedNodeInfo pHeaderNode) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, LIST_CELL_TAG, getHeaderClasses(pHeaderNode), getHeaderStyles(pHeaderNode));
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPCell lHeaderCell = pSerialiser.getElementFactory().getCell();

  // Add the header prompt to the cell if one exists
  Optional.ofNullable(pHeaderNode.getSummaryPrompt()).ifPresent(pEvaluatedPrompt -> {
    Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();
    pSerialiser.startContainer(ElementContainerFactory.getContainer(lHeaderCell, lCellParagraph));
    pSerialiser.addParagraphText(pSerialiser.getSafeStringAttribute(pEvaluatedPrompt));
    pSerialiser.endContainer();
  });

  pSerialiser.add(lHeaderCell);
  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:ListWidgetBuilder.java   
/**
 * Serialises a list body cell
 * @param pSerialisationContext
 * @param pSerialiser
 * @param pItemNode The item node of the cell if the row and column of the cell has content
 * @param pIsNestedList Whether or not the list if nested, a different class is applied to nested list cells
 */
private void addBodyCell(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, Optional<EvaluatedNodeInfo> pItemNode, boolean pIsNestedList) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, LIST_CELL_TAG, getCellClasses(pItemNode, pIsNestedList), getCellStyles(pItemNode));
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPCell lCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();

  if (pItemNode.isPresent() && pItemNode.get().getVisibility() != NodeVisibility.DENIED) {
    // Column was found for this row and it isn't denied visibility, add content
    pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph));
    pSerialiser.getWidgetBuilder(pItemNode.get().getWidgetBuilderType()).buildWidget(pSerialisationContext, pSerialiser, pItemNode.get());
    pSerialiser.endContainer();
  }

  pSerialiser.add(lCell);
  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:MultiOptionSelectWidget.java   
private PdfPCell createColumnItem(PDFSerialiser pSerialiser, EvaluatedNodeInfo pEvalNode,
                                  LayoutFieldValueMappingItemColumn pColumnItem, int pItemsPerRow, boolean pHideField) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, MULTI_OPTION_CELL_TAG,
                                             getColumnItemClasses(pEvalNode), getColumnItemStyles(pEvalNode));
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPCell lFieldCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();
  lFieldCell.setColspan(FOXGridUtils.calculateAdjustedColumnSpan(pColumnItem.getColSpan(), pItemsPerRow));

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lFieldCell, lCellParagraph));
  addColumnItemContent(pSerialiser, pColumnItem, pHideField);
  pSerialiser.endContainer();

  pSerialiser.popElementAttributes();

  return lFieldCell;
}
项目:FOXopen    文件:FormWidget.java   
/**
 * Serialises a table cell of the column item content with cell styles applied
 * @param pSerialisationContext
 * @param pSerialiser
 * @param pColumnItem The column item to create a cell for
 * @param pFormColumns The number of columns in the form, used to determine field column spans
 */
private void addColumnItem(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, LayoutWidgetItemColumn pColumnItem, int pFormColumns) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, FORM_CELL_TAG, getColumnItemCellClasses(pColumnItem), getColumnItemCellStyles(pColumnItem));
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPCell lFormCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();
  lFormCell.setColspan(FOXGridUtils.calculateAdjustedColumnSpan(pColumnItem.getColSpan(), pFormColumns));

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lFormCell, lCellParagraph));
  addColumnItemContent(pSerialisationContext, pSerialiser, pColumnItem);
  pSerialiser.endContainer();

  pSerialiser.add(lFormCell);
  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:WidgetBuilderPDFSerialiser.java   
@Override
public void buildPrompt(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EN pEvalNode) {
  if (hasPrompt(pEvalNode)) {
    ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
    pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, PROMPT_TAG, getPromptClasses(pEvalNode), Collections.emptyList());
    pSerialiser.pushElementAttributes(lElementAttributes);

    Paragraph lParagraph = pSerialiser.getElementFactory().getParagraph();
    pSerialiser.startContainer(ElementContainerFactory.getContainer(lParagraph));
    renderXMLStringContent(pSerialisationContext, pSerialiser, pEvalNode.getPrompt().getString());
    pSerialiser.endContainer();
    pSerialiser.add(lParagraph);

    pSerialiser.popElementAttributes();
  }
}
项目:FOXopen    文件:HeaderFooterComponent.java   
@Override
public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EPN pEvalNode) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, mTag,
                                             Collections.singletonList(pEvalNode.getClasses()),
                                             Collections.singletonList(pEvalNode.getStyles()));
  pSerialiser.pushElementAttributes(lElementAttributes);

  // Add header/footer content to a table
  PdfPTable lTable = pSerialiser.getElementFactory().getTable(1);
  PdfPCell lCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph));
  processChildren(pSerialisationContext, pSerialiser, pEvalNode);
  pSerialiser.endContainer();

  lTable.addCell(lCell);

  // Consume the header/footer content (i.e. set the header or footer content via the serialiser)
  mHeaderFooterContentConsumer.accept(pSerialiser, new HeaderFooterContent(lTable));
  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:HeadingComponentBuilder.java   
@Override
public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedHeadingPresentationNode pEvalNode) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, HEADING_TAG_PREFIX + pEvalNode.getLevel(),
                                             Collections.singletonList(pEvalNode.getClasses()),
                                             Collections.singletonList(pEvalNode.getStyles()));
  pSerialiser.pushElementAttributes(lElementAttributes);

  // Heading text is contained within a table so that it may be styled as a block-level element (i.e. the same as a
  // div with borders, background colours etc.)
  PdfPTable lTable = pSerialiser.getElementFactory().getTable(1);
  PdfPCell lCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph));
  processChildren(pSerialisationContext, pSerialiser, pEvalNode);
  pSerialiser.endContainer();

  lTable.addCell(lCell);
  // A table spacer is required so any content before the heading is not overlapped
  pSerialiser.addTableSpacer();
  pSerialiser.add(lTable);

  pSerialiser.popElementAttributes();
}
项目:FOXopen    文件:GridCellComponentBuilder.java   
@Override
public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedGridCellPresentationNode pEvalNode) {
  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, GRID_CELL_TAG,
                                             Arrays.asList(GRID_CELL_CLASS, pEvalNode.getClasses()),
                                             Collections.singletonList(pEvalNode.getStyles()));
  pSerialiser.pushElementAttributes(lElementAttributes);

  PdfPCell lCell = pSerialiser.getElementFactory().getCell();
  Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph();
  lCell.setColspan(pEvalNode.getColumnSpan());

  pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph));
  processChildren(pSerialisationContext, pSerialiser, pEvalNode);
  pSerialiser.endContainer();
  pSerialiser.add(lCell);

  pSerialiser.popElementAttributes();
}
项目:osdq-core    文件:DataDictionaryPDF.java   
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();
 }
项目:testarea-itext5    文件:ColorParagraphBackground.java   
@Test
public void testParagraphBackgroundEventListener() throws DocumentException, FileNotFoundException
{
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "document-with-paragraph-backgrounds.pdf")));
    ParagraphBackground border = new ParagraphBackground();
    writer.setPageEvent(border);
    document.open();
    document.add(new Paragraph("Hello,"));
    document.add(new Paragraph("In this document, we'll add several paragraphs that will trigger page events. As long as the event isn't activated, nothing special happens, but let's make the event active and see what happens:"));
    border.setActive(true);
    document.add(new Paragraph("This paragraph now has a background. Isn't that fantastic? By changing the event, we can even draw a border, change the line width of the border and many other things. Now let's deactivate the event."));
    border.setActive(false);
    document.add(new Paragraph("This paragraph no longer has a background."));
    document.close();
}
项目:testarea-itext5    文件:ChangeMargins.java   
/**
 * <a href="http://stackoverflow.com/questions/38057241/itextpdf-different-margin-on-specific-page">
 * itextpdf different margin on specific page
 * </a>
 * <p>
 * This test shows how to set different margins to separate pages.
 * </p> 
 */
@Test
public void testChangingMargins() throws IOException, DocumentException
{
    StringBuilder builder = new StringBuilder("test");
    for (int i = 0; i < 100; i++)
        builder.append(" test");
    String test = builder.toString();

    try (   OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "ChangingMargins.pdf")))
    {
        Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter.getInstance(pdfDocument, pdfStream);
        pdfDocument.open();

        for (int m = 0; m < pdfDocument.getPageSize().getWidth() / 2 && m < pdfDocument.getPageSize().getHeight() / 2; m += 100)
        {
            // pdfDocument.setMargins(m, m, 100, 100);
            pdfDocument.setMargins(m, m, m, m);
            pdfDocument.newPage();
            pdfDocument.add(new Paragraph(test));
        }

        pdfDocument.close();
    }
}
项目:testarea-itext5    文件:CreateAndAppendDoc.java   
/**
 * <a href="http://stackoverflow.com/questions/29001852/how-to-create-a-pdf-and-you-then-merge-another-pdf-to-the-same-document-using-it">
 * how to create a PDF and you then merge another pdf to the same document using itext
 * </a>
 * <p>
 * Testing the OP's method with <code>paginate</code> set to <code>false</code>
 * </p>
 */
@Test
public void testAppendPDFs() throws IOException, DocumentException
{
    try (
            InputStream testA4Stream = getClass().getResourceAsStream("testA4.pdf");
            InputStream fromStream = getClass().getResourceAsStream("from.pdf");
            InputStream prefaceStream = getClass().getResourceAsStream("preface.pdf");
            InputStream type3Stream = getClass().getResourceAsStream("Test_Type3_Problem.pdf");
            FileOutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "appendPdfs.pdf"));
        )
    {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.open();
        document.add(new Paragraph("Some content to start with"));
        appendPDFs(Arrays.asList(testA4Stream, fromStream, prefaceStream, type3Stream), writer, document, null, false);
        document.close();
    }
}
项目:testarea-itext5    文件:CreateAndAppendDoc.java   
/**
 * <a href="http://stackoverflow.com/questions/29001852/how-to-create-a-pdf-and-you-then-merge-another-pdf-to-the-same-document-using-it">
 * how to create a PDF and you then merge another pdf to the same document using itext
 * </a>
 * <p>
 * Testing the OP's method with <code>paginate</code> set to <code>true</code>
 * </p>
 */
@Test
public void testAppendPDFsPaginate() throws IOException, DocumentException
{
    try (
            InputStream testA4Stream = getClass().getResourceAsStream("testA4.pdf");
            InputStream fromStream = getClass().getResourceAsStream("from.pdf");
            InputStream prefaceStream = getClass().getResourceAsStream("preface.pdf");
            InputStream type3Stream = getClass().getResourceAsStream("Test_Type3_Problem.pdf");
            FileOutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "appendPdfsPaginate.pdf"));
        )
    {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.open();
        document.add(new Paragraph("Some content to start with"));
        appendPDFs(Arrays.asList(testA4Stream, fromStream, prefaceStream, type3Stream), writer, document, null, true);
        document.close();
    }
}
项目:testarea-itext5    文件:DenseMerging.java   
static byte[] createSimpleTextPdf(String paragraphFormat, int paragraphCount) throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 0; i < paragraphCount; i++)
    {
        Paragraph paragraph = new Paragraph();
        paragraph.add(String.format(paragraphFormat, i));
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
项目:testarea-itext5    文件:VeryDenseMerging.java   
static byte[] createSimpleTextPdf(String paragraphFormat, int paragraphCount) throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 0; i < paragraphCount; i++)
    {
        Paragraph paragraph = new Paragraph();
        paragraph.add(String.format(paragraphFormat, i));
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
项目:testarea-itext5    文件:ImportPageWithoutFreeSpace.java   
/**
 * This method creates a PDF with a single styled paragraph.
 */
static byte[] createSimpleTextPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();

    Paragraph paragraph = new Paragraph();
    paragraph.add(new Phrase("Beware: ", new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC)));
    paragraph.add(new Phrase("The implementation of ", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    paragraph.add(new Phrase("MarginFinder", new Font(FontFamily.COURIER, 12, Font.ITALIC)));
    paragraph.add(new Phrase(" is far from optimal. It is not even correct as it includes all curve control points which is too much. Furthermore it ignores stuff like line width or wedge types. It actually merely is a proof-of-concept.", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    document.add(paragraph);

    document.close();

    return baos.toByteArray();
}
项目:testarea-itext5    文件:DynamicFooter.java   
public PdfPTable generateFooter() {
    try {
        BaseFont baseFont = BaseFont.createFont(/*"resources/ARIAL.TTF"*/ "c:/Windows/Fonts/arial.ttf", BaseFont.IDENTITY_H, true);
        footerTable = new PdfPTable(1);
        footerTable.setTotalWidth(440);
        footerTable.setLockedWidth(true);

        Font pageNumberFont = new Font(baseFont, 9, Font.BOLD);
        Paragraph pageNumberP = new Paragraph(titleIndex+"-"+ pageNumber, pageNumberFont);
        PdfPCell pageNumberCell = new PdfPCell(pageNumberP);
        pageNumberCell.setBorder(0);
        pageNumberCell.setPaddingTop(20);
        footerTable.addCell(pageNumberCell);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return footerTable;
}
项目:tellervo    文件:SeriesReport.java   
/**
 * Get an iText Paragraph for the Title 
 * 
 * @return Paragraph
 */
private Paragraph getTitlePDF()
{
    Paragraph p = new Paragraph();

    p.add(new Chunk(s.getDisplayTitle()+"\n", titleFont));

    // Add object name if this is a mSeries
    if(s.getSeries() instanceof TridasMeasurementSeries)
    {
        TridasObject tobj = s.getMeta(Metadata.OBJECT, TridasObject.class);

        p.add(new Chunk(tobj.getTitle(), subTitleFont));
    }       
    return p;       
}
项目:tellervo    文件:SeriesReport.java   
/**
 * iText paragraph containing created and lastmodified timestamps
 * 
 * @return Paragraph
 */
private Paragraph getTimestampPDF()
{
    // Set up calendar
    Date createdTimestamp = s.getSeries().getCreatedTimestamp().getValue()
            .toGregorianCalendar().getTime();
    Date lastModifiedTimestamp = s.getSeries().getLastModifiedTimestamp()
            .getValue().toGregorianCalendar().getTime();
    DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);

    Paragraph p = new Paragraph();


    p.add(new Chunk("Created: ", subSubSectionFont));
    p.add(new Chunk(df1.format(createdTimestamp), bodyFont));
    p.add(new Chunk("\nLast Modified: ", subSubSectionFont));
    p.add(new Chunk(df1.format(lastModifiedTimestamp), bodyFont));


    return p;

}
项目:tellervo    文件:SeriesReport.java   
private Paragraph getSeriesComments() 
{


    Paragraph p = new Paragraph();

    if(s.getSeries().getComments()!=null){

        p.setLeading(0, 1.2f);
        p.add(new Chunk("Comments: \n", subSubSectionFont));
        p.add(new Chunk(s.getSeries().getComments(), bodyFont));
        return p;
    }
    else
    {
        return p;
    }


}
项目:tellervo    文件:SeriesReport.java   
/**
 * iText paragraph of element and sample info
 * @return Paragraph
 */
private Paragraph getElementAndSampleInfo()
{
    Paragraph p = new Paragraph();

    TridasElement telem = s.getMeta(Metadata.ELEMENT, TridasElement.class);
    TridasSample tsamp = s.getMeta(Metadata.SAMPLE, TridasSample.class);

    p.add(new Chunk("Element and sample details:\n", subSubSectionFont));

    p.add(new Chunk("- Taxon:  ", bodyFont));
    p.add(new Chunk(telem.getTaxon().getNormal()+"\n", bodyFontItalic));
    p.add(new Chunk("- Element type: "+ telem.getType().getNormal()+"\n", bodyFont));
    p.add(new Chunk("- Sample type: "+ tsamp.getType().getNormal()+"\n", bodyFont));
    return p;

}
项目:tellervo    文件:ProSheet.java   
private Paragraph getObjectDescription() 
{

    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);
    p.setAlignment(Element.ALIGN_JUSTIFIED);
       p.setSpacingAfter(10);
       p.setSpacingBefore(50);

    if(o.getDescription()!=null){
        p.add(new Chunk(o.getDescription(), bodyFont));
    }
    else{
        p.add(new Chunk("No description recorded", bodyFont));
    }

    return p;
}
项目:tellervo    文件:ProSheet.java   
private Paragraph getObjectComments() 
{

    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);
    p.setAlignment(Element.ALIGN_JUSTIFIED);
       p.setSpacingAfter(10);

    if(o.getComments()!=null){
        p.add(new Chunk("Notes: ", commentFont));
        p.add(new Chunk(o.getComments(), commentFont));
    }


    return p;
}
项目:tellervo    文件:CompleteBoxLabel.java   
/**
 * iText paragraph containing created and lastmodified timestamps
 * 
 * @return Paragraph
 */
private Paragraph getTimestampPDF(WSIBox b)
{
    // Set up calendar
    Date createdTimestamp = b.getCreatedTimestamp().getValue()
            .toGregorianCalendar().getTime();
    Date nowTimestamp = new Date();

    DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);

    Paragraph p = new Paragraph();


    p.add(new Chunk("Created: ", subSubSectionFont));
    p.add(new Chunk(df1.format(createdTimestamp), bodyFont));
    //p.add(new Chunk("\nLast Modified: ", subSubSectionFont));
    //p.add(new Chunk(df1.format(lastModifiedTimestamp), bodyFontLarge));
    p.add(new Chunk("\nLabel updated: ", subSubSectionFont));
    p.add(new Chunk(df1.format(nowTimestamp), bodyFont));


    return p;

}
项目:tellervo    文件:CompleteBoxLabel.java   
private Paragraph getComments(WSIBox b) throws DocumentException
{

    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);

    p.add(new Chunk("Comments: \n", subSubSectionFont));
    if(b.getComments()!=null){
        p.add(new Chunk(b.getComments(), bodyFont));
    }
    else{
        p.add(new Chunk("No comments recorded", bodyFont));
    }

    return(p);
}
项目:tellervo    文件:BasicBoxLabel.java   
/**
 * iText paragraph containing created and lastmodified timestamps
 * 
 * @return Paragraph
 */
private Paragraph getTimestampPDF(WSIBox b)
{
    // Set up calendar
    Date createdTimestamp = b.getCreatedTimestamp().getValue()
            .toGregorianCalendar().getTime();
    Date nowTimestamp = new Date();

    DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);

    Paragraph p = new Paragraph();


    p.add(new Chunk("Created: ", subSubSectionFont));
    p.add(new Chunk(df1.format(createdTimestamp), bodyFont));
    //p.add(new Chunk("\nLast Modified: ", subSubSectionFont));
    //p.add(new Chunk(df1.format(lastModifiedTimestamp), bodyFontLarge));
    p.add(new Chunk("\nLabel updated: ", subSubSectionFont));
    p.add(new Chunk(df1.format(nowTimestamp), bodyFont));


    return p;

}
项目:tellervo    文件:BasicBoxLabel.java   
private Paragraph getComments(WSIBox b) throws DocumentException
{

    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);

    p.add(new Chunk("Comments: \n", subSubSectionFont));
    if(b.getComments()!=null){
        p.add(new Chunk(b.getComments(), bodyFont));
    }
    else{
        p.add(new Chunk("No comments recorded", bodyFont));
    }

    return(p);
}