當前位置: 首頁>>代碼示例>>Java>>正文


Java PDType1Font類代碼示例

本文整理匯總了Java中org.apache.pdfbox.pdmodel.font.PDType1Font的典型用法代碼示例。如果您正苦於以下問題:Java PDType1Font類的具體用法?Java PDType1Font怎麽用?Java PDType1Font使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PDType1Font類屬於org.apache.pdfbox.pdmodel.font包,在下文中一共展示了PDType1Font類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createRingManagerDocument

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Test
public void createRingManagerDocument() throws Exception {
    final PDDocument document = new PDDocument();
    final PDPage page = new PDPage(PDRectangle.A4);
    document.addPage(page);

    final float startY = page.getMediaBox().getHeight() - 150;
    final int startX = 56;

    final PDPageContentStream contentStream = new PDPageContentStream(document, page);
    Table table = getRingManagerTable();

    (new TableDrawer(contentStream, table, startX, startY)).draw();

    contentStream.setFont(PDType1Font.HELVETICA, 8.0f);
    contentStream.beginText();

    contentStream.newLineAtOffset(startX, startY - (table.getHeight() + 22));
    contentStream.showText("Dieser Kampf muss der WB nicht entsprechen, da als Sparringskampf angesetzt.");
    contentStream.endText();

    contentStream.close();

    document.save("target/ringmanager.pdf");
    document.close();
}
 
開發者ID:vandeseer,項目名稱:easytable,代碼行數:27,代碼來源:TableDrawerIntegrationTest.java

示例2: addHeaderPJ

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
/**
 * @param textHeader
 * @param font
 * @param PAGE_SIZE_A4
 * @param contentStream
 * @return ajoute un header a la piece
 * @throws IOException
 */
private Float addHeaderPJ(final String textHeader, final PDFont font, final PDRectangle PAGE_SIZE_A4,
		final PDPageContentStream contentStream) throws IOException {
	Float marginTop = 0f;
	// si font Ok, on ajoute le text
	if (font != null && ConstanteUtils.DOSSIER_ADD_HEADER_IMG) {

		// calcul de la largeur et hauteur du txt
		Float titleWidth = font.getStringWidth(textHeader) / 1000 * ConstanteUtils.DOSSIER_FONT_SIZE;
		Float titleHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000
				* ConstanteUtils.DOSSIER_FONT_SIZE;

		// calcul de la marge du haut : hauteur du text + marge
		marginTop = titleHeight + ConstanteUtils.DOSSIER_MARGIN;

		// calcul de la position du text
		Float xText = (PAGE_SIZE_A4.getWidth() - 2 * ConstanteUtils.DOSSIER_MARGIN - titleWidth) / 2;
		Float yText = PAGE_SIZE_A4.getHeight() - marginTop;

		// ecriture du text
		contentStream.beginText();
		contentStream.setFont(PDType1Font.HELVETICA_BOLD, ConstanteUtils.DOSSIER_FONT_SIZE);
		contentStream.newLineAtOffset(xText, yText);
		contentStream.showText(textHeader);
		contentStream.endText();
	}
	return marginTop;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:36,代碼來源:CandidatureController.java

示例3: generateBillHeader

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
private void generateBillHeader(PDPage firstPage, PDPageContentStream contentStream)
        throws IOException {
    // Add header text
    PDFont currentFont;
    int currentFontSize;
    String headerLine1 = "Git Rekt Resort";
    String headerLine2 = "Customer Bill";
    contentStream.setLeading(10);
    currentFont = BOLD;
    currentFontSize = 14;
    contentStream.setFont(currentFont, currentFontSize);
    contentStream.beginText();
    float offsetX = getCenteredTextXPos(firstPage, headerLine1, currentFont, currentFontSize);
    contentStream.newLineAtOffset(offsetX, 750f);
    contentStream.showText(headerLine1);
    currentFont = PDType1Font.COURIER_BOLD;
    currentFontSize = 12;
    contentStream.setFont(currentFont, currentFontSize);
    float offsetX2 = getCenteredTextXPos(firstPage, headerLine2, currentFont, currentFontSize);
    contentStream.newLineAtOffset(-offsetX + offsetX2, -5f);
    contentStream.newLine();
    contentStream.showText(headerLine2);
    contentStream.endText();
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:25,代碼來源:BillPdfGenerator.java

示例4: test001

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@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();
}
 
開發者ID:ansafari,項目名稱:melon,代碼行數:26,代碼來源:PdfDemo.java

示例5: create100Pages

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
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;
}
 
開發者ID:mkl-public,項目名稱:testarea-pdfbox1,代碼行數:20,代碼來源:InsertPages.java

示例6: createSampleDocument

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Test
public void createSampleDocument() throws Exception {
    // Define the table structure first
    TableBuilder tableBuilder = new TableBuilder()
            .addColumnOfWidth(300)
            .addColumnOfWidth(120)
            .addColumnOfWidth(70)
            .setFontSize(8)
            .setFont(PDType1Font.HELVETICA);

    // Header ...
    tableBuilder.addRow(new RowBuilder()
            .add(Cell.withText("This is right aligned without a border").setHorizontalAlignment(RIGHT))
            .add(Cell.withText("And this is another cell"))
            .add(Cell.withText("Sum").setBackgroundColor(Color.ORANGE))
            .setBackgroundColor(Color.BLUE)
            .build());

    // ... and some cells
    for (int i = 0; i < 10; i++) {
        tableBuilder.addRow(new RowBuilder()
                .add(Cell.withText(i).withAllBorders())
                .add(Cell.withText(i * i).withAllBorders())
                .add(Cell.withText(i + (i * i)).withAllBorders())
                .setBackgroundColor(i % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE)
                .build());
    }

    final PDDocument document = new PDDocument();
    final PDPage page = new PDPage(PDRectangle.A4);
    document.addPage(page);

    final PDPageContentStream contentStream = new PDPageContentStream(document, page);

    // Define the starting point
    final float startY = page.getMediaBox().getHeight() - 50;
    final int startX = 50;

    // Draw!
    (new TableDrawer(contentStream, tableBuilder.build(), startX, startY)).draw();
    contentStream.close();

    document.save("target/sampleWithColorsAndBorders.pdf");
    document.close();
}
 
開發者ID:vandeseer,項目名稱:easytable,代碼行數:46,代碼來源:TableDrawerIntegrationTest.java

示例7: printPDFFile

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@FXML
public void printPDFFile(ActionEvent event) throws IOException {
    try {
        String fileName = "PDFoutput.pdf";

        PDDocument doc = new PDDocument();
        PDPage page = new PDPage();
        doc.addPage(page);

        PDPageContentStream content = new PDPageContentStream(doc, page);

        content.beginText();
        content.setFont(PDType1Font.TIMES_ROMAN, 26);
        content.moveTextPositionByAmount(220, 750);
        content.drawString("Titel");
        content.endText();

        content.beginText();
        content.setFont(PDType1Font.TIMES_ROMAN, 16);
        content.moveTextPositionByAmount(80, 700);
        content.drawString("Inhoud");
        content.endText();

        content.close();
        doc.save(fileName);
        doc.close();

        System.out.println("your file was saved in: " + System.getProperty("user.dir"));

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}
 
開發者ID:dewarian,項目名稱:FYS_T3,代碼行數:34,代碼來源:statisticsController.java

示例8: setUpProjectionProfile

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Before
public void setUpProjectionProfile() {
	PDPage pdPage = new PDPage();
	
	TextElement textElement = new TextElement(5f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "test", 1f);
	TextElement textElement2 = new TextElement(5f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "test", 1f);
	List<TextElement> textList = new ArrayList<>();
	textList.add(textElement);
	textList.add(textElement2);

	Ruling ruling = new Ruling(0, 0, 10, 10);
	List<Ruling> rulingList = new ArrayList<>();
	rulingList.add(ruling);


	page = new Page(0, 0, 1, 1, 0, 1, pdPage, textList, rulingList);
	
	List<Rectangle> rectangles = new ArrayList<>();
	rectangles.add(new Rectangle(0f, 0f, 500f, 5f));
	
	pProfile = new ProjectionProfile(page, rectangles, 5, 5);
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:23,代碼來源:TestProjectionProfile.java

示例9: createTextElement

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Test
public void createTextElement() {
	
	TextElement textElement = new TextElement(5f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f);
	
	Assert.assertNotNull(textElement);
	Assert.assertEquals("A", textElement.getText());
	Assert.assertEquals(1f, textElement.getFontSize(), 0);
	Assert.assertEquals(15f, textElement.getLeft(), 0);
	Assert.assertEquals(5f, textElement.getTop(), 0);
	Assert.assertEquals(10f, textElement.getWidth(), 0);
	Assert.assertEquals(20f, textElement.getHeight(), 0);
	Assert.assertEquals(PDType1Font.HELVETICA, textElement.getFont());
	Assert.assertEquals(1f, textElement.getWidthOfSpace(), 0);
	Assert.assertEquals(0f, textElement.getDirection(), 0);
	
	
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:19,代碼來源:TestTextElement.java

示例10: createTextElementWithDirection

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Test
public void createTextElementWithDirection() {
	
	TextElement textElement = new TextElement(5f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f, 6f);
	
	Assert.assertNotNull(textElement);
	Assert.assertEquals("A", textElement.getText());
	Assert.assertEquals(1f, textElement.getFontSize(), 0);
	Assert.assertEquals(15f, textElement.getLeft(), 0);
	Assert.assertEquals(5f, textElement.getTop(), 0);
	Assert.assertEquals(10f, textElement.getWidth(), 0);
	Assert.assertEquals(20f, textElement.getHeight(), 0);
	Assert.assertEquals(PDType1Font.HELVETICA, textElement.getFont());
	Assert.assertEquals(1f, textElement.getWidthOfSpace(), 0);
	Assert.assertEquals(6f, textElement.getDirection(), 0);
	
	
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:19,代碼來源:TestTextElement.java

示例11: mergeFourElementsIntoOneWord

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Test
public void mergeFourElementsIntoOneWord() {
	
	List<TextElement> elements = new ArrayList<>();
	elements.add(new TextElement(0f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f, 6f));
	elements.add(new TextElement(0f, 25f, 10f, 20f, PDType1Font.HELVETICA, 1f, "B", 1f, 6f));
	elements.add(new TextElement(0f, 35f, 10f, 20f, PDType1Font.HELVETICA, 1f, "C", 1f, 6f));
	elements.add(new TextElement(0f, 45f, 10f, 20f, PDType1Font.HELVETICA, 1f, "D", 1f, 6f));
	
	List<TextChunk> words = TextElement.mergeWords(elements);
	
	List<TextChunk> expectedWords = new ArrayList<>();
	TextChunk textChunk = new TextChunk(new TextElement(0f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f, 6f));
	textChunk.add(new TextElement(0f, 25f, 10f, 20f, PDType1Font.HELVETICA, 1f, "B", 1f, 6f));
	textChunk.add(new TextElement(0f, 35f, 10f, 20f, PDType1Font.HELVETICA, 1f, "C", 1f, 6f));
	textChunk.add(new TextElement(0f, 45f, 10f, 20f, PDType1Font.HELVETICA, 1f, "D", 1f, 6f));
	expectedWords.add(textChunk);
	
	Assert.assertEquals(expectedWords, words);
	
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:22,代碼來源:TestTextElement.java

示例12: mergeElementsWithSkippingRules

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
@Test
public void mergeElementsWithSkippingRules() {
	
	List<TextElement> elements = new ArrayList<>();
	elements.add(new TextElement(0f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f, 6f));
	elements.add(new TextElement(0f, 17f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f, 6f));
	elements.add(new TextElement(0f, 25f, 10f, 20f, PDType1Font.HELVETICA, 1f, "B", 1f, 6f));
	elements.add(new TextElement(0.001f, 25f, 10f, 20f, PDType1Font.HELVETICA, 1f, " ", 1f, 6f));
	elements.add(new TextElement(0f, 35f, 10f, 20f, PDType1Font.HELVETICA, 1f, "C", 1f, 6f));
	elements.add(new TextElement(0f, 45f, 10f, 20f, PDType1Font.TIMES_ROMAN, 10f, "D", 1f, 6f));
	
	List<TextChunk> words = TextElement.mergeWords(elements);
	
	List<TextChunk> expectedWords = new ArrayList<>();
	TextChunk textChunk = new TextChunk(new TextElement(0f, 15f, 10f, 20f, PDType1Font.HELVETICA, 1f, "A", 1f, 6f));
	textChunk.add(new TextElement(0f, 25f, 10f, 20f, PDType1Font.HELVETICA, 1f, "B", 1f, 6f));
	textChunk.add(new TextElement(0f, 35f, 10f, 20f, PDType1Font.HELVETICA, 1f, "C", 1f, 6f));
	textChunk.add(new TextElement(0f, 45f, 10f, 20f, PDType1Font.TIMES_ROMAN, 10f, "D", 1f, 6f));
	expectedWords.add(textChunk);
	
	Assert.assertEquals(expectedWords, words);
	
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:24,代碼來源:TestTextElement.java

示例13: build

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
public byte[] build() throws IOException {
    this.acroForm.setNeedAppearances(false);

    // Fix annotations
    for (PDPage page : this.pdfDocument.getPages()) {
        for (PDAnnotation annot : page.getAnnotations()) {
            annot.setPage(page);
        }
    }

    // Define font resources names used in PDF template
    final PDResources dr = new PDResources();
    dr.put(COSName.getPDFName("Helv"), PDType1Font.HELVETICA);
    dr.put(COSName.getPDFName("HeBo"), PDType1Font.HELVETICA_BOLD);
    this.acroForm.setDefaultResources(dr);

    // Convert form fields to text
    this.acroForm.flatten();

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    pdfDocument.save(bos);
    pdfDocument.close();
    return bos.toByteArray();
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:25,代碼來源:HunterPaymentPdfFeature.java

示例14: drawSectionHeader

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
private void drawSectionHeader(String title, float cardXCoordinate, float cardYCoordinate, PDPage page, PDPageContentStream contentStream) throws IOException {
    // Set background color
    Color color = new Color(73, 89, 105);
    float colorBoxWidth = page.getMediaBox().getWidth() - 2 * PdfBoxStyle.LEFT_RIGHT_MARGINS_OF_LETTER;
    float colorBoxHeight = PdfBoxStyle.DEFAULT_TABLE_ROW_HEIGHT;
    PDFont titleFont = PDType1Font.TIMES_BOLD;
    float titleFontSize = PdfBoxStyle.TEXT_MEDIUM_SIZE;
    Color titleColor = Color.WHITE;

    pdfBoxService.addColorBox(color, cardXCoordinate, cardYCoordinate, colorBoxWidth, colorBoxHeight, page, contentStream);

    float titleYCoordinate = cardYCoordinate + (colorBoxHeight / 2)
            - ((titleFont.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * titleFontSize) / 4);

    pdfBoxService.addTextAtOffset(title, titleFont, titleFontSize, titleColor, cardXCoordinate + 4f, titleYCoordinate, contentStream);
}
 
開發者ID:bhits,項目名稱:pcm-api,代碼行數:17,代碼來源:ConsentPdfGeneratorImpl.java

示例15: writeInputFieldToPDFPage

import org.apache.pdfbox.pdmodel.font.PDType1Font; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/43604973/creating-a-checkbox-and-printing-it-to-pdf-file-is-not-working-using-pdfbox-1-8">
 * Creating a checkbox and printing it to pdf file is not working using pdfbox 1.8.9 api
 * </a>
 * <p>
 * The OP's method for checkbox creation.
 * </p>
 * @see #testCheckboxLikeSureshGoud()
 */
public static void writeInputFieldToPDFPage( PDPage pdPage, PDDocument document, Float x, Float y, Boolean ticked) throws IOException {
    PDFont font = PDType1Font.HELVETICA;
    PDResources res = new PDResources();
    String fontName = res.addFont(font);
    String da = ticked?"/" + fontName + " 10 Tf 0 0.4 0 rg":"";

    COSDictionary acroFormDict = new COSDictionary();
    acroFormDict.setBoolean(COSName.getPDFName("NeedAppearances"), true);
    acroFormDict.setItem(COSName.FIELDS, new COSArray());
    acroFormDict.setItem(COSName.DA, new COSString(da));

    PDAcroForm acroForm =  new PDAcroForm(document, acroFormDict);
    acroForm.setDefaultResources(res);
    document.getDocumentCatalog().setAcroForm(acroForm);

    PDGamma colourBlack = new PDGamma();
    PDAppearanceCharacteristicsDictionary fieldAppearance =
        new PDAppearanceCharacteristicsDictionary(new COSDictionary());
    fieldAppearance.setBorderColour(colourBlack);
    if(ticked) {
        COSArray arr = new COSArray();
        arr.add(new COSFloat(0.89f));
        arr.add(new COSFloat(0.937f));
        arr.add(new COSFloat(1f));
        fieldAppearance.setBackground(new PDGamma(arr));
    }

    COSDictionary cosDict = new COSDictionary();
    COSArray rect = new COSArray();

    rect.add(new COSFloat(x));
    rect.add(new COSFloat(new Float(y-5)));
    rect.add(new COSFloat(new Float(x+10)));
    rect.add(new COSFloat(new Float(y+5)));

    cosDict.setItem(COSName.RECT, rect);
    cosDict.setItem(COSName.FT, COSName.getPDFName("Btn")); // Field Type
    cosDict.setItem(COSName.TYPE, COSName.ANNOT);
    cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget"));
    if(ticked) {
        cosDict.setItem(COSName.TU, new COSString("Checkbox with PDFBox"));
    }
    cosDict.setItem(COSName.T, new COSString("Chk"));
    //Tick mark color and size of the mark
    cosDict.setItem(COSName.DA, new COSString(ticked?"/F0 10 Tf 0 0.4 0 rg":"/FF 1 Tf 0 0 g"));
    cosDict.setInt(COSName.F, 4);

    PDCheckbox checkbox = new PDCheckbox(acroForm, cosDict);
    checkbox.setFieldFlags(PDCheckbox.FLAG_READ_ONLY);
    checkbox.setValue("Yes");

    checkbox.getWidget().setAppearanceCharacteristics(fieldAppearance);

    pdPage.getAnnotations().add(checkbox.getWidget());
    acroForm.getFields().add(checkbox);
}
 
開發者ID:mkl-public,項目名稱:testarea-pdfbox1,代碼行數:66,代碼來源:CreateCheckbox.java


注:本文中的org.apache.pdfbox.pdmodel.font.PDType1Font類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。