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


Java BaseFont类代码示例

本文整理汇总了Java中com.lowagie.text.pdf.BaseFont的典型用法代码示例。如果您正苦于以下问题:Java BaseFont类的具体用法?Java BaseFont怎么用?Java BaseFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createContent

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
	Document pdfDoc = di.getPdfDocument();
	try {
		pdfDoc.add(new Paragraph("Hello World!"));
		try {
			BaseFont bf = BaseFont.createFont("STSong-Light",
					"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font FontChinese = new Font(bf, 12, Font.NORMAL);
			String info=wi.getParameter("info");
			Paragraph p0 = new Paragraph(info, FontChinese);
			pdfDoc.add(p0);
			Paragraph p1 = new Paragraph("Beetle Web Framework 页面生成PDF文件演示!", FontChinese);
			pdfDoc.add(p1);
		} catch (Exception ex1) {
			throw new ControllerException(ex1);
		}
	} catch (DocumentException ex) {
		throw new ControllerException(ex);
	}
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:21,代码来源:GenPdfController.java

示例2: generatePdf

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
@Override
@Nullable
public byte[] generatePdf(@NonNull final String _html) {
    try {
        final ITextRenderer renderer = new ITextRenderer();
        final ITextFontResolver fontResolver = renderer.getFontResolver();

        final ClassPathResource regular = new ClassPathResource("fonts/LiberationSerif-Regular.ttf");
        fontResolver.addFont(regular.getURL().toString(), BaseFont.IDENTITY_H, true);

        renderer.setDocumentFromString(_html);
        renderer.layout();

        @Cleanup final ByteArrayOutputStream os = new ByteArrayOutputStream();
        renderer.createPDF(os);

        return os.toByteArray();
    } catch(Exception _e) {
        log.error("Failed to generate PDF", _e);
        return null;
    }
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:23,代码来源:ReportGeneratorServiceImpl.java

示例3: setPageNumbers

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
private void setPageNumbers() throws DocumentException, IOException {		
	
	int pages = getReader().getNumberOfPages();
	int i = 0;	
	PdfContentByte overContent;
	Rectangle pageSize = null;
	BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);

	while (i < pages) {
		i++;
		overContent = getStamper().getOverContent(i);
		pageSize = overContent.getPdfDocument().getPageSize();
		overContent.beginText();
		overContent.setFontAndSize(font, 9);
		overContent.setTextMatrix(pageSize.getWidth() - 50, pageSize.getHeight() - 70);
		overContent.showText("Page " + i + " of " + pages);
		overContent.endText();
	}
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:20,代码来源:PDFController.java

示例4: getResourceHyphenationTree

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
 * @param key
 * @return a hyphenation tree
 */
public static HyphenationTree getResourceHyphenationTree(String key) {
    try {
        InputStream stream = BaseFont.getResourceStream(defaultHyphLocation + key + ".xml");
        if (stream == null && key.length() > 2) {
            stream = BaseFont.getResourceStream(defaultHyphLocation + key.substring(0, 2) + ".xml");
        }
        if (stream == null) {
            return null;
        }
        HyphenationTree hTree = new HyphenationTree();
        hTree.loadSimplePatterns(stream);
        return hTree;
    }
    catch (Exception e) {
        return null;
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:22,代码来源:Hyphenator.java

示例5: main

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
 * Using a True Type Font.
 */
@Test
public void main() throws Exception {


	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file
	PdfWriter.getInstance(document,PdfTestBase.getOutputStream("truetype.pdf"));

	// step 3: we open the document
	document.open();

	String f = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf/LiberationMono-Regular.ttf").getAbsolutePath();
	// step 4: we add content to the document
	BaseFont bfComic = BaseFont.createFont(f, BaseFont.CP1252,	BaseFont.NOT_EMBEDDED);
	Font font = new Font(bfComic, 12);
	String text1 = "This is the quite popular Liberation Mono.";
	document.add(new Paragraph(text1, font));

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:29,代码来源:TrueTypeTest.java

示例6: main

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
 * Listing the encodings of font comic.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {

	File font = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf/LiberationMono-Regular.ttf");
	BufferedWriter out = new BufferedWriter(new FileWriter(PdfTestBase.OUTPUT_DIR + "encodings.txt"));
	BaseFont bfComic = BaseFont.createFont(font.getAbsolutePath(), BaseFont.CP1252,
			BaseFont.NOT_EMBEDDED);
	out.write("postscriptname: " + bfComic.getPostscriptFontName());
	out.write("\r\n\r\n");
	String[] codePages = bfComic.getCodePagesSupported();
	out.write("All available encodings:\n\n");
	for (int i = 0; i < codePages.length; i++) {
		out.write(codePages[i]);
		out.write("\r\n");
	}
	out.flush();
	out.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:26,代码来源:ListEncodingsTest.java

示例7: main

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
    * Specifying an encoding.
    */
@Test
   public void main() throws Exception {
       
       
       // step 1: creation of a document-object
       Document document = new Document();
       
           
           // step 2: creation of the writer
           PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontencoding.pdf"));
           
           // step 3: we open the document
           document.open();
           
           // step 4: we add content to the document
           BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
           Font font = new Font(helvetica, 12, Font.NORMAL);
           Chunk chunk = new Chunk("Sponsor this example and send me 1\u20ac. These are some special characters: \u0152\u0153\u0160\u0161\u0178\u017D\u0192\u02DC\u2020\u2021\u2030", font);
           document.add(chunk);
       
       // step 5: we close the document
       document.close();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:27,代码来源:FontEncodingTest.java

示例8: main

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
 * Retrieving the full font name
 */
@Test
public void main() throws Exception {

	
	File font = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf/LiberationMono-Regular.ttf");
	BufferedWriter out = new BufferedWriter(new FileWriter(PdfTestBase.OUTPUT_DIR
			+ "fullfontname_liberationmono.txt"));
	BaseFont bf = BaseFont.createFont(font.getAbsolutePath(), "winansi", BaseFont.NOT_EMBEDDED);
	out.write("postscriptname: " + bf.getPostscriptFontName());
	out.write("\r\n\r\n");
	String names[][] = bf.getFullFontName();
	out.write("\n\nListing the full font name:\n\n");
	for (int k = 0; k < names.length; ++k) {
		if (names[k][0].equals("3") && names[k][1].equals("1")) {
			 // Microsoftencoding
			out.write(names[k][3] + "\r\n");
		}
	}
	out.flush();
	out.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:26,代码来源:FullFontNamesTest.java

示例9: OscarChartPrinter

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
	this.request = request;
	this.os = os;

	document = new Document();
	// writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
	
    writer = PdfWriter.getInstance(document,os);
	writer.setPageEvent(new EndPage());
	document.setPageSize(PageSize.LETTER);
	document.open();
	//Create the font we are going to print to
       bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
       font = new Font(bf, FONTSIZE, Font.NORMAL);
       boldFont = new Font(bf,FONTSIZE,Font.BOLD);
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:17,代码来源:OscarChartPrinter.java

示例10: PdfRecordPrinter

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
public PdfRecordPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
    this.request = request;
    this.os = os;
    formatter = new SimpleDateFormat("dd-MMM-yyyy");

    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriter.getInstance(document,os);
    writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    
    document.open();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:21,代码来源:PdfRecordPrinter.java

示例11: start

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
public void start() throws DocumentException,IOException {
    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
    // writer = PdfWriter.getInstance(document,os);
    // writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    document.open();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:17,代码来源:PdfRecordPrinter.java

示例12: printPdf

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
 * Prints the consultation request.
 * @throws IOException when an error with the output stream occurs
 * @throws DocumentException when an error in document construction occurs
 */
public void printPdf(LoggedInInfo loggedInInfo) throws IOException, DocumentException {

	// Create the document we are going to write to
	document = new Document();
	// PdfWriter.getInstance(document, os);
	PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

	document.setPageSize(PageSize.LETTER);
	document.addTitle(getResource("msgConsReq"));
	document.addCreator("OSCAR");
	document.open();

	// Create the fonts that we are going to use
	bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
			BaseFont.NOT_EMBEDDED);
	headerFont = new Font(bf, 14, Font.BOLD);
	infoFont = new Font(bf, 12, Font.NORMAL);
	font = new Font(bf, 9, Font.NORMAL);
	boldFont = new Font(bf, 10, Font.BOLD);
	bigBoldFont = new Font(bf, 12, Font.BOLD);

	createConsultationRequest(loggedInInfo);

	document.close();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:31,代码来源:ConsultationPDFCreator.java

示例13: initFont

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
private static void initFont() {
	String fontName = ServerConfigurationService.getString("pdf.default.font");
	if (StringUtils.isNotBlank(fontName)) {
		FontFactory.registerDirectories();
		if (FontFactory.isRegistered(fontName)) {
			font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
			boldFont = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.BOLD);
		} else {
			log.warn("Can not find font: " + fontName);
		}
	}
	if (font == null) {
		font = new Font();
		boldFont = new Font(Font.COURIER, 10, Font.BOLD);
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:SpreadsheetDataFileWriterPdf.java

示例14: resolveFonts

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
private void resolveFonts( cfSession _Session, ITextRenderer _renderer ) throws dataNotSupportedException, cfmRunTimeException{
	ITextFontResolver resolver = _renderer.getFontResolver();
	
	boolean embed = getDynamic( _Session, "FONTEMBED" ).getBoolean();
	for ( int i = 0; i < defaultFontDirs.length; i++ ){
		File nextFontDir = new File( defaultFontDirs[i] );
		File[] fontFiles = nextFontDir.listFiles( new FilenameFilter() {
			public boolean accept( File _dir, String _name ){
				String name = _name.toLowerCase();
				return name.endsWith( ".otf" ) || name.endsWith( ".ttf" );
			}
     });
		if ( fontFiles != null ){
      for ( int f = 0; f < fontFiles.length; f++ ){
      	try{
      		resolver.addFont( fontFiles[f].getAbsolutePath(), BaseFont.IDENTITY_H,
  	          embed );
      	}catch( Exception ignored ){} // ignore fonts that can't be added
      }
		}
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:23,代码来源:cfDOCUMENT.java

示例15: onOpenDocument

import com.lowagie.text.pdf.BaseFont; //导入依赖的package包/类
/**
 * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable and set its logo image if
 * there is a logoImage to be used, creates and sets the nestedHeaderTable and its content.
 *
 * @param writer   The PdfWriter for this document.
 * @param document The document.
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
public void onOpenDocument(PdfWriter writer, Document document) {
    try {

        loadHeaderTable();

        // initialization of the template
        tpl = writer.getDirectContent().createTemplate(100, 100);

        // initialization of the font
        helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);

    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:24,代码来源:BulkReceivingPdf.java


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