當前位置: 首頁>>代碼示例>>Java>>正文


Java BaseFont.createFont方法代碼示例

本文整理匯總了Java中com.lowagie.text.pdf.BaseFont.createFont方法的典型用法代碼示例。如果您正苦於以下問題:Java BaseFont.createFont方法的具體用法?Java BaseFont.createFont怎麽用?Java BaseFont.createFont使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lowagie.text.pdf.BaseFont的用法示例。


在下文中一共展示了BaseFont.createFont方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
 * Changing the width of font glyphs.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
	System.out.println("Fixed Font Width");
	// step 1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	try {
		// step 2
		PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "fixedfontwidth.pdf"));
		// step 3
		document.open();
		// step 4
		BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false, false, null, null);
		int widths[] = bf.getWidths();
		for (int k = 0; k < widths.length; ++k) {
			if (widths[k] != 0)
				widths[k] = 1000;
		}
		bf.setForceWidthsOutput(true);
		document.add(new Paragraph("A big text to show Helvetica with fixed width.", new Font(bf)));
	} catch (Exception de) {
		de.printStackTrace();
	}
	// step 5
	document.close();
}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:31,代碼來源:FixedFontWidth.java

示例5: txtToPdf

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
public static void txtToPdf(InputStream is, File fileOut) throws Exception{
	Document doc = new Document();
	FileOutputStream out = new FileOutputStream(fileOut);
	PdfWriter.getInstance(doc, out);
	BaseFont bfHei = BaseFont.createFont(FONT_PATH, BaseFont.IDENTITY_H,
			BaseFont.NOT_EMBEDDED);
	Font font = new Font(bfHei, 12);
	BufferedReader reader = new BufferedReader(new InputStreamReader(is));
	String content = null;
	StringBuffer bu = new StringBuffer();
	doc.open();
	while ((content = reader.readLine()) != null) {
		bu.append(content);
	}
	Paragraph text = new Paragraph(bu.toString(), font);
	doc.add(text);
	doc.close();
	reader.close();
	if (is != null)
		is.close();
}
 
開發者ID:yichenlian,項目名稱:convertJob,代碼行數:22,代碼來源:ConvertJob.java

示例6: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
	 * Using oth
	 * 
	 * @param args
	 *            no arguments needed
	 */
	public static void main(String[] args) {
		// step 1
		Document document = new Document(PageSize.A4, 50, 50, 50, 50);
		try {
			// step 2
			PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "opentypefont.pdf"));
			// step 3
			document.open();
			// step 4
			//Don't use path read ttf into byte[] instead
//			BaseFont bf = BaseFont.createFont("liz.otf", BaseFont.CP1252, true);
			InputStream inputStream = PdfTestRunner.getActivity().getResources().openRawResource(R.raw.liz);
			byte[] buffer = new byte[inputStream.available()];
			inputStream.read(buffer);
			BaseFont bf = BaseFont.createFont("freesans.ttf", BaseFont.CP1252, true, false, buffer, null);
			String text = "Some text with the otf font LIZ.";
			document.add(new Paragraph(text, new Font(bf, 14)));
		} catch (Exception de) {
			de.printStackTrace();
		}
		// step 5
		document.close();
	}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:30,代碼來源:OpenTypeFont.java

示例7: 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() throws IOException, DocumentException {

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

	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();

	document.close();
}
 
開發者ID:oscarservice,項目名稱:oscar-old,代碼行數:30,代碼來源:ConsultationPDFCreator.java

示例8: createFixedFont

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
private BaseFont createFixedFont() throws Exception {
	
	boolean cached = true;
	byte[] ttf;
	{
		InputStream in = CheckPdfRenderer.class.getResourceAsStream("/com/moss/check/us/VeraMono.ttf");
		ByteArrayOutputStream out = new ByteArrayOutputStream();

		byte[] buffer = new byte[1024 * 10]; //10k buffer
		for(int numRead = in.read(buffer); numRead!=-1; numRead = in.read(buffer)){
			out.write(buffer, 0, numRead);
		}

		ttf = out.toByteArray();
	}
	byte[] pfb = null; 
	boolean noThrow = false;
	
	BaseFont baseFont = BaseFont.createFont("VeraMono.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, cached, ttf, pfb, noThrow);
	
	return baseFont;
}
 
開發者ID:mosscode,項目名稱:us-check-printing,代碼行數:23,代碼來源:CheckPdfRenderer.java

示例9: createMicrFont

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
private BaseFont createMicrFont() throws Exception {
	
	boolean cached = true;
	byte[] ttf;
	{
		InputStream in = CheckPdfRenderer.class.getResourceAsStream("/com/moss/check/us/GnuMICR.ttf");
		ByteArrayOutputStream out = new ByteArrayOutputStream();

		byte[] buffer = new byte[1024 * 10]; //10k buffer
		for(int numRead = in.read(buffer); numRead!=-1; numRead = in.read(buffer)){
			out.write(buffer, 0, numRead);
		}

		ttf = out.toByteArray();
	}
	byte[] pfb = null; 
	boolean noThrow = false;
	
	BaseFont baseFont = BaseFont.createFont("GnuMICR.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, cached, ttf, pfb, noThrow);
	
	return baseFont;
}
 
開發者ID:mosscode,項目名稱:us-check-printing,代碼行數:23,代碼來源:CheckPdfRenderer.java

示例10: getFont

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
private static Font getFont( String fontPath, float size )
{
    try
    {
        BaseFont baseFont = BaseFont.createFont( fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED );
        return new Font( baseFont, size );
    }
    catch ( Exception ex )
    {
        throw new RuntimeException( "Error while creating base font", ex );
    }
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:13,代碼來源:PDFUtils.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);

	document = new Document();
	writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
	writer.setStrictImageSequence(true);

	document.setPageSize(PageSize.LETTER);
	document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:14,代碼來源:TicklerPrinter.java

示例12: printRtf

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
public void printRtf()throws IOException, DocumentException{
	//create an input stream from the rtf string bytes
	byte[] rtfBytes = handler.getOBXResult(0, 0).getBytes();
	ByteArrayInputStream rtfStream = new ByteArrayInputStream(rtfBytes);
	
	//create & open the document we are going to write to and its writer
	document = new Document();
	RtfWriter2 writer = RtfWriter2.getInstance(document,os);
	document.setPageSize(PageSize.LETTER);
	document.addTitle("Title of the Document");
	document.addCreator("OSCAR");
	document.open();
	
    //Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, 11, Font.NORMAL);
    boldFont = new Font(bf, 12, Font.BOLD);
 //   redFont = new Font(bf, 11, Font.NORMAL, Color.RED);
    
    //add the patient information
    addRtfPatientInfo();
    
    //add the results
	writer.importRtfDocument(rtfStream, null);
	
	document.close();
	os.flush();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:29,代碼來源:LabPDFCreator.java

示例13: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
 * Embedding True Type Fonts.
 */
@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();

	// step 4: we add content to the document
	BaseFont bfComic = BaseFont.createFont(PdfTestBase.RESOURCES_DIR + "/liberation-fonts-ttf/LiberationSans-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
	Font font = new Font(bfComic, 12);
	String text1 = "This is the quite popular True Type font 'LiberationSans'.";
	String text2 = "Some greek characters: \u0393\u0394\u03b6";
	String text3 = "Some cyrillic characters: \u0418\u044f";
	document.add(new Paragraph(text1, font));
	document.add(new Paragraph(text2, font));
	document.add(new Paragraph(text3, font));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:33,代碼來源:TrueTypeTest.java

示例14: main

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
/**
 * Writing vertical text.
 */
@Test
public void main() throws Exception {
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	texts[3] = convertCid(texts[0]);
	texts[4] = convertCid(texts[1]);
	texts[5] = convertCid(texts[2]);
	PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("vertical.pdf"));
	int idx = 0;
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	for (int j = 0; j < 2; ++j) {
		BaseFont bf = BaseFont.createFont("KozMinPro-Regular", encs[j],	false);
		cb.setRGBColorStroke(255, 0, 0);
		cb.setLineWidth(0);
		float x = 400;
		float y = 700;
		float height = 400;
		float leading = 30;
		int maxLines = 6;
		for (int k = 0; k < maxLines; ++k) {
			cb.moveTo(x - k * leading, y);
			cb.lineTo(x - k * leading, y - height);
		}
		cb.rectangle(x, y, -leading * (maxLines - 1), -height);
		cb.stroke();
		VerticalText vt = new VerticalText(cb);
		vt.setVerticalLayout(x, y, height, maxLines, leading);
		vt.addText(new Chunk(texts[idx++], new Font(bf, 20)));
		vt.addText(new Chunk(texts[idx++], new Font(bf, 20, 0, Color.blue)));
		vt.go();
		vt.setAlignment(Element.ALIGN_RIGHT);
		vt.addText(new Chunk(texts[idx++],	new Font(bf, 20, 0, Color.orange)));
		vt.go();
		document.newPage();
	}
	document.close();

}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:42,代碼來源:VerticalTest.java

示例15: printPdf

import com.lowagie.text.pdf.BaseFont; //導入方法依賴的package包/類
public void printPdf() throws IOException, DocumentException{

        // check that we have data to print
        if (handler == null)
            throw new DocumentException();

        //response.setContentType("application/pdf");  //octet-stream
        //response.setHeader("Content-Disposition", "attachment; filename=\""+handler.getPatientName().replaceAll("\\s", "_")+"_LabReport.pdf\"");

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

        //Set page event, function onEndPage will execute each time a page is finished being created
        writer.setPageEvent(this);

        document.setPageSize(PageSize.LETTER);
        document.addTitle("Title of the Document");
        document.addCreator("OSCAR");
        document.open();

        //Create the fonts that we are going to use
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        font = new Font(bf, 9, Font.NORMAL);
        boldFont = new Font(bf, 10, Font.BOLD);
      //  redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

        // add the header table containing the patient and lab info to the document
        createInfoTable();

        // add the tests and test info for each header
        ArrayList<String> headers = handler.getHeaders();
        for (int i=0; i < headers.size(); i++)
            addLabCategory( headers.get(i) ,null);

        for(MessageHandler extraHandler:handlers) {
        	ArrayList<String> extraHeaders = extraHandler.getHeaders();
            for (int i=0; i < extraHeaders.size(); i++)
                addLabCategory( extraHeaders.get(i) , extraHandler);
        }
        // add end of report table
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setPhrase(new Phrase("  "));
        table.addCell(cell);
        cell.setBorder(15);
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPhrase(new Phrase("END OF REPORT", boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        document.add(table);

        document.close();

        os.flush();
    }
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:62,代碼來源:LabPDFCreator.java


注:本文中的com.lowagie.text.pdf.BaseFont.createFont方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。