当前位置: 首页>>代码示例>>Java>>正文


Java PDPageContentStream.moveTextPositionByAmount方法代码示例

本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPageContentStream.moveTextPositionByAmount方法的典型用法代码示例。如果您正苦于以下问题:Java PDPageContentStream.moveTextPositionByAmount方法的具体用法?Java PDPageContentStream.moveTextPositionByAmount怎么用?Java PDPageContentStream.moveTextPositionByAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.pdfbox.pdmodel.PDPageContentStream的用法示例。


在下文中一共展示了PDPageContentStream.moveTextPositionByAmount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generatePage

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private PDPage generatePage(String[] lines, int startAt, PDDocument document) throws IOException {
    PDPage page = new PDPage(new PDRectangle(612f, 396f));
    PDPageContentStream contentStream = new PDPageContentStream(document, page);

    // Positions are measured from the bottom left corner of the page at 72 DPI

    // Add report text to page
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(36+xOffset, 360+yOffset);
    contentStream.setFont(font, fontSize);
    int lineNumber = startAt;
    while (lineNumber < startAt + linesPerPage && lineNumber < lines.length) {
        contentStream.drawString(lines[lineNumber]);
        contentStream.moveTextPositionByAmount(0, (-1*fontSize));
        lineNumber += 1;
    }
    contentStream.endText();

    contentStream.close();

    return page;

}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:24,代码来源:ReportPrintFormatter.java

示例2: printPDFFile

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的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

示例3: drawAgeColorStripe

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void drawAgeColorStripe(PDPageContentStream contentStream, PDFont font, Attendee attendee) throws IOException {
    // Draw age color stripe
    String stripeText = "VOID";
    if (attendee.getCurrentAgeRange() != null) {
        contentStream.setNonStrokingColor(Color.decode(attendee.getCurrentAgeRange().getStripeColor()));
        stripeText = attendee.getCurrentAgeRange().getStripeText();
    } else {
        contentStream.setNonStrokingColor(Color.black);
    }
    contentStream.fillRect(155, 92, 300, 45);

    contentStream.setLineWidth(0.5f);

    // Draw age range text in color stripe
    contentStream.beginText();
    contentStream.setFont(font, 32);
    contentStream.setNonStrokingColor(Color.white);
    contentStream.setStrokingColor(Color.black);
    contentStream.moveTextPositionByAmount(438, 105);
    contentStream.appendRawCommands("2 Tr ");       // Set text rendering mode
    Float ageRangeWidth = ((font.getStringWidth(stripeText) / 1000.0f) * 32);
    contentStream.moveTextPositionByAmount(-ageRangeWidth, 0);
    contentStream.drawString(stripeText);
    contentStream.endText();
}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:26,代码来源:FullBadgePrintFormatter.java

示例4: drawStringWithResizing

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
 * Draws the given string, optionally supports scaling to fit.
 * @param x Left side of text, or center point of text if centered (1/72 inch)
 * @param y Bottom of text, in points (1/72 inch)
 * @param text Text to draw
 * @param optOrig Resize Options
 * @throws IOException Error generating PDF
 */
void drawStringWithResizing(PDPageContentStream stream, float x, float y, String text, ResizeOptions optOrig) throws IOException {
    ResizeOptions opt = new ResizeOptions(optOrig);
    float textSize = opt.font.getStringWidth(text); // in thousandths of font pt size.
    float size = opt.size;

    // If text size is greater than maximum width, recalculate the correct font size, based on our restrictions
    if (textSize * (size/1000.0f) > opt.maxTextWidth) {
        size = opt.maxTextWidth * 1000.0f / textSize;
        if (size < opt.minFontSize) {
            // We have utterly failed to fit the text with the minimum font size,
            // So we're forced to use that.
            size = opt.minFontSize;
        }
    }

    if (opt.centered) {
        x -= textSize * (size/(2*1000.0f));
    }

    // Actually draw the text
    stream.beginText();
    stream.setStrokingColor(Color.black);
    stream.setNonStrokingColor(Color.black);
    stream.moveTextPositionByAmount(x, y);
    stream.setFont(opt.font, size);
    stream.drawString(text);
    stream.endText();
}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:37,代码来源:FormatterBase.java

示例5: drawStringWithResizing

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
 * Draws the given string, optionally supports scaling to fit.
 * @param contentStream Open stream to draw in to
 * @param x Left side of text, or center point of text if centered (1/72 inch)
 * @param y Bottom of text, in points (1/72 inch)
 * @param text Text to draw
 * @param optOrig Resize Options
 * @throws IOException Error generating PDF
 */
private void drawStringWithResizing(PDPageContentStream contentStream, float x, float y, String text, ResizeOptions optOrig) throws IOException {
    ResizeOptions opt = new ResizeOptions(optOrig);
    float textSize = opt.font.getStringWidth(text); // in thousandths of font pt size.
    float size = opt.size;

    // If text size is greater than maximum width, recalculate the correct font size, based on our restrictions
    if (textSize * (size/1000.0f) > opt.maxTextWidth) {
        size = opt.maxTextWidth * 1000.0f / textSize;
        if (size < opt.minFontSize) {
            // We have utterly failed to fit the text with the minimum font size,
            // So we're forced to use that.
            size = opt.minFontSize;
        }
    }

    if (opt.centered) {
        x -= textSize * (size/(2*1000.0f));
    }

    // Actually draw the text
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(x, y);
    contentStream.setFont(opt.font, size);
    contentStream.drawString(text);
    contentStream.endText();
}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:36,代码来源:FullBadgePrintFormatter.java

示例6: drawBadgeType

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void drawBadgeType(PDPageContentStream contentStream, Attendee attendee) throws IOException {
    // Draw badge type in color stripe
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(167, 105);
    contentStream.drawString(attendee.getBadge().getBadgeTypeText());
    contentStream.endText();
}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:8,代码来源:FullBadgePrintFormatter.java

示例7: generatePage

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private PDPage generatePage(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

    // Draw real name
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(220+xOffset, 175+yOffset);
    contentStream.setFont( font, 24 );
    contentStream.drawString(attendee.getFirstName() + " " + attendee.getLastName());
    contentStream.endText();

    // Draw age color stripe
    String stripeText = "VOID";
    if (attendee.getCurrentAgeRange() != null) {
        contentStream.setNonStrokingColor(Color.decode(attendee.getCurrentAgeRange().getStripeColor()));
        stripeText = attendee.getCurrentAgeRange().getStripeText();
    } else {
        contentStream.setNonStrokingColor(Color.black);
    }
    contentStream.fillRect(150+xOffset, 90+yOffset, 310, 44);

    contentStream.setLineWidth(0.5f);
    contentStream.beginText();
    contentStream.setFont(font, 24);
    contentStream.setNonStrokingColor(Color.white);
    contentStream.setStrokingColor(Color.black);
    contentStream.moveTextPositionByAmount(297+xOffset, 102+yOffset);
    contentStream.appendRawCommands("2 Tr ");       // Set text rendering mode

    Float ageRangeWidth = ((font.getStringWidth(stripeText) / 1000.0f) * 18) / 2;
    contentStream.moveTextPositionByAmount(-ageRangeWidth, 0);
    contentStream.drawString(stripeText);
    contentStream.endText();

    contentStream.close();

    return page;
}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:42,代码来源:LiteBadgePrintFormatter.java


注:本文中的org.apache.pdfbox.pdmodel.PDPageContentStream.moveTextPositionByAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。