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


Java BaseFont類代碼示例

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


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

示例1: cellRodape

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
    Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
    PdfPTable pTable = new PdfPTable(1);
    pTable.setWidthPercentage(100f);
    PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
    if(l){cellValue.setBorderWidthLeft(0);}
    if(r){cellValue.setBorderWidthRight(0);}
   switch (align) 
   {
       case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
       case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
       case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
       default:break;
   }
    pTable.addCell(cellValue);
    return pTable;
}
 
開發者ID:JIGAsoftSTP,項目名稱:NICON,代碼行數:19,代碼來源:ExporOnlyViagemPdf.java

示例2: build

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
/**
 * Update NDA file with visitor name and visitor signature.
 * 
 * @param destFile 
 * @param signatureImage signature file
 * @param visitorName
 * @return File
 */
public static File build(Path destFile, File signatureImage, String visitorName) {
	try {
		PdfReader pdfReader = new PdfReader(ndaUrl);
		PdfStamper pdfStamper = new PdfStamper(pdfReader,
				new FileOutputStream(destFile.toString()));
		Image image = createNDAImage(signatureImage, 0, 0);
		PdfContentByte over = pdfStamper.getOverContent(5);
		over.addImage(image);
		PdfContentByte pdfContentByte = pdfStamper.getOverContent(5);
		pdfContentByte.beginText();
		pdfContentByte.setFontAndSize(BaseFont.createFont
				(BaseFont.HELVETICA, 
						BaseFont.CP1257, 
						BaseFont.EMBEDDED
						)
				, 10); 
		pdfContentByte.setTextMatrix(112, 428); 
		pdfContentByte.showText(visitorName);
		pdfContentByte.setTextMatrix(89, 406);
		pdfContentByte.showText(new SimpleDateFormat("E, dd MMM yyyy").format(new Date()));
		pdfContentByte.endText();
		pdfStamper.close();
		return destFile.toFile();
	} catch (IOException | DocumentException | NumberFormatException e) {
		logger.error("Exception while generating NDA file. ",e);
		return null;
	}
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:37,代碼來源:NdaBuilder.java

示例3: funcaoTitulo

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
private Phrase funcaoTitulo(int i) {
    String txt;
    Font fontcabecatable =  FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
    switch (i)
    {
        case 0:txt="Nr. Factura";break;
        case 1:txt="Nome do Segurado"; break;
        case 2:txt="Prémio";break;
        case 3:txt="Imposto 6%";break;
        case 4:txt="Imposto 5%";break;
        case 5:txt="FGA 2.6%";break;
        default:txt="TOTAL";break;
    }
    
    a=com.itextpdf.text.Element.ALIGN_CENTER;
    Phrase rt = new Phrase(txt,fontcabecatable);
    return rt; 
}
 
開發者ID:JIGAsoftSTP,項目名稱:NICON,代碼行數:19,代碼來源:ExportMapaProducao__.java

示例4: getIdentityFont

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
private BaseFont getIdentityFont(String fontPath,ApplicationContext applicationContext) throws DocumentException,IOException {
	if(!fontPath.startsWith(ApplicationContext.CLASSPATH_URL_PREFIX)){
		fontPath=ApplicationContext.CLASSPATH_URL_PREFIX+fontPath;
	}
	String fontName = fontPath;
	int lastSlashPos=fontPath.lastIndexOf("/");
	if(lastSlashPos!=-1){
		fontName = fontPath.substring(lastSlashPos+1,fontPath.length());			
	}
	if (fontName.toLowerCase().endsWith(".ttc")) {
		fontName = fontName + ",0";
	}
	InputStream inputStream=null;
	try{
		inputStream=applicationContext.getResource(fontPath).getInputStream();
		byte[] bytes = IOUtils.toByteArray(inputStream);
		BaseFont baseFont = BaseFont.createFont(fontName, BaseFont.IDENTITY_H,BaseFont.EMBEDDED,true,bytes,null);
		baseFont.setSubset(true);
		return baseFont;			
	}finally{
		if(inputStream!=null)inputStream.close();
	}
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:24,代碼來源:FontBuilder.java

示例5: exportPdfFile

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
public static File exportPdfFile(String urlStr) throws Exception {
	// String outputFile = this.fileRoot + "/" +
	// ServiceConstants.DIR_PUBINFO_EXPORT + "/" + getFileName() + ".pdf";
	String outputFile = "D:/Documents/test3.pdf";
	OutputStream os = new FileOutputStream(outputFile);
	ITextRenderer renderer = new ITextRenderer();

	String str = getHtmlFile(urlStr);
	renderer.setDocumentFromString(str);
	ITextFontResolver fontResolver = renderer.getFontResolver();

	fontResolver.addFont("F:/keyworkspace/survey/src/conf/itextpdf/simsun.ttc",BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
	// // 宋體字
	fontResolver.addFont("F:/keyworkspace/survey/src/conf/itextpdf/ARIALUNI.TTF",BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);// 宋體字
	renderer.layout();

	renderer.createPDF(os);

	os.flush();
	os.close();
	return new File(outputFile);

}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:24,代碼來源:PDFUtil.java

示例6: testShowTextAlignedVsSimpleColumnTopAlignment

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
 * ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
 * </a>
 * <p>
 * Indeed, the coordinates do not line up. The y coordinate of 
 * {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
 * denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
 * the text to come.
 * </p>
 */
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
    Document document = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
    document.open();

    Font fontQouteItems = new Font(BaseFont.createFont(), 12);
    PdfContentByte canvas = writer.getDirectContent();

    // Item Number
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);

    // Estimated Qty
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);

    // Item Description
    ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
    ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
    ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
    ct.go();

    document.close();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:37,代碼來源:UseColumnText.java

示例7: getFont

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
public Font getFont(int _style, final float size) {
	final int style;
	if(!allowUnderline) {
		style = _style & (~(Font.UNDERLINE));
	} else {
		style = _style;
	}
	String key = style + "," + size;
	return getFont(key, new FontBuilder() {
		@Override
		public Font createFont() {
	    	int baseStyle = style & Font.BOLDITALIC;
			BaseFont bf = baseFontMap.get(baseStyle);
	        return new Font(bf, size, style);
		}
	});    	
}
 
開發者ID:lexml,項目名稱:lexml-renderer-pdf,代碼行數:18,代碼來源:LexmlFontFactory.java

示例8: setApplicationContext

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
	Collection<FontRegister> fontRegisters=applicationContext.getBeansOfType(FontRegister.class).values();
	for(FontRegister fontReg:fontRegisters){
		String fontName=fontReg.getFontName();
		String fontPath=fontReg.getFontPath();
		if(StringUtils.isEmpty(fontPath) || StringUtils.isEmpty(fontName)){
			continue;
		}
		try {
			BaseFont baseFont=getIdentityFont(fontPath,applicationContext);
			if(baseFont==null){
				throw new ReportComputeException("Font " + fontPath + " does not exist");
			}
			fontMap.put(fontName, baseFont);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ReportComputeException(e);
		}
	}
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:21,代碼來源:FontBuilder.java

示例9: writeSimplePdf

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
public static void writeSimplePdf() throws Exception{
			//1.新建document對象
			//第一個參數是頁麵大小。接下來的參數分別是左、右、上和下頁邊距。
			Document document = new Document(PageSize.A4, 50, 50, 50, 50);
			//2.建立一個書寫器(Writer)與document對象關聯,通過書寫器(Writer)可以將文檔寫入到磁盤中。
			//創建 PdfWriter 對象 第一個參數是對文檔對象的引用,第二個參數是文件的實際名稱,在該名稱中還會給出其輸出路徑。
			PdfWriter writer = PdfWriter.getInstance(document, 	new FileOutputStream("D:\\Documents\\ITextTest.pdf"));
			//3.打開文檔
			document.open();		
			//4.向文檔中添加內容
			//通過 com.lowagie.text.Paragraph 來添加文本。可以用文本及其默認的字體、顏色、大小等等設置來創建一個默認段落
			BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font fontChinese = new Font(bfChinese, 22, Font.BOLD, BaseColor.BLACK);
			
			document.add(new Paragraph("sdfsdfsd全是中文顯示了沒.fsdfsfs",fontChinese));
			document.add(new Paragraph("Some more text on the 	first page with different color and font type.",
					FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new BaseColor(255, 150, 200))));
			Paragraph pragraph=new Paragraph("你這裏有中亠好", fontChinese);
			document.add(pragraph);
			
			//圖像支持格式 GIF, Jpeg, PNG, wmf
			Image gif = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
			gif.setBorder(5);
			gif.scaleAbsolute(30,30);
			gif.setAlignment(Image.RIGHT|Image.TEXTWRAP);
			document.add(gif);
			Paragraph pragraph11=new Paragraph("你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好你這裏有中亠好", fontChinese);
			document.add(pragraph11);
			
			Image gif15 = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
//			gif15.setBorder(50);
			gif15.setBorder(Image.BOX);
			gif15.setBorderColor(BaseColor.RED);
//			gif15.setBorderColorBottom(borderColorBottom)
			gif15.setBorderWidth(1);
			gif15.scalePercent(50);
			document.add(gif15);
			//5.關閉文檔
			document.close();
		}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:41,代碼來源:ItextpdfTest.java

示例10: addOfferInstances

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
private void addOfferInstances(List<OfferInstance> offerInstances, Document document, BaseFont bf)
		throws DocumentException {

	if(offerInstances.isEmpty()) {
		return;
	}

	document.add(new Paragraph("Wybrane oferty: ", new Font(bf, 12)));

	PdfPTable offerInstancesTable = new PdfPTable(3);
	offerInstancesTable.setWidthPercentage(100);
	offerInstancesTable.setSpacingBefore(18f);
	offerInstancesTable.setSpacingAfter(18f);
	createofferInstancesTableHeaders(offerInstancesTable);
	createofferInstancesTableContent(offerInstances, offerInstancesTable);
	document.add(offerInstancesTable);
}
 
開發者ID:marcin-pwr,項目名稱:hotel,代碼行數:18,代碼來源:ResidenceService.java

示例11: makePDF

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
private static void makePDF(Bitmap bmp, File file) {
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.addAuthor(FullscreenActivity.mAuthor.toString());
        document.addTitle(FullscreenActivity.mTitle.toString());
        document.addCreator("OpenSongApp");
        if (bmp!=null && bmp.getWidth()>bmp.getHeight()) {
            document.setPageSize(PageSize.A4.rotate());
        } else {
            document.setPageSize(PageSize.A4);
        }
        document.addTitle(FullscreenActivity.mTitle.toString());
        document.open();//document.add(new Header("Song title",FullscreenActivity.mTitle.toString()));
        BaseFont urName = BaseFont.createFont("assets/fonts/Lato-Reg.ttf", "UTF-8",BaseFont.EMBEDDED);
        Font TitleFontName  = new Font(urName, 14);
        Font AuthorFontName = new Font(urName, 10);
        document.add(new Paragraph(FullscreenActivity.mTitle.toString(),TitleFontName));
        document.add(new Paragraph(FullscreenActivity.mAuthor.toString(),AuthorFontName));
        addImage(document,bmp);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:thebigg73,項目名稱:OpenSongTablet,代碼行數:26,代碼來源:ExportPreparer.java

示例12: stampTextOriginal

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
/**
 * The OP's original code transformed into Java
 */
void stampTextOriginal(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setColorFill(new BaseColor(255,200,200));
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:StampColoredText.java

示例13: stampTextChanged

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
/**
 * The OP's code transformed into Java changed with the work-around.
 */
void stampTextChanged(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.setColorFill(new BaseColor(255,200,200));
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:StampColoredText.java

示例14: testAddUnicodeStampSampleOriginal

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/erkv9wot9d460dg/sampleOriginal.pdf?dl=0">
 * sampleOriginal.pdf
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader. With a different starting file, though, it doesn't, cf.
 * {@link #testAddUnicodeStampEg_01()}.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testAddUnicodeStampSampleOriginal() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("sampleOriginal.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "sampleOriginal-unicodeStamp.pdf"))  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);
        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        PdfContentByte cb = stamper.getOverContent(1);

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);
        
        stamper.close();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:39,代碼來源:StampUnicodeText.java

示例15: testAddUnicodeStampEg_01

import com.itextpdf.text.pdf.BaseFont; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/erkv9wot9d460dg/sampleOriginal.pdf?dl=0">
 * sampleOriginal.pdf
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader, cf. {@link #testAddUnicodeStampSampleOriginal()}. With
 * a different starting file, though, it doesn't as this test shows.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testAddUnicodeStampEg_01() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("eg_01.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "eg_01-unicodeStamp.pdf"))  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);

        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        PdfContentByte cb = stamper.getOverContent(1);

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);
        
        stamper.close();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:40,代碼來源:StampUnicodeText.java


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