本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPageContentStream.setLineWidth方法的典型用法代码示例。如果您正苦于以下问题:Java PDPageContentStream.setLineWidth方法的具体用法?Java PDPageContentStream.setLineWidth怎么用?Java PDPageContentStream.setLineWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.PDPageContentStream
的用法示例。
在下文中一共展示了PDPageContentStream.setLineWidth方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: drawBadgeNumber
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void drawBadgeNumber(PDPage page, PDFont font, Attendee attendee) throws IOException {
String badgeNumber = attendee.getBadgeNumber();
if (badgeNumber == null) {
return; // no text, don't draw anything
}
List<String> badgeNumberParts = BadgeLib.splitBadgeNumber(badgeNumber);
PDPageContentStream stream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, false);
String stripeColor = attendee.getCurrentAgeRange().getStripeColor();
stream.setNonStrokingColor(BadgeLib.getForegroundColor(stripeColor));
// Bounding box:
// stream.fillRect(163, 95, 40, 30);
PDRectangle boundingBox = new PDRectangle(163, 95, 40, 30);
stream.setLineWidth(0.25f);
stream.beginText();
int fontSize = BadgeLib.findMaxFontSize(font, badgeNumberParts,boundingBox);
stream.setFont(font, fontSize);
float textWidth = font.getStringWidth(badgeNumberParts.get(0));
Float offset = textWidth * (fontSize/(2*1000.0f));
stream.newLineAtOffset(185-offset, 105+fontSize); // First character position
stream.showText(badgeNumberParts.get(0));
if (badgeNumberParts.size() > 1) {
textWidth = font.getStringWidth(badgeNumberParts.get(1));
Float newOffset = textWidth * (fontSize/(2*1000.0f));
stream.newLineAtOffset(offset-newOffset, -1*fontSize); // First character position
stream.showText(badgeNumberParts.get(1));
}
stream.close();
}
示例3: drawBadgeTypeText
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void drawBadgeTypeText(PDPage page, PDFont font, Attendee attendee) throws IOException {
if (attendee.getBadge() == null || attendee.getBadge().getBadgeTypeText() == null) {
return; // no text, don't draw anything
}
String badgeTypeText = attendee.getBadge().getBadgeTypeText();
PDPageContentStream stream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, false);
// PDRectangle boundingBox = new PDRectangle(206, 85, 253, 44);
stream.setLineWidth(0.5f);
stream.beginText();
int fontSize = BadgeLib.findMaxLineSize(font, badgeTypeText,240, 40);
stream.setFont(font, fontSize);
if (attendee.getBadge() != null &&
(attendee.getBadge().getBadgeTypeText().equals("Friday") ||
attendee.getBadge().getBadgeTypeText().equals("Saturday") ||
attendee.getBadge().getBadgeTypeText().equals("Sunday"))) {
if (attendee.getBadge() != null && attendee.getBadge().getBadgeTypeBackgroundColor() != null) {
stream.setNonStrokingColor(BadgeLib.getForegroundColor(attendee.getCurrentAgeRange().getStripeColor()));
} else {
stream.setNonStrokingColor(Color.WHITE);
stream.setStrokingColor(Color.black);
}
} else {
if (attendee.getBadge() != null && attendee.getBadge().getBadgeTypeBackgroundColor() != null) {
stream.setNonStrokingColor(BadgeLib.getForegroundColor(attendee.getBadge().getBadgeTypeBackgroundColor()));
} else {
stream.setNonStrokingColor(Color.WHITE);
stream.setStrokingColor(Color.black);
}
}
float textWidth = font.getStringWidth(badgeTypeText);
Float offset = textWidth * (fontSize/(2*1000.0f));
stream.newLineAtOffset(330-offset, 100); // First character position
stream.showText(badgeTypeText);
stream.close();
}
示例4: addTextSimpleUnderlined
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
public static void addTextSimpleUnderlined(PDPageContentStream stream, PdfTextStyle textConfig, float textX, float textY, String text) {
addTextSimple(stream, textConfig, textX, textY, text);
try {
float lineOffset = textConfig.getFontSize() / 8F;
stream.setStrokingColor(textConfig.getColor());
stream.setLineWidth(0.5F);
stream.moveTo(textX, textY - lineOffset);
stream.lineTo(textX + getTextWidth(textConfig.getCurrentFontStyle(), textConfig.getFontSize(), text), textY - lineOffset);
stream.stroke();
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: testAddEmptySignatureField
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/37601092/pdfbox-identify-specific-pages-and-functionalities-recommendations">
* PDFBox identify specific pages and functionalities recommendations
* </a>
*
* <p>
* This test shows how to add an empty signature field with a custom appearance
* to an existing PDF.
* </p>
*/
@Test
public void testAddEmptySignatureField() throws IOException
{
try ( InputStream sourceStream = getClass().getResourceAsStream("test.pdf");
OutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "test-with-empty-sig-field.pdf")))
{
PDFont font = PDType1Font.HELVETICA;
PDResources resources = new PDResources();
resources.put(COSName.getPDFName("Helv"), font);
PDDocument document = PDDocument.load(sourceStream);
PDAcroForm acroForm = new PDAcroForm(document);
acroForm.setDefaultResources(resources);
document.getDocumentCatalog().setAcroForm(acroForm);
PDRectangle rect = new PDRectangle(50, 750, 200, 50);
PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
PDAppearanceStream appearanceStream = new PDAppearanceStream(document);
appearanceStream.setBBox(rect.createRetranslatedRectangle());
appearanceStream.setResources(resources);
appearanceDictionary.setNormalAppearance(appearanceStream);
PDPageContentStream contentStream = new PDPageContentStream(document, appearanceStream);
contentStream.setStrokingColor(Color.BLACK);
contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
contentStream.setLineWidth(2);
contentStream.addRect(0, 0, rect.getWidth(), rect.getHeight());
contentStream.fill();
contentStream.moveTo(1 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
contentStream.lineTo(2 * rect.getHeight() / 4, 3 * rect.getHeight() / 4);
contentStream.moveTo(1 * rect.getHeight() / 4, 3 * rect.getHeight() / 4);
contentStream.lineTo(2 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
contentStream.moveTo(3 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
contentStream.lineTo(rect.getWidth() - rect.getHeight() / 4, 1 * rect.getHeight() / 4);
contentStream.stroke();
contentStream.setNonStrokingColor(Color.DARK_GRAY);
contentStream.beginText();
contentStream.setFont(font, rect.getHeight() / 5);
contentStream.newLineAtOffset(3 * rect.getHeight() / 4, -font.getBoundingBox().getLowerLeftY() * rect.getHeight() / 5000);
contentStream.showText("Customer");
contentStream.endText();
contentStream.close();
PDSignatureField signatureField = new PDSignatureField(acroForm);
signatureField.setPartialName("SignatureField");
PDPage page = document.getPage(0);
PDAnnotationWidget widget = signatureField.getWidgets().get(0);
widget.setAppearance(appearanceDictionary);
widget.setRectangle(rect);
widget.setPage(page);
page.getAnnotations().add(widget);
acroForm.getFields().add(signatureField);
document.save(output);
document.close();
}
}
示例6: drawBorder
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
* Renders the borders
*
* @param stream
* The stream used to render the borders
* @param left
* The coordinate of the left edge of the object
* @param top
* The coordinate of the top edge of the object
* @param width
* The width the object will be rendered
* @param height
* The height the object will be rendered
* @throws IOException
* If writing to the stream fails
*/
protected void drawBorder(final PDPageContentStream stream, final float left, final float top, final float width, final float height) throws IOException {
stream.moveTo(left, top);
float lineWidth = -1;
if (topBorder > 0) {
stream.setLineWidth(topBorder);
lineWidth = topBorder;
stream.lineTo(left + width, top);
} else {
stream.moveTo(left + width, top);
}
if (rightBorder > 0) {
if (lineWidth != rightBorder) {
stream.setLineWidth(rightBorder);
}
lineWidth = rightBorder;
stream.lineTo(left + width, top - height);
} else {
stream.moveTo(left + width, top - height);
}
if (bottomBorder > 0) {
if (lineWidth != bottomBorder) {
stream.setLineWidth(bottomBorder);
}
lineWidth = bottomBorder;
stream.lineTo(left, top - height);
} else {
stream.moveTo(left, top - height);
}
if (leftBorder > 0) {
if (lineWidth != leftBorder) {
stream.setLineWidth(leftBorder);
}
lineWidth = leftBorder;
stream.setLineWidth(leftBorder);
stream.lineTo(left, top);
} else {
stream.moveTo(left, top);
}
if (topBorder > 0) {
if (lineWidth != topBorder) {
stream.setLineWidth(topBorder);
}
lineWidth = topBorder;
stream.setLineWidth(topBorder);
stream.lineTo(left + width, top);
}
stream.stroke();
}
示例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;
}
示例8: drawVerticalAgeRangeText
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void drawVerticalAgeRangeText(PDPage page, PDFont font, Attendee attendee) throws IOException {
PDPageContentStream stream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, false);
stream.setLineWidth(0.5f);
stream.beginText();
stream.setFont(font, 30);
String stripeColor = attendee.getCurrentAgeRange().getStripeColor();
stream.setNonStrokingColor(BadgeLib.getForegroundColor(stripeColor));
stream.newLineAtOffset(172, 275); // First character position
String ageString = BadgeLib.getAgeRangeAtCon(attendee, currentDateForAgeCalculation);
if (ageString.toLowerCase().equals("adult")) {
stream.showText("A");
stream.newLineAtOffset(-1, -32);
stream.showText("D");
stream.newLineAtOffset(0, -32);
stream.showText("U");
stream.newLineAtOffset(2, -32);
stream.showText("L");
stream.newLineAtOffset(2, -32);
stream.showText("T");
} else if (ageString.toLowerCase().equals("youth")) {
stream.showText("Y");
stream.newLineAtOffset(-2, -32);
stream.showText("O");
stream.newLineAtOffset(0, -32);
stream.showText("U");
stream.newLineAtOffset(4, -32);
stream.showText("T");
stream.newLineAtOffset(-3, -32);
stream.showText("H");
} else if (ageString.toLowerCase().equals("child")) {
stream.showText("C");
stream.newLineAtOffset(0, -32);
stream.showText("H");
stream.newLineAtOffset(5, -32);
stream.showText("I");
stream.newLineAtOffset(-3, -32);
stream.showText("L");
stream.newLineAtOffset(-2, -32);
stream.showText("D");
} else {
stream.showText("V");
stream.newLineAtOffset(0, -32);
stream.showText("O");
stream.newLineAtOffset(5, -32);
stream.showText("I");
stream.newLineAtOffset(-5, -32);
stream.showText("D");
}
stream.close();
}
示例9: placeBorders
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void placeBorders(PDPageContentStream stream, float startY, float endY, float x, float allowedWidth) throws IOException {
if (border) {
stream.setStrokingColor(0, 0, 0);
stream.setLineWidth(0.3f);
float y0 = startY - BORDER_Y_DELTA;
float y1 = endY - (BORDER_Y_DELTA + 1);
if (!noInnerBorders) {
if (!noTopBorder || noTopBorder && !placeFirstBorder) {
stream.moveTo(x, y0);
stream.lineTo(x + allowedWidth, y0);
stream.stroke();
}
if (!noBottomBorder || noBottomBorder && !placeLastBorder) {
stream.moveTo(x, y1);
stream.lineTo(x + allowedWidth, y1);
stream.stroke();
}
} else {
if (!noTopBorder && placeFirstBorder) {
stream.moveTo(x, y0);
stream.lineTo(x + allowedWidth, y0);
stream.stroke();
}
if (!noBottomBorder && placeLastBorder) {
stream.moveTo(x, y1);
stream.lineTo(x + allowedWidth, y1);
stream.stroke();
}
}
float currX = x;
stream.moveTo(currX, y0);
stream.lineTo(currX, y1);
stream.stroke();
for (float width : cellWidths) {
if (!noInnerBorders) {
stream.moveTo(currX, y0);
stream.lineTo(currX, y1);
stream.stroke();
}
currX += width * allowedWidth;
}
stream.moveTo(currX, y0);
stream.lineTo(currX, y1);
stream.stroke();
}
}
示例10: drawLine
import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
* Helper method to draw a fine line
*
* @param stream
* The stream used to draw the line
* @param left
* The left end of the line
* @param top
* The vertical position of the line
* @param width
* The width of the line
* @throws IOException
* If writing to the stream fails
*/
private void drawLine(final PDPageContentStream stream, final float left, final float top, final float width) throws IOException {
stream.setLineWidth(0.25f);
stream.moveTo(left, top);
stream.lineTo(left + width, top);
stream.stroke();
}