本文整理匯總了Java中org.apache.pdfbox.pdmodel.font.PDType1Font.HELVETICA_BOLD屬性的典型用法代碼示例。如果您正苦於以下問題:Java PDType1Font.HELVETICA_BOLD屬性的具體用法?Java PDType1Font.HELVETICA_BOLD怎麽用?Java PDType1Font.HELVETICA_BOLD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.pdfbox.pdmodel.font.PDType1Font
的用法示例。
在下文中一共展示了PDType1Font.HELVETICA_BOLD屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test001
@Test
public void test001() throws IOException {
//E:\Repository\Git\melon\melon-sample-pdf\src\main\resources\HTTP權威指南.pdf
System.out.println("Hello World!");
PDDocument pdDocument = new PDDocument();
PDPage pdPage = new PDPage();
pdDocument.addPage(pdPage);
PDFont pdFont = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, pdPage);
contentStream.beginText();
contentStream.setFont(pdFont, 14);
contentStream.newLineAtOffset(100, 700);
contentStream.showText("Hello World");
contentStream.endText();
contentStream.close();
String directory = PdfDemo.class.getClassLoader().getResource("").getPath();
String fileName = "text.pdf";
pdDocument.save(directory + fileName);
pdDocument.close();
}
示例2: create
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();
}
示例3: addTitleRow
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();
}
示例4: chooseMatchingHelvetica
/**
* Get a PDType1Font.HELVETICA-variant, which matches the given font
*
* @param font
* Font to get the styles from
* @return a PDFont Helvetica variant which matches the style in the given Font
* object.
*/
public static PDFont chooseMatchingHelvetica(Font font) {
if ((font.getStyle() & (Font.ITALIC | Font.BOLD)) == (Font.ITALIC | Font.BOLD))
return PDType1Font.HELVETICA_BOLD_OBLIQUE;
if ((font.getStyle() & Font.ITALIC) == Font.ITALIC)
return PDType1Font.HELVETICA_OBLIQUE;
if ((font.getStyle() & Font.BOLD) == Font.BOLD)
return PDType1Font.HELVETICA_BOLD;
return PDType1Font.HELVETICA;
}
示例5: generateAttendeePage
private PDPage generateAttendeePage(Attendee attendee, PDDocument document) throws IOException {
PDPage page = new PDPage(new PDRectangle(612f, 396f));
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
// Positions are measured from the bottom left corner of the page at 72 DPI
// Set up global transformation matrix according to xOffset, yOffset.
// NOTE: if we want to support per-printer/per-client scaling, we would replace the 1's
// below, with xScale and yScale.
contentStream.concatenate2CTM(1, 0, 0, 1, xOffset, yOffset);
// Draw fields on badge depending on badge type
drawStaffNames(contentStream, attendee);
drawBadgeNumber(contentStream, attendee);
drawAgeColorStripe(contentStream, font, attendee);
drawBadgeType(contentStream, attendee);
contentStream.close();
return page;
}
示例6: main
public static void main(String[] args) throws IOException
{
PDDocument doc = new PDDocument();
File pdfFile = File.createTempFile("devict-example", ".pdf");
try
{
PDPage page = new PDPage();
doc.addPage(page);
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contents = new PDPageContentStream(doc, page);
contents.beginText();
contents.setFont(font, 12);
contents.newLineAtOffset(100, 700);
contents.showText("Hello DevICT PDFBox the time is " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
contents.endText();
contents.close();
doc.save(pdfFile);
}
finally
{
System.out.printf("PDF created and saved at %s\n", pdfFile.getAbsolutePath());
doc.close();
}
Desktop.getDesktop().open(pdfFile);
}
示例7: createRollover
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();
}
示例8: testDrawEuro
/**
* <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();
}
示例9: testDrawTmSignBroken
/**
* <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();
}
示例10: testDrawTmSignCustomDraw
@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();
}
示例11: testDrawTmSignLetters
@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();
}
示例12: convertPDF
@Override
public File convertPDF(File theFile, String md5UploadedFile) throws PDFConverterException {
try {
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(100, 700);
contentStream.showText("This is a test PDF file.");
contentStream.endText();
contentStream.close();
String outFileName = this.getOutputFileName(md5UploadedFile);
File outputFile = new File(Config.getString("application.staticFiles"), outFileName);
document.save(outputFile);
document.close();
return outputFile;
} catch (Exception e) {
log.error("Fail to create dummy PDF", e);
throw new PDFConverterException(e);
}
}
示例13: tryBuiltinFallback
private PDFont tryBuiltinFallback(String fontFamily, boolean isItalic, boolean isBold)
{
PDFont font;
fontFamily = fontFamily.toLowerCase();
switch (fontFamily) {
case "courier":
case "courier new":
case "lucida console":
if (isBold && isItalic) { font = PDType1Font.COURIER_BOLD_OBLIQUE;}
else if (isBold) { font = PDType1Font.COURIER_BOLD;}
else if (isItalic) { font = PDType1Font.COURIER_OBLIQUE;}
else { font = PDType1Font.COURIER;}
break;
case "times":
case "garamond":
case "georgia":
case "times new roman":
case "serif":
if (isBold && isItalic) { font = PDType1Font.TIMES_BOLD_ITALIC;}
else if (isBold) { font = PDType1Font.TIMES_BOLD;}
else if (isItalic) { font = PDType1Font.TIMES_ITALIC;}
else { font = PDType1Font.TIMES_ROMAN;}
break;
default:
if (isBold && isItalic) { font = PDType1Font.HELVETICA_BOLD_OBLIQUE;}
else if (isBold) { font = PDType1Font.HELVETICA_BOLD;}
else if (isItalic) { font = PDType1Font.HELVETICA_OBLIQUE;}
else { font = PDType1Font.HELVETICA;}
break;
}
return font;
}
示例14: testLessThanAddTextChunkIntTextChunk
@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());
}
示例15: testErrorAddTextChunkIntTextChunk
@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);
}