本文整理汇总了Java中org.apache.pdfbox.pdmodel.font.PDType0Font.load方法的典型用法代码示例。如果您正苦于以下问题:Java PDType0Font.load方法的具体用法?Java PDType0Font.load怎么用?Java PDType0Font.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.font.PDType0Font
的用法示例。
在下文中一共展示了PDType0Font.load方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PagerController
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
public PagerController(float marginLeft, float marginRight, float marginTop, float marginBottom, Options options) throws IOException {
// set values defined by user
this.doc = new PDDocument();
this.marginLeft = marginLeft;
this.marginRight = marginRight;
this.marginTop = marginTop;
this.marginBottom = marginBottom;
this.options = options;
// initialize standard values.
// note that it should be possible to set a custom font at a later time.
this.font = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrime.ttf"));
this.boldFont = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrimeBold.ttf"));
this.italicFont = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrimeItalic.ttf"));
this.boldItalicFont = PDType0Font.load(doc, Fonts.class.getResourceAsStream("CourierPrimeBoldItalic.ttf"));
this.pagers = new HashMap<>();
}
示例2: loadPDFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
/**
* Load the {@link PDFont} associated to this preload font. This class uses no
* caching!
*
* @param aDoc
* The {@link PDDocument} to which the font should be attached to. May
* not be <code>null</code>.
* @return The loaded font.
* @throws IOException
* In case loading the external file fails
*/
@Nonnull
public PDFont loadPDFont (@Nonnull final PDDocument aDoc) throws IOException
{
if (m_aFont != null)
{
// Pre-defined font
return m_aFont;
}
PDFont ret = null;
if (m_aTTF != null)
ret = PDType0Font.load (aDoc, m_aTTF, m_bEmbed);
else
if (m_aOTF != null)
ret = PDType0Font.load (aDoc, m_aOTF, m_bEmbed);
if (ret == null)
throw new IllegalArgumentException ("Cannot load font resources of type " + m_aFontRes.getFontType ());
return ret;
}
示例3: main
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
public static void main (final String [] args) throws IOException
{
final String s = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. ";
final String file = "pdf/issue-3168.pdf";
try (final PDDocument doc = new PDDocument ())
{
final PDPage page = new PDPage (PDRectangle.A4);
doc.addPage (page);
final PDFont font = PDType0Font.load (doc,
EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
.getInputStream ());
try (final PDPageContentStream contents = new PDPageContentStream (doc, page))
{
contents.beginText ();
contents.setFont (font, 12);
contents.newLineAtOffset (100, 700);
contents.showText (s);
contents.endText ();
}
doc.save (file);
}
}
示例4: findFallbackFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
private PDFont findFallbackFont(IFontTextDrawerEnv env) throws IOException {
/*
* We search for the right font in the system folders... We try to use
* LucidaSansRegular and if not found Arial, because this fonts often exists. We
* use the Java default font as fallback.
*
* Normally this method is only used and called if a default font misses some
* special characters, e.g. Hebrew or Arabic characters.
*/
String javaHome = System.getProperty("java.home", ".");
String javaFontDir = javaHome + "/lib/fonts";
String windir = System.getenv("WINDIR");
if (windir == null)
windir = javaFontDir;
File[] paths = new File[] { new File(new File(windir), "fonts"), new File(System.getProperty("user.dir", ".")),
new File("/Library/Fonts"), new File("/usr/share/fonts/truetype"), new File(javaFontDir) };
File foundFontFile = null;
for (String fontFileName : new String[] { "LucidaSansRegular.ttf", "arial.ttf", "Arial.ttf" }) {
for (File path : paths) {
File arialFile = new File(path, fontFileName);
if (arialFile.exists()) {
foundFontFile = arialFile;
break;
}
}
if (foundFontFile != null)
break;
}
return PDType0Font.load(env.getDocument(), foundFontFile);
}
示例5: loadIconFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
private void loadIconFont() {
PDDocument pdDocument = document.getPDDocument();
try (InputStream inputStream = TitleBlockWriter.class.getClassLoader()
.getResourceAsStream(ICON_FONT_FILE)) {
iconFont = PDType0Font.load(pdDocument, inputStream);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, null, e);
}
}
示例6: loadFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
/**
* Loads BankGothic Md BT Medium.ttf in to a given document or falls back to Helvetica Bold
* @param document Open PDDocument (PDF)
* @return font
*/
static PDFont loadFont(PDDocument document) {
Path fontPath = Paths.get(badgeResourcePath, "/Bitstream - BankGothic Md BT Medium.ttf");
try (InputStream stream = new FileInputStream(fontPath.toFile())) {
return PDType0Font.load(document, stream);
} catch (IOException ex) {
log.warn("Error, couldn't load font '{}'", fontPath.toAbsolutePath());
return PDType1Font.HELVETICA_BOLD;
}
}
示例7: loadTTF
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
/**
* Tries to load a font from the system database.
* @param fontFamily
* @param isItalic
* @param isBold
* @return the font or {@code null} when not found
*/
private PDFont loadTTF(String fontFamily, boolean isItalic, boolean isBold)
{
PDFont font = null;
try {
URI uri = fontDB.findFontURI(fontFamily, isBold, isItalic);
if (uri != null)
font = PDType0Font.load(doc, new File(uri));
}
catch (IOException e) {
font = null;
}
return font;
}
示例8: main
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
public static void main (final String [] args) throws IOException
{
final String s = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. ";
final String file = "pdf/issue-3170.pdf";
final StringBuilder aSB = new StringBuilder ();
for (int i = 0; i < 300; i++)
aSB.append (s).append (' ');
final String message = aSB.toString ();
try (final PDDocument doc = new PDDocument ())
{
final PDPage page = new PDPage (PDRectangle.A4);
doc.addPage (page);
final PDFont font = PDType0Font.load (doc,
EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
.getInputStream ());
try (final PDPageContentStream contents = new PDPageContentStream (doc, page))
{
contents.beginText ();
contents.setFont (font, 12);
contents.newLineAtOffset (100, 700);
contents.showText (message);
contents.endText ();
}
doc.save (file);
}
}
示例9: getFont
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
public static PDFont getFont(PDDocument doc, URL fontURL) throws IOException {
PDFont font = PDType0Font.load(doc, fontURL.openStream());
return font;
}
示例10: draw
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
public static <T> void draw(VennFigure<T> vennFigure, PDDocument doc) throws IOException {
// based on https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java?revision=1703059&view=markup
PDFont font = PDType0Font.load(doc, VennDrawPDF.class.getResourceAsStream("../fx/mplus-1p-regular.ttf"));
Rectangle2D drawRect = vennFigure.drawRect(str ->
stringBoundingBox(font, str, FONT_SIZE)
);
PDRectangle pageSize = new PDRectangle((float)drawRect.getWidth() + MARGIN*2, (float)drawRect.getHeight() + MARGIN*2);
PDPage page = new PDPage(pageSize);
doc.addPage(page);
VennDrawPDF.draw(vennFigure, doc, page, font, pageSize);
// PDF/A1b support
/*
// add XMP metadata
XMPMetadata xmp = XMPMetadata.createXMPMetadata();
try
{
DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
dc.setTitle("Venn Diagram");
dc.setSource("VennDraw "+ VersionResolver.getVersion());
dc.setDescription("Venn Diagram");
PDFAIdentificationSchema id = xmp.createAndAddPFAIdentificationSchema();
id.setPart(1);
id.setConformance("B");
XmpSerializer serializer = new XmpSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(xmp, baos, true);
PDMetadata metadata = new PDMetadata(doc);
metadata.importXMPMetadata(baos.toByteArray());
doc.getDocumentCatalog().setMetadata(metadata);
} catch(BadFieldValueException|TransformerException e) {
throw new RuntimeException(e);
}
// sRGB output intent
InputStream colorProfile = VennDrawPDF.class.getResourceAsStream(
"sRGB Color Space Profile.icm");
PDOutputIntent intent = new PDOutputIntent(doc, colorProfile);
intent.setInfo("sRGB IEC61966-2.1");
intent.setOutputCondition("sRGB IEC61966-2.1");
intent.setOutputConditionIdentifier("sRGB IEC61966-2.1");
intent.setRegistryName("http://www.color.org");
doc.getDocumentCatalog().addOutputIntent(intent);
*/
}
示例11: main
import org.apache.pdfbox.pdmodel.font.PDType0Font; //导入方法依赖的package包/类
public static void main (final String [] args) throws IOException
{
final String s = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. ";
final String file = "pdf/benchmark-type0.pdf";
final StringBuilder aSB = new StringBuilder ();
for (int i = 0; i < 300; i++)
aSB.append (s).append (' ');
final String message = aSB.toString ();
final long nStart = System.currentTimeMillis ();
try (final PDDocument doc = new PDDocument ())
{
final PDPage page = new PDPage ();
doc.addPage (page);
final PDFont font = PDType0Font.load (doc,
EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
.getInputStream ());
System.out.println ("Finished loading font at " + (System.currentTimeMillis () - nStart) + "ms");
for (int i = 0; i < 100; ++i)
font.getStringWidth (message);
System.out.println ("Finished string width (" +
message.length () +
" chars) after " +
(System.currentTimeMillis () - nStart) +
"ms");
try (final PDPageContentStream contents = new PDPageContentStream (doc, page))
{
contents.beginText ();
contents.setFont (font, 12);
contents.newLineAtOffset (100, 700);
contents.showText (message);
contents.endText ();
}
doc.save (file);
}
System.out.println (file + " created! Took " + (System.currentTimeMillis () - nStart) + "ms");
}