Java Code Examples for org.apache.pdfbox.pdmodel.font.PDType1Font#HELVETICA_BOLD
The following examples show how to use
org.apache.pdfbox.pdmodel.font.PDType1Font#HELVETICA_BOLD .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloWorldFont.java From blog-codes with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { // Create a document and add a page to it PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage( page ); // Create a new font object selecting one of the PDF base fonts PDFont font = PDType1Font.HELVETICA_BOLD; // Start a new content stream which will "hold" the to be created content PDPageContentStream contentStream = new PDPageContentStream(document, page); // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World" contentStream.beginText(); contentStream.setFont( font, 12 ); contentStream.newLineAtOffset( 100, 700 ); contentStream.showText( "Hello World" ); contentStream.endText(); // Make sure that the content stream is closed: contentStream.close(); // Save the results and ensure that the document is properly closed: document.save( "/home/lili/data/Hello World.pdf"); document.close(); }
Example 2
Source File: DetectFontLoader.java From synopsys-detect with Apache License 2.0 | 5 votes |
public PDFont loadBoldFont(final PDDocument document) { try { return PDType0Font.load(document, DetectFontLoader.class.getResourceAsStream("/NotoSansCJKtc-Bold.ttf")); } catch (final IOException e) { logger.warn("Failed to load CJK Bold font, some glyphs may not encode correctly.", e); return PDType1Font.HELVETICA_BOLD; } }
Example 3
Source File: ArrangeText.java From testarea-pdfbox2 with Apache License 2.0 | 5 votes |
/** * <a href="https://stackoverflow.com/questions/48902656/how-can-i-align-arrange-text-fields-into-two-column-layout-using-apache-pdfbox"> * How can I Align/ Arrange text fields into two column layout using Apache PDFBox - java * </a> * <p> * This test shows how to align text in two columns. * </p> */ @Test public void testArrangeTextForUser2967784() throws IOException { PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDFont fontNormal = PDType1Font.HELVETICA; PDFont fontBold = PDType1Font.HELVETICA_BOLD; PDPageContentStream contentStream =new PDPageContentStream(document, page); contentStream.beginText(); contentStream.newLineAtOffset(100, 600); contentStream.setFont(fontBold, 15); contentStream.showText("Name: "); contentStream.setFont(fontNormal, 15); contentStream.showText ("Rajeev"); contentStream.newLineAtOffset(200, 00); contentStream.setFont(fontBold, 15); contentStream.showText("Address: " ); contentStream.setFont(fontNormal, 15); contentStream.showText ("BNG"); contentStream.newLineAtOffset(-200, -20); contentStream.setFont(fontBold, 15); contentStream.showText("State: " ); contentStream.setFont(fontNormal, 15); contentStream.showText ("KAR"); contentStream.newLineAtOffset(200, 00); contentStream.setFont(fontBold, 15); contentStream.showText("Country: " ); contentStream.setFont(fontNormal, 15); contentStream.showText ("INDIA"); contentStream.endText(); contentStream.close(); document.save(new File(RESULT_FOLDER, "arrangedTextForUser2967784.pdf")); }
Example 4
Source File: TestLine.java From tabula-java with MIT License | 5 votes |
@Test public void testSetTextElements() { Line line = new Line(); TextElement tElement = new TextElement(0, 0, 0, 0, PDType1Font.HELVETICA_BOLD, 10, "test", 5); TextChunk tChunk = new TextChunk(tElement); List<TextChunk> tList = new ArrayList<>(); tList.add(tChunk); line.setTextElements(tList); assertEquals("test", line.getTextElements().get(0).getText()); }
Example 5
Source File: TestLine.java From tabula-java with MIT License | 5 votes |
@Test public void testAddTextChunkIntTextChunk() { Line line = new Line(); TextElement tElement = new TextElement(0, 0, 0, 0, PDType1Font.HELVETICA_BOLD, 10, "test", 5); TextChunk tChunk = new TextChunk(tElement); line.addTextChunk(3, tChunk); assertEquals("test", line.getTextElements().get(3).getText()); }
Example 6
Source File: TestLine.java From tabula-java with MIT License | 5 votes |
@Test public void testLessThanAddTextChunkIntTextChunk() { Line line = new Line(); TextElement tElement = new TextElement(0, 0, 0, 0, PDType1Font.HELVETICA_BOLD, 10, "test", 5); TextChunk tChunk = new TextChunk(tElement); line.addTextChunk(0, tChunk); line.addTextChunk(0, tChunk); assertEquals("testtest", line.getTextElements().get(0).getText()); }
Example 7
Source File: TestLine.java From tabula-java with MIT License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testErrorAddTextChunkIntTextChunk() { Line line = new Line(); TextElement tElement = new TextElement(0, 0, 0, 0, PDType1Font.HELVETICA_BOLD, 10, "test", 5); TextChunk tChunk = new TextChunk(tElement); line.addTextChunk(-1, tChunk); }
Example 8
Source File: TestLine.java From tabula-java with MIT License | 5 votes |
@Test public void testToString() { Line line = new Line(); TextElement tElement = new TextElement(0, 0, 0, 0, PDType1Font.HELVETICA_BOLD, 10, "test", 5); TextChunk tChunk = new TextChunk(tElement); line.addTextChunk(0, tChunk); line.addTextChunk(0, tChunk); assertEquals("technology.tabula.Line[x=0.0,y=0.0,w=0.0,h=0.0,bottom=0.000000,right=0.000000,chunks='testtest', ]", line.toString()); }
Example 9
Source File: TestCell.java From tabula-java with MIT License | 5 votes |
@Test public void testGetTextElements() { Cell cell = new Cell(0, 0, 0, 0); assertTrue(cell.getTextElements().isEmpty()); TextElement tElement = new TextElement(0, 0, 0, 0, PDType1Font.HELVETICA_BOLD, 10, "test", 5); TextChunk tChunk = new TextChunk(tElement); List<TextChunk> tList = new ArrayList<>(); tList.add(tChunk); cell.setTextElements(tList); assertEquals("test", cell.getTextElements().get(0).getText()); }
Example 10
Source File: PdfBoxFontMapper.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
public static PDType1Font getPDFont(Font javaFont) { switch (javaFont.getFamily()) { case Font.SERIF: if (javaFont.isPlain()) { return PDType1Font.TIMES_ROMAN; } else if (javaFont.isBold()) { if (javaFont.isItalic()) { return PDType1Font.TIMES_BOLD_ITALIC; } else { return PDType1Font.TIMES_BOLD; } } else { return PDType1Font.TIMES_ITALIC; } case Font.SANS_SERIF: if (javaFont.isPlain()) { return PDType1Font.HELVETICA; } else if (javaFont.isBold()) { if (javaFont.isItalic()) { return PDType1Font.HELVETICA_BOLD_OBLIQUE; } else { return PDType1Font.HELVETICA_BOLD; } } else { return PDType1Font.HELVETICA_OBLIQUE; } case Font.MONOSPACED: if (javaFont.isPlain()) { return PDType1Font.COURIER; } else if (javaFont.isBold()) { if (javaFont.isItalic()) { return PDType1Font.COURIER_BOLD_OBLIQUE; } else { return PDType1Font.COURIER_BOLD; } } else { return PDType1Font.COURIER_OBLIQUE; } case Font.DIALOG: case Font.DIALOG_INPUT: return PDType1Font.SYMBOL; default: throw new DSSException("The font is not supported! Please use DSSFileFont implementation for custom fonts."); } }