本文整理匯總了Java中com.itextpdf.text.pdf.BaseFont.getWidthPoint方法的典型用法代碼示例。如果您正苦於以下問題:Java BaseFont.getWidthPoint方法的具體用法?Java BaseFont.getWidthPoint怎麽用?Java BaseFont.getWidthPoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.BaseFont
的用法示例。
在下文中一共展示了BaseFont.getWidthPoint方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCreateLinkWithAppearance
import com.itextpdf.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/34734669/define-background-color-and-transparency-of-link-annotation-in-pdf">
* Define background color and transparency of link annotation in PDF
* </a>
* <p>
* This test creates a link annotation with custom appearance. Adobe Reader chooses
* to ignore it but other viewers use it. Interestingly Adobe Acrobat export-as-image
* does use the custom appearance...
* </p>
*/
@Test
public void testCreateLinkWithAppearance() throws IOException, DocumentException
{
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "custom-link.appearance.pdf")));
writer.setCompressionLevel(0);
doc.open();
BaseFont baseFont = BaseFont.createFont();
int fontSize = 15;
doc.add(new Paragraph("Hello", new Font(baseFont, fontSize)));
PdfContentByte content = writer.getDirectContent();
String text = "Test";
content.setFontAndSize(baseFont, fontSize);
content.beginText();
content.moveText(100, 500);
content.showText(text);
content.endText();
Rectangle linkLocation = new Rectangle(95, 495 + baseFont.getDescentPoint(text, fontSize),
105 + baseFont.getWidthPoint(text, fontSize), 505 + baseFont.getAscentPoint(text, fontSize));
PdfAnnotation linkGreen = PdfAnnotation.createLink(writer, linkLocation, PdfName.HIGHLIGHT, "green" );
PdfTemplate appearance = PdfTemplate.createTemplate(writer, linkLocation.getWidth(), linkLocation.getHeight());
PdfGState state = new PdfGState();
//state.FillOpacity = .3f;
// IMPROVEMENT: Use blend mode Darken instead of transparency; you may also want to try Multiply.
state.setBlendMode(new PdfName("Darken"));
appearance.setGState(state);
appearance.setColorFill(BaseColor.GREEN);
appearance.rectangle(0, 0, linkLocation.getWidth(), linkLocation.getHeight());
appearance.fill();
linkGreen.setAppearance(PdfName.N, appearance);
writer.addAnnotation(linkGreen);
doc.open();
doc.close();
}
示例2: cellLayout
import com.itextpdf.text.pdf.BaseFont; //導入方法依賴的package包/類
public void cellLayout(final PdfPCell cell,
final Rectangle position,
final PdfContentByte[] canvases) {
try {
final BaseFont bf = font.getCalculatedBaseFont(false);
float availableWidth = position.getWidth();
float contentWidth = bf.getWidthPoint(content, font.getSize());
final String newContent;
if (contentWidth > availableWidth) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Need to truncate '"
+ content
+ "'");
}
final int contentLength = content.length();
int leftChar = 0;
availableWidth -= bf.getWidthPoint("...", font.getSize());
while (leftChar < contentLength) {
availableWidth -= bf.getWidthPoint(content.charAt(leftChar), font.getSize());
if (availableWidth > 0) {
leftChar++;
} else {
break;
}
}
newContent = content.substring(0, leftChar)
+ "...";
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Not truncating '"
+ content
+ "'");
}
newContent = content;
}
final PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS];
final ColumnText ct = new ColumnText(canvas);
ct.setSimpleColumn(position);
ct.addElement(new Paragraph(newContent, font));
ct.go();
} catch (final DocumentException e) {
throw new ExceptionConverter(e);
}
}