Java Code Examples for org.apache.pdfbox.pdmodel.edit.PDPageContentStream

The following are top voted examples for showing how to use org.apache.pdfbox.pdmodel.edit.PDPageContentStream. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: testarea-pdfbox1   File: InsertPages.java   Source Code and License 8 votes vote down vote up
public PDDocument create100Pages() throws IOException
{
    PDDocument document = new PDDocument();
    
    for (int i = 0; i < 100; i++)
    {
        PDPage page = new PDPage();
        document.addPage(page);
        PDPageContentStream content = new PDPageContentStream(document, page);
        content.beginText();
        content.setFont(PDType1Font.HELVETICA_BOLD, 100);
        content.moveTextPositionByAmount(100, 300);
        content.drawString(String.format("-%s-", i + 1));
        content.endText();
        content.close();
    }
    
    return document;
}
 
Example 2
Project: ctsms   File: PDFImprinter.java   Source Code and License 7 votes vote down vote up
private PDPageContentStream openContentStream(PDPage page, boolean setPageSize, boolean applyPageOrientation) throws IOException {
	contentStream = new PDPageContentStream(doc, page, true, false);
	if (painter != null) {
		PDRectangle pageSize = page.findMediaBox();
		if (PageOrientation.LANDSCAPE.equals(painter.getPageOrientation())) {
			if (setPageSize) {
				painter.setPageHeight(pageSize.getWidth());
				painter.setPageWidth(pageSize.getHeight());
			}
			if (applyPageOrientation) {
				contentStream.concatenate2CTM(0, 1, -1, 0, pageSize.getWidth(), 0); // cos(theta) sin(theta) -sin(theta) cos(theta) 0 0 cm
			}
		} else {
			if (setPageSize) {
				painter.setPageHeight(pageSize.getHeight());
				painter.setPageWidth(pageSize.getWidth());
			}
		}
	}
	return contentStream;
}
 
Example 3
Project: pdfbox-layout   File: AbstractShape.java   Source Code and License 7 votes vote down vote up
@Override
   public void fill(PDDocument pdDocument, PDPageContentStream contentStream,
    Position upperLeft, float width, float height, Color color,
    DrawListener drawListener) throws IOException {

add(pdDocument, contentStream, upperLeft, width, height);

if (color != null) {
    contentStream.setNonStrokingColor(color);
}
CompatibilityHelper.fillNonZero(contentStream);

if (drawListener != null) {
    drawListener.drawn(this, upperLeft, width, height);
}

   }
 
Example 4
Project: pdfboxExamples   File: PdfTable.java   Source Code and License 7 votes vote down vote up
@Test
public void test() throws IOException, COSVisitorException {

	PDDocument doc = new PDDocument();
	PDPage page = new PDPage();
	doc.addPage(page);
	PDPageContentStream contentStream = new PDPageContentStream(doc, page);

	String[][] content = { { "Team", "Captain" },
			{ "Hull City", "Robert Koren" },
			{ "Aston Villa", "Ron Vlaar" },
			{ "Manchester United", "Nemanja Vidic" },
			{ "Manchester City", "Vincent Kompany" } };

	drawTable(page, contentStream, 700, 100, content);

	contentStream.close();
	Path outputFilePath = Files.createTempFile("Test-CaptainTeam-Table", ".pdf");
	doc.save(outputFilePath.toFile());
	logger.info("test# "+ outputFilePath.toAbsolutePath().toString());

}
 
Example 5
Project: testarea-pdfbox1   File: PdfRenderingEndorsementAlternative.java   Source Code and License 7 votes vote down vote up
void newPage() throws IOException
{
    close();

    PDPage page = new PDPage(PDPage.PAGE_SIZE_LETTER);
    doc.addPage(page);
    content = new PDPageContentStream(doc, page);
    content.drawImage(logoImg, 50, 720);
    content.setLineWidth(.5f);
    content.setNonStrokingColor(Color.GRAY);
    content.drawLine(50, 710, 562, 710);

    previousBandBase = 770;
    render(new BandColumn(BandColumn.Layout.headerText, "ENDOSO", null));
    for (String head: header)
        render(new BandColumn(BandColumn.Layout.headerText, head, null));

    content.setNonStrokingColor(Color.BLACK);
    previousBandBase = 680;
}
 
Example 6
Project: testarea-pdfbox1   File: ExtractWithoutExtraSpaces.java   Source Code and License 7 votes vote down vote up
byte[] createTestDocument() throws IOException, COSVisitorException
{
    try (   ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PDDocument doc = new PDDocument()   )
    {
        PDPage page = new PDPage(new PDRectangle(792, 612));
        doc.addPage(page);
        
        PDFont font = PDType1Font.COURIER;

        PDPageContentStream contents = new PDPageContentStream(doc, page);
        contents.beginText();
        contents.setFont(font, 9);
        contents.moveTextPositionByAmount(100, 500);
        contents.drawString("             2                                                                  Netto        5,00 EUR 3,00");
        contents.moveTextPositionByAmount(0, 0);
        contents.drawString("                2882892  ENERGIZE LR6 Industrial                     2,50 EUR 1");
        contents.endText();
        contents.close();
        
        doc.save(baos);
        
        return baos.toByteArray();
    }
}
 
Example 7
Project: pdfwriter   File: PDFChart.java   Source Code and License 7 votes vote down vote up
private void writeImageToPDF(PDJpeg img, int c, int size) throws IOException {
	PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
				
	float x = getLeftX();
	float y = page.getYCursor()-img.getHeight();

	if (c>0&&(c%2==0)) {
		x+=350;
	}
	
	if (size > 0) {
		y = page.getYCursor()-400;
	}
	if (isFullPage())
		  y = page.getLowY();
		cs.drawImage(img, x, y);
 		cs.close();
}
 
Example 8
Project: pdfwriter   File: PageHeader.java   Source Code and License 7 votes vote down vote up
public void create(PDDocument document, PDFPage page) throws IOException {

	PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
       
	PDRectangle pageSize = page.getBleedBox();
       float pageWidth = pageSize.getWidth();
       page.translateAndRotateIfNecessary(cs, pageWidth, 0);
       
	cs.beginText();
	PDFont font = PDType1Font.HELVETICA_BOLD;
	cs.setFont(font, 20);
	cs.moveTextPositionByAmount(page.getLeftX(), page.getTopY());
	cs.drawString(title);
	cs.endText();
	cs.drawLine(page.getLeftX(), page.getTopY()-height, page.getRightX(), page.getTopY()-height);
		cs.close();
}
 
Example 9
Project: pdfwriter   File: PDFTable.java   Source Code and License 7 votes vote down vote up
public void addTitleRow(String[] titles) throws IOException {
	if (hideTable)
		return;
	int size = 16;
	float cellSize = (getWidth()/titles.length);
	PDFont font = PDType1Font.HELVETICA_BOLD;
	PDPageContentStream cs = new PDPageContentStream(document, page, true, 	false);
	cs.setFont(font, size);
	float leftX = getLeftX()+30;

	for (String title : titles) {
		cs.beginText();
		cs.moveTextPositionByAmount(leftX, page.getYCursor());
		cs.drawString(title);
		cs.endText();
		if (cellSize != -1)
			leftX += cellSize;
		else
			leftX += (font.getStringWidth(title) / 1000 * size)+5;
	}
	cs.drawLine(getLeftX(), page.getYCursor() - 5, getRightX(), page.getYCursor() - 5);
	cs.close();
	
	scrolldown();
}
 
Example 10
Project: brigen-base   File: TextPageAppender.java   Source Code and License 7 votes vote down vote up
@Override
protected void appendContent(int start, int pages, int page, PDPageContentStream contentStream,
        PDRectangle rect) throws IOException {
    float fontSize = getFontSize();
    contentStream.beginText();
    contentStream.setFont(font, fontSize);
    contentStream.setNonStrokingColor(getColor());
    String str = getText(start, pages, page);
    float contentWidth;
    float contentHeight;
    {
        contentWidth = (font.getStringWidth(str) / 1000) * fontSize;
        contentHeight = (font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000)
                * fontSize;
    }
    double angle = (getRotate() * Math.PI) / 180.0;
    float[] point = getRotatePoint(angle, rect.getWidth(), rect.getHeight(), contentWidth,
            contentHeight);
    contentStream.setTextRotation(angle, point[0], point[1]);
    contentStream.drawString(str);
    contentStream.endText();
}
 
Example 11
Project: ctsms   File: Settings.java   Source Code and License 6 votes vote down vote up
private static String checkPDFTemplateFileName(String PDFTemplateFileName, String path) throws IOException, IllegalArgumentException {
	String template;
	if (PDFTemplateFileName != null && PDFTemplateFileName.length() > 0) {
		File file = new File(PDFTemplateFileName);
		if (file.exists()) {
			if (file.isFile()) {
				if (file.canRead()) {
					PDDocument doc = null;
					try {
						doc = PDDocument.load(file);
						PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get(0);
						PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
						contentStream.close();
						template = file.getCanonicalPath();
					} catch (Exception e) {
						throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_INVALID_PDF_ERROR,
								DefaultMessages.PDF_TEMPLATE_FILE_INVALID_PDF_ERROR, PDFTemplateFileName), e);
					} finally {
						if (doc != null) {
							doc.close();
						}
					}
				} else {
					throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_ACCESS_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_ACCESS_ERROR,
							PDFTemplateFileName));
				}
			} else {
				throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_NOTAFILE_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_NOTAFILE_ERROR,
						PDFTemplateFileName));
			}
		} else {
			throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_DOES_NOT_EXIST_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_DOES_NOT_EXIST_ERROR,
					PDFTemplateFileName));
		}
	} else {
		template = "";
	}
	return template;
}
 
Example 12
Project: ctsms   File: EcrfPDFPainter.java   Source Code and License 6 votes vote down vote up
private void drawBlock(PDPageContentStream contentStream,EcrfPDFBlock block ) throws Exception {
	if (// BlockType.NEW_LIST_ENTRY.equals(block.getType())
			BlockType.NEW_ECRF.equals(block.getType())) {
		// || BlockType.ECRF_SIGNATURE.equals(block.getType())) {
		cursor.setSectionY(cursor.getBlockY());
		cursor.setIndexY(cursor.getBlockY());
	} else if (BlockType.NEW_SECTION.equals(block.getType())) {
		cursor.setSectionY(cursor.getBlockY());
		cursor.setIndexY(cursor.getBlockY());
	} else if (BlockType.NEW_INDEX.equals(block.getType())) {
		cursor.setIndexY(cursor.getBlockY());
	}
	cursor.setBlocks(block);
	cursor.setBlockY(cursor.getBlockY() - block.renderBlock(contentStream, cursor));

}
 
Example 13
Project: ctsms   File: EcrfPDFPainter.java   Source Code and License 6 votes vote down vote up
public void drawPageBreakNewPage(PDPageContentStream contentStream) throws Exception {
	EcrfPDFBlock block = blocks.get(blockIndex);

	if (BlockType.INPUT_FIELD.equals(block.getType())
			|| BlockType.AUDIT_TRAIL_VALUE.equals(block.getType())
			|| BlockType.FIELD_STATUS_ENTRY.equals(block.getType())
			|| BlockType.NEW_SECTION.equals(block.getType())
			|| BlockType.NEW_INDEX.equals(block.getType())) {
		// paint ecrf header again
		drawBlock(contentStream, new EcrfPDFBlock(cursor.getEcrfBlock(), true));
	}
	if (BlockType.INPUT_FIELD.equals(block.getType())
			|| BlockType.AUDIT_TRAIL_VALUE.equals(block.getType())
			|| BlockType.FIELD_STATUS_ENTRY.equals(block.getType())) {
		// start section+index again
		drawBlock(contentStream, new EcrfPDFBlock(cursor.getSectionBlock(), true));
		drawBlock(contentStream, new EcrfPDFBlock(cursor.getIndexBlock(), true));
	}
}
 
Example 14
Project: ctsms   File: ProbandLetterPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	PDFUtil.renderTextLine(
			contentStream,
			fontA,
			PDFUtil.FontSize.TINY,
			Settings.getColor(ProbandLetterPDFSettingCodes.TEXT_COLOR, Bundle.PROBAND_LETTER_PDF, ProbandLetterPDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getProbandLetterPDFLabel(Locales.PROBAND_LETTER_PDF, ProbandLetterPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(ProbandLetterPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LETTER_PDF, ProbandLetterPDFDefaultSettings.PAGE_LEFT_MARGIN)
			+ (pageWidth
					- Settings.getFloat(ProbandLetterPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LETTER_PDF, ProbandLetterPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings
					.getFloat(ProbandLetterPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.PROBAND_LETTER_PDF, ProbandLetterPDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f,
					Settings.getFloat(ProbandLetterPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.PROBAND_LETTER_PDF, ProbandLetterPDFDefaultSettings.PAGE_LOWER_MARGIN),
					PDFUtil.Alignment.BOTTOM_CENTER);
	writer.closeContentStream();
}
 
Example 15
Project: ctsms   File: CVPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
public void drawPage(PDPageContentStream contentStream) throws Exception {
	// PDFUtil.renderFrame(contentStream, FRAME_COLOR, Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN),
	// Settings.getFloat(CVPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LOWER_MARGIN), pageWidth -
	// Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat(CVPDFSettingCodes.PAGE_RIGHT_MARGIN,
	// Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_RIGHT_MARGIN), pageHeight - PAGE_UPPER_MARGIN - Settings.getFloat(CVPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.CV_PDF,
	// CVPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_LEFT, PAGE_FRAME_LINE_WIDTH);

	if (cursor.getStaff() != null) {
		// CVPDFBlock block = blocks.get(blockIndex - 1);
		PDFUtil.renderTextLine(
				contentStream,
				fontA,
				PDFUtil.FontSize.TINY,
				Settings.getColor(CVPDFSettingCodes.TEXT_COLOR, Bundle.CV_PDF, CVPDFDefaultSettings.TEXT_COLOR),
				L10nUtil.getCVPDFLabel(Locales.CV_PDF, CVPDFLabelCodes.FOOTER_NAME, "", cursor.getStaff().getNameWithTitles()),
				Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN),
				Settings.getFloat(CVPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_LEFT);
	}
}
 
Example 16
Project: ctsms   File: CVPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	// PDFUtil.renderTextLine(
	// contentStream,
	// fontA,
	// PDFUtil.FontSize.TINY,
	// Settings.getColor(CVPDFSettingCodes.TEXT_COLOR, Bundle.CV_PDF, CVPDFDefaultSettings.TEXT_COLOR),
	// L10nUtil.getCVPDFLabel(Locales.CV_PDF, CVPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
	// Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN)
	// + (pageWidth - Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat(
	// CVPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f,
	// Settings.getFloat(CVPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_CENTER);

	PDFUtil.renderTextLine(
			contentStream,
			fontA,
			PDFUtil.FontSize.TINY,
			Settings.getColor(CVPDFSettingCodes.TEXT_COLOR, Bundle.CV_PDF, CVPDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getCVPDFLabel(Locales.CV_PDF, CVPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN)
					+ (pageWidth - Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat(
							CVPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_RIGHT_MARGIN)),
					Settings.getFloat(CVPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_RIGHT);
	writer.closeContentStream();
}
 
Example 17
Project: ctsms   File: CourseCertificatePDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	PDFUtil.renderTextLine(
			contentStream,
			fontA,
			PDFUtil.FontSize.TINY,
			Settings.getColor(CourseCertificatePDFSettingCodes.TEXT_COLOR, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getCourseCertificatePDFLabel(Locales.COURSE_CERTIFICATE_PDF, CourseCertificatePDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_LEFT_MARGIN)
			+ (pageWidth
					- Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.COURSE_CERTIFICATE_PDF,
							CourseCertificatePDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_RIGHT_MARGIN,
									Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f,
									Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_LOWER_MARGIN),
									PDFUtil.Alignment.BOTTOM_CENTER);
	writer.closeContentStream();
}
 
Example 18
Project: ctsms   File: ReimbursementsPDFPainter.java   Source Code and License 6 votes vote down vote up
public void drawPageBreakOldPage(PDPageContentStream contentStream) throws Exception {
	ReimbursementsPDFBlock block = blocks.get(blockIndex - 1);
	// if (BlockType.NEW_INDEX.equals(block.getType())) {
	// (new EcrfPDFBlock(BlockType.END_OF_SECTION)).renderBlock(contentStream, cursor);
	// } else
	if (BlockType.PAYMENT_METHOD_TABLE_ROW.equals(block.getType())
			|| BlockType.BANK_ACCOUNT_TABLE_ROW.equals(block.getType())) {
		if (!block.isLastTableRow()) {
			PDFUtil.renderLine(contentStream, Settings.getColor(ReimbursementsPDFSettingCodes.PAYMENT_TABLE_FRAME_COLOR, Bundle.REIMBURSEMENTS_PDF,
					ReimbursementsPDFDefaultSettings.PAYMENT_TABLE_FRAME_COLOR), cursor.getBlockX(), cursor.getBlockY(),// - height,
					cursor.getBlockX() + cursor.getBlockWidth(), cursor.getBlockY(),// - height, // height,
					// PDFUtil.Alignment.TOP_LEFT,
					Settings.getFloat(ReimbursementsPDFSettingCodes.PAYMENT_TABLE_BLOCK_FRAME_LINE_WIDTH, Bundle.REIMBURSEMENTS_PDF,
							ReimbursementsPDFDefaultSettings.PAYMENT_TABLE_BLOCK_FRAME_LINE_WIDTH));
		}
	}
}
 
Example 19
Project: ctsms   File: ReimbursementsPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	PDFUtil.renderTextLine(
			contentStream,
			fontD,
			PDFUtil.FontSize.TINY,
			Settings.getColor(ReimbursementsPDFSettingCodes.TEXT_COLOR, Bundle.REIMBURSEMENTS_PDF, ReimbursementsPDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getReimbursementsPDFLabel(Locales.REIMBURSEMENTS_PDF, ReimbursementsPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(ReimbursementsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.REIMBURSEMENTS_PDF, ReimbursementsPDFDefaultSettings.PAGE_LEFT_MARGIN)
			+ (pageWidth
					- Settings.getFloat(ReimbursementsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.REIMBURSEMENTS_PDF, ReimbursementsPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings
					.getFloat(ReimbursementsPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.REIMBURSEMENTS_PDF, ReimbursementsPDFDefaultSettings.PAGE_RIGHT_MARGIN))
					/ 2.0f,
					Settings.getFloat(ReimbursementsPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.REIMBURSEMENTS_PDF, ReimbursementsPDFDefaultSettings.PAGE_LOWER_MARGIN),
					PDFUtil.Alignment.BOTTOM_CENTER);
	writer.closeContentStream();
}
 
Example 20
Project: ctsms   File: ProbandListEntryTagsPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
public void drawPage(PDPageContentStream contentStream) throws Exception {
	if (cursor.getListEntryBlock() != null) {
		(new ProbandListEntryTagsPDFBlock(cursor.getListEntryBlock(), BlockType.PAGE_TITLE, true)).renderBlock(contentStream, cursor);
	}
	// PDFUtil.renderFrame(contentStream, FRAME_COLOR, Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF,
	// ProbandListEntryTagsPDFDefaultSettings.PAGE_LEFT_MARGIN),
	// Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_LOWER_MARGIN),
	// pageWidth -
	// Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_LEFT_MARGIN) -
	// Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_RIGHT_MARGIN,
	// Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_RIGHT_MARGIN), pageHeight - PAGE_UPPER_MARGIN -
	// Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LOWER_MARGIN,
	// Bundle.PROBAND_LIST_ENTRY_TAGS_PDF,
	// ProbandListEntryTagsPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_LEFT, PAGE_FRAME_LINE_WIDTH);
}
 
Example 21
Project: ctsms   File: ProbandListEntryTagsPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	PDFUtil.renderTextLine(
			contentStream,
			fontA,
			PDFUtil.FontSize.TINY,
			Settings.getColor(ProbandListEntryTagsPDFSettingCodes.TEXT_COLOR, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getProbandListEntryTagsPDFLabel(Locales.PROBAND_LIST_ENTRY_TAGS_PDF, EcrfPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_LEFT_MARGIN)
			+ (pageWidth
					- Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF,
							ProbandListEntryTagsPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings
							.getFloat(
									ProbandListEntryTagsPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF,
									ProbandListEntryTagsPDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f,
									Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF,
											ProbandListEntryTagsPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_CENTER);
	writer.closeContentStream();
}
 
Example 22
Project: ctsms   File: InputFieldPDFBlock.java   Source Code and License 6 votes vote down vote up
private float renderTextValue(float x, float y, InputFieldType fieldType, PDPageContentStream contentStream, InputFieldPDFBlockCursor cursor) throws Exception {
	float width = cursor.getBlockIndentedX() + cursor.getBlockIndentedWidth() - x - getXFrameIndent();
	float height = Math.max(PDFUtil.renderMultilineText(
			contentStream,
			cursor.getFontB(),
			PDFUtil.FontSize.MEDIUM,
			isPreset() || blank ? getPresetTextColor() : getTextColor(),
					getTextValue(blank),
					x,
					y,
					PDFUtil.Alignment.TOP_LEFT,
					width), InputFieldType.MULTI_LINE_TEXT.equals(fieldType) ? getMultiLineTextMinHeight() : 0.0f);
	PDFUtil.renderFrame(contentStream, getFrameColor(),
			x - getXValueFrameIndent(),
			y + getYValueFrameIndent(),
			width + 2.0f * getXValueFrameIndent(),
			height + 2.0f * getYValueFrameIndent(),
			PDFUtil.Alignment.TOP_LEFT, getValueFrameLineWidth());
	return height;
}
 
Example 23
Project: ctsms   File: InquiriesPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	PDFUtil.renderTextLine(
			contentStream,
			fontA,
			PDFUtil.FontSize.TINY,
			Settings.getColor(InquiriesPDFSettingCodes.TEXT_COLOR, Bundle.INQUIRIES_PDF, InquiriesPDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getInquiriesPDFLabel(Locales.INQUIRIES_PDF, EcrfPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(InquiriesPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.INQUIRIES_PDF, InquiriesPDFDefaultSettings.PAGE_LEFT_MARGIN)
			+ (pageWidth - Settings.getFloat(InquiriesPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.INQUIRIES_PDF, InquiriesPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings
					.getFloat(
							InquiriesPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.INQUIRIES_PDF, InquiriesPDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f,
							Settings.getFloat(InquiriesPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.INQUIRIES_PDF, InquiriesPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_CENTER);
	writer.closeContentStream();
}
 
Example 24
Project: ctsms   File: CourseParticipantListPDFPainter.java   Source Code and License 6 votes vote down vote up
@Override
protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException {
	PDPageContentStream contentStream = writer.openContentStream(page);
	PDFUtil.renderTextLine(
			contentStream,
			fontA,
			PDFUtil.FontSize.TINY,
			Settings.getColor(CourseParticipantListPDFSettingCodes.TEXT_COLOR, Bundle.COURSE_PARTICIPANT_LIST_PDF, CourseParticipantListPDFDefaultSettings.TEXT_COLOR),
			L10nUtil.getCourseParticipantListPDFLabel(Locales.COURSE_PARTICIPANT_LIST_PDF, CourseParticipantListPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages),
			Settings.getFloat(CourseParticipantListPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.COURSE_PARTICIPANT_LIST_PDF,
					CourseParticipantListPDFDefaultSettings.PAGE_LEFT_MARGIN)
					+ (pageWidth
							- Settings.getFloat(CourseParticipantListPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.COURSE_PARTICIPANT_LIST_PDF,
									CourseParticipantListPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat(CourseParticipantListPDFSettingCodes.PAGE_RIGHT_MARGIN,
											Bundle.COURSE_PARTICIPANT_LIST_PDF, CourseParticipantListPDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f, Settings.getFloat(
													CourseParticipantListPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.COURSE_PARTICIPANT_LIST_PDF, CourseParticipantListPDFDefaultSettings.PAGE_LOWER_MARGIN),
													PDFUtil.Alignment.BOTTOM_CENTER);
	writer.closeContentStream();
}
 
Example 25
Project: ctsms   File: PDFUtil.java   Source Code and License 6 votes vote down vote up
private static void drawString(PDPageContentStream contentStream, String text) throws IOException {
	if (contentStream != null && text != null && text.length() > 0) {
		char[] tc = text.toCharArray();
		StringBuilder sb = new StringBuilder();
		Encoding encoding = EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING);
		for (int i = 0; i < tc.length; i++) {
			Character c = tc[i];
			try {
				sb.appendCodePoint(encoding.getCode(encoding.getNameFromCharacter(c)));
			} catch (IOException e) {
				sb.append(c);
			}
		}
		contentStream.drawString(sb.toString());
	}
}
 
Example 26
Project: ctsms   File: PDFUtil.java   Source Code and License 6 votes vote down vote up
private static void setLineDashPattern(PDPageContentStream contentStream, LineStyle lineStyle) throws IOException {
	if (contentStream != null) { // && lineStyle != null) {
		float[] pattern;
		float phase;
		switch (lineStyle) {
			case DASHED:
				pattern = new float[]{3.0f};
				phase = 0.0f;
				break;
			default: //solid else...
				pattern = new float[] {};
				phase = 0.0f;
				break;
		}
		// if (pattern != null) {
		contentStream.setLineDashPattern(pattern, phase);
		// }
	}
}
 
Example 27
Project: pdfbox-layout   File: HorizontalRuler.java   Source Code and License 6 votes vote down vote up
@Override
   public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
    Position upperLeft, DrawListener drawListener) throws IOException {
if (getColor() != null) {
    contentStream.setStrokingColor(getColor());
}
if (getStroke() != null) {
    getStroke().applyTo(contentStream);
    float x = upperLeft.getX();
    float y = upperLeft.getY() - getStroke().getLineWidth() / 2;
    contentStream.addLine(x, y, x + getWidth(), y);
    contentStream.stroke();
}
if (drawListener != null) {
    drawListener.drawn(this, upperLeft, getWidth(), getHeight());
}
   }
 
Example 28
Project: pdfbox-layout   File: AbstractShape.java   Source Code and License 6 votes vote down vote up
@Override
   public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
    Position upperLeft, float width, float height, Color color,
    Stroke stroke, DrawListener drawListener) throws IOException {

add(pdDocument, contentStream, upperLeft, width, height);

if (stroke != null) {
    stroke.applyTo(contentStream);
}
if (color != null) {
    contentStream.setStrokingColor(color);
}
contentStream.stroke();

if (drawListener != null) {
    drawListener.drawn(this, upperLeft, width, height);
}

   }
 
Example 29
Project: testarea-pdfbox1   File: RolloverAnnotation.java   Source Code and License 6 votes vote down vote up
void createRollover(PDAnnotation annotation, String filename) throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    List<PDAnnotation> annotations = page.getAnnotations();

    float x = 100;
    float y = 500;
    String text = "PDFBox";
    PDFont font = PDType1Font.HELVETICA_BOLD;
    float textWidth = font.getStringWidth(text) / 1000 * 18;

    PDPageContentStream contents = new PDPageContentStream(document, page);
    contents.beginText();
    contents.setFont(font, 18);
    contents.moveTextPositionByAmount(x, y);
    contents.drawString(text);
    contents.endText();
    contents.close();

    PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
    PDAppearanceStream normal = createAppearanceStream(document, textWidth, font, "0.5 0.5 0.5 rg");
    PDAppearanceStream rollover = createAppearanceStream(document, textWidth, font, "1 0.7 0.5 rg");
    PDAppearanceStream down = createAppearanceStream(document, textWidth, font, "0 0 0 rg");
    appearanceDictionary.setNormalAppearance(normal);
    appearanceDictionary.setRolloverAppearance(rollover);
    appearanceDictionary.setDownAppearance(down);
    annotation.setAppearance(appearanceDictionary);

    PDRectangle position = new PDRectangle();
    position.setLowerLeftX(x);
    position.setLowerLeftY(y - 5);
    position.setUpperRightX(x + textWidth);
    position.setUpperRightY(y + 20);
    annotation.setRectangle(position);

    annotations.add(annotation);
    document.save(new File(RESULT_FOLDER, filename));
    document.close();
}
 
Example 30
Project: testarea-pdfbox1   File: OverlayWithEffect.java   Source Code and License 6 votes vote down vote up
void overlayWithDarkenBlendMode(PDDocument document, PDDocument overlay) throws IOException
{
    PDXObjectForm xobject = importAsXObject(document, (PDPage) overlay.getDocumentCatalog().getAllPages().get(0));
    PDExtendedGraphicsState darken = new PDExtendedGraphicsState();
    darken.getCOSDictionary().setName("BM", "Darken");
    
    List<PDPage> pages = document.getDocumentCatalog().getAllPages();

    for (PDPage page: pages)
    {
        Map<String, PDExtendedGraphicsState> states = page.getResources().getGraphicsStates();
        if (states == null)
            states = new HashMap<String, PDExtendedGraphicsState>();
        String darkenKey = MapUtil.getNextUniqueKey(states, "Dkn");
        states.put(darkenKey, darken);
        page.getResources().setGraphicsStates(states);

        PDPageContentStream stream = new PDPageContentStream(document, page, true, false, true);
        stream.appendRawCommands(String.format("/%s gs ", darkenKey));
        stream.drawXObject(xobject, 0, 0, 1, 1);
        stream.close();
    }
}
 
Example 31
Project: testarea-pdfbox1   File: OverwriteImage.java   Source Code and License 6 votes vote down vote up
/**
 * Applying the code to the OP's sample file from a former question.
 * 
 * @throws IOException
 * @throws CryptographyException
 * @throws COSVisitorException
 */
@Test
public void testDrunkenFistSample() throws IOException, CryptographyException, COSVisitorException
{
    try (   InputStream resource = getClass().getResourceAsStream("sample.pdf");
            InputStream left = getClass().getResourceAsStream("left.png");
            InputStream right = getClass().getResourceAsStream("right.png");
            PDDocument document = PDDocument.load(resource) )
    {
        if (document.isEncrypted())
        {
            document.decrypt("");
        }
        
        PDJpeg leftImage = new PDJpeg(document, ImageIO.read(left));
        PDJpeg rightImage = new PDJpeg(document, ImageIO.read(right));

        ImageLocator locator = new ImageLocator();
        List<?> allPages = document.getDocumentCatalog().getAllPages();
        for (int i = 0; i < allPages.size(); i++)
        {
            PDPage page = (PDPage) allPages.get(i);
            locator.processStream(page, page.findResources(), page.getContents().getStream());
        }

        for (ImageLocation location : locator.getLocations())
        {
            PDRectangle cropBox = location.getPage().findCropBox();
            float center = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2.0f;
            PDJpeg image = location.getMatrix().getXPosition() < center ? leftImage : rightImage;
            AffineTransform transform = location.getMatrix().createAffineTransform();

            PDPageContentStream content = new PDPageContentStream(document, location.getPage(), true, false, true);
            content.drawXObject(image, transform);
            content.close();
        }

        document.save(new File(RESULT_FOLDER, "sample-changed.pdf"));
    }
}
 
Example 32
Project: testarea-pdfbox1   File: ClipPage.java   Source Code and License 6 votes vote down vote up
void clipPage(PDDocument document, PDPage page, BoundingBox clipBox) throws IOException
{
	PDPageContentStream pageContentStream = new PDPageContentStream(document, page, true, false);
	pageContentStream.addRect(clipBox.getLowerLeftX(), clipBox.getLowerLeftY(), clipBox.getWidth(), clipBox.getHeight());
	pageContentStream.clipPath(PathIterator.WIND_NON_ZERO);
	pageContentStream.close();

	COSArray newContents = new COSArray();
	COSStreamArray contents = (COSStreamArray) page.getContents().getStream();
	newContents.add(contents.get(contents.getStreamCount()-1));
	for (int i = 0; i < contents.getStreamCount()-1; i++)
	{
		newContents.add(contents.get(i));
	}
	page.setContents(new PDStream(new COSStreamArray(newContents)));
}
 
Example 33
Project: testarea-pdfbox1   File: DrawSpecialCharacters.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/22260344/pdfbox-encode-symbol-currency-euro">
 * PdfBox encode symbol currency euro
 * </a>
 * <p>
 * Three ways of trying to draw a '�' symbol, the first one fails.
 * </p>
 */
@Test
public void testDrawEuro() throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream contents = new PDPageContentStream(document, page);
    PDFont font = PDType1Font.HELVETICA_BOLD;
    contents.beginText();
    contents.setFont(font, 18);
    contents.moveTextPositionByAmount(30, 600);
    contents.drawString("�");
    contents.moveTextPositionByAmount(0, -30);
    contents.drawString(String.valueOf(Character.toChars(EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING).getCode("Euro"))));
    contents.moveTextPositionByAmount(0, -30);
    byte[] commands = "(x) Tj ".getBytes();
    commands[1] = (byte) 128;
    contents.appendRawCommands(commands);
    contents.endText();
    contents.close();
    document.save(new File(RESULT_FOLDER, "Euro.pdf"));
    document.close();
}
 
Example 34
Project: testarea-pdfbox1   File: DrawSpecialCharacters.java   Source Code and License 6 votes vote down vote up
/**
    * <a href="http://stackoverflow.com/questions/30619974/pdfbox-unable-to-write-superscripted-characters">
    * PDFBox unable to write superscripted characters
    * </a>
    * <p>
    * {@link #testDrawTmSignBroken()} represents the observation the OP made,
    * {@link #testDrawTmSignCustomDraw()} is a solution using custom drawing operations, and
    * {@link #testDrawTmSignLetters()} is a solution drawing the trademark symbol using smaller letters with text rise.
    * </p>
    */
@Test
public void testDrawTmSignBroken() throws IOException, COSVisitorException
{
	PDDocument document = new PDDocument();
       PDPage page = new PDPage();
       document.addPage(page);
       PDPageContentStream contents = new PDPageContentStream(document, page);
       PDFont font = PDType1Font.HELVETICA_BOLD;
       contents.beginText();
       contents.setFont(font, 18);
       contents.moveTextPositionByAmount(30, 600);
       contents.drawString("90000039-PREDISOL � C YELLOW 13 SNDOT�M");
       contents.endText();
       contents.close();
       document.save(new File(RESULT_FOLDER, "TM_naive.pdf"));
       document.close();
}
 
Example 35
Project: testarea-pdfbox1   File: DrawSpecialCharacters.java   Source Code and License 6 votes vote down vote up
@Test
public void testDrawTmSignCustomDraw() throws IOException, COSVisitorException
{
	PDDocument document = new PDDocument();
       PDPage page = new PDPage();
       document.addPage(page);
       PDPageContentStream contents = new PDPageContentStream(document, page);
       PDFont font = PDType1Font.HELVETICA_BOLD;
       contents.beginText();
       contents.setFont(font, 18);
       contents.moveTextPositionByAmount(30, 600);
       contents.drawString("90000039-PREDISOL � C YELLOW 13 SNDOT");
       byte[] commands = "(x) Tj ".getBytes();
       commands[1] = (byte) 0231;
       contents.appendRawCommands(commands);
       contents.drawString("M");
       contents.endText();
       contents.close();
       document.save(new File(RESULT_FOLDER, "TM_customDraw.pdf"));
       document.close();
}
 
Example 36
Project: testarea-pdfbox1   File: DrawSpecialCharacters.java   Source Code and License 6 votes vote down vote up
@Test
public void testDrawTmSignLetters() throws IOException, COSVisitorException
{
	PDDocument document = new PDDocument();
       PDPage page = new PDPage();
       document.addPage(page);
       PDPageContentStream contents = new PDPageContentStream(document, page);
       PDFont font = PDType1Font.HELVETICA_BOLD;
       contents.beginText();
       contents.setFont(font, 18);
       contents.moveTextPositionByAmount(30, 600);
       contents.drawString("90000039-PREDISOL � C YELLOW 13 SNDOT");
       contents.appendRawCommands("\n6 Ts\n".getBytes());
       contents.setFont(font, 10);
       contents.drawString("TM");
       contents.appendRawCommands("\n0 Ts\n".getBytes());
       contents.setFont(font, 18);
       contents.drawString("M");
       contents.endText();
       contents.close();
       document.save(new File(RESULT_FOLDER, "TM_letters.pdf"));
       document.close();
}
 
Example 37
Project: testarea-pdfbox1   File: InsertPages.java   Source Code and License 6 votes vote down vote up
public PDDocument create1Page(String mark) throws IOException
{
    PDDocument document = new PDDocument();
    
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream content = new PDPageContentStream(document, page);
    content.beginText();
    content.setFont(PDType1Font.HELVETICA_BOLD, 100);
    content.moveTextPositionByAmount(100, 300);
    content.drawString(mark);
    content.endText();
    content.close();
    
    return document;
}
 
Example 38
Project: yuzhouwan   File: ReportConvertPdf.java   Source Code and License 6 votes vote down vote up
private static void drawImageWithScale(PDDocument doc, PDPageContentStream content, String imgPath,
                                       int bufferedImageType, float scale) throws IOException {
    BufferedImage bufferedImage = ImageIO.read(new File(imgPath));
    BufferedImage image = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImageType);
    image.createGraphics().drawRenderedImage(bufferedImage, null);

    PDXObjectImage xImage = new PDPixelMap(doc, image);

    content.drawXObject(xImage, 100, 100, xImage.getWidth() * scale, xImage.getHeight() * scale);
}
 
Example 39
Project: elaborate4-backend   File: PdfMaker.java   Source Code and License 6 votes vote down vote up
public PdfMaker(Project _project, EntityManager _entityManager) {
	this.project = _project;
	this.entityManager = _entityManager;
	if (_project == null) {
		doc = null;

	} else {
		try {
			doc = new PDDocument();

			ProjectService projectService = ProjectService.instance();
			projectService.setEntityManager(entityManager);
			List<ProjectEntry> projectEntriesInOrder = projectService.getProjectEntriesInOrder(project.getId());

			for (ProjectEntry projectEntry : projectEntriesInOrder) {
				PDPage page = new PDPage();
				doc.addPage(page);

				PDFont font = PDType1Font.HELVETICA_BOLD;

				PDPageContentStream content = new PDPageContentStream(doc, page);
				content.beginText();
				content.setFont(font, 12);
				content.drawString(projectEntry.getName());
				for (Transcription transcription : projectEntry.getTranscriptions()) {
					content.drawString(transcription.getTextLayer());
					content.drawString(transcription.getBody());
				}

				content.endText();
				content.close();
			}

		} catch (Exception e) {
			System.out.println("Exception");
		}
	}
}
 
Example 40
Project: pdfwriter   File: PDFTitlePage.java   Source Code and License 6 votes vote down vote up
private void addTitleAndSubtitle(int offset) throws IOException {
	PDPageContentStream cs = new PDPageContentStream(document, this, true, false);
	cs.beginText();
	cs.setFont(PDType1Font.HELVETICA_BOLD, 30);
	float xPosition = getLeftX()+50;
	float yPosition = ((getTopY()/2)-borders-offset);
	cs.moveTextPositionByAmount(xPosition, yPosition);
	cs.drawString(title);
	cs.endText();
	
	cs.beginText();
		cs.setFont(PDType1Font.HELVETICA_OBLIQUE, 20);
		yPosition -= 40;
	cs.moveTextPositionByAmount(xPosition, yPosition);
	cs.drawString(subtitle);
	cs.endText();

 		cs.close();
}