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


Java PhysicalFonts.getBoldForm方法代码示例

本文整理汇总了Java中org.docx4j.fonts.PhysicalFonts.getBoldForm方法的典型用法代码示例。如果您正苦于以下问题:Java PhysicalFonts.getBoldForm方法的具体用法?Java PhysicalFonts.getBoldForm怎么用?Java PhysicalFonts.getBoldForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.docx4j.fonts.PhysicalFonts的用法示例。


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

示例1: output

import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
/** Create a pdf version of the document. 
	 * 
	 * @param os
	 *            The OutputStream to write the pdf to 
	 * 
	 * */     
    public void output(OutputStream os) throws Docx4JException {
    	
    					
        try {
			// Put the html in result
			org.w3c.dom.Document xhtmlDoc = org.docx4j.XmlUtils.neww3cDomDocument();
			javax.xml.transform.dom.DOMResult result = new javax.xml.transform.dom.DOMResult(xhtmlDoc);
			
			AbstractHtmlExporter exporter = new HtmlExporter();
			exporter.html(wordMLPackage, result, false,
					System.getProperty("java.io.tmpdir") ); // false -> don't use HTML fonts.
					
			// Now render the XHTML
			org.xhtmlrenderer.pdf.ITextRenderer renderer = new org.xhtmlrenderer.pdf.ITextRenderer();
					
			// 4.  Use addFont code like that below as necessary for the fonts
			
				// See https://xhtmlrenderer.dev.java.net/guide/users-guide-r7.html#xil_32
			org.xhtmlrenderer.extend.FontResolver resolver = renderer.getFontResolver();		
					
			Map fontsInUse = wordMLPackage.getMainDocumentPart().fontsInUse();
			Iterator fontMappingsIterator = fontsInUse.entrySet().iterator();
			while (fontMappingsIterator.hasNext()) {
			    Map.Entry pairs = (Map.Entry)fontMappingsIterator.next();
			    if(pairs.getKey()==null) {
			    	log.info("Skipped null key");
			    	pairs = (Map.Entry)fontMappingsIterator.next();
			    }
			    
			    String fontName = (String)pairs.getKey();
			    
			    PhysicalFont pf = wordMLPackage.getFontMapper().getFontMappings().get(fontName);
			    
			    if (pf==null) {
			    	log.error("Document font " + fontName + " is not mapped to a physical font!");
			    	continue;
			    }
			    
			    embed(renderer, pf);	        
			    // For any font we embed, also embed the bold, italic, and bold italic substitute
			    // .. at present, we can't tell which of these forms are actually used, so add them all
			    // bold, italic etc
			    PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
			    if (pfVariation!=null) {
				    embed(renderer, pfVariation);	        
			    }
			    pfVariation = PhysicalFonts.getBoldItalicForm(pf);
			    if (pfVariation!=null) {
				    embed(renderer, pfVariation);	        
			    }
			    pfVariation = PhysicalFonts.getItalicForm(pf);
			    if (pfVariation!=null) {
				    embed(renderer, pfVariation);	        
			    }
			    
			}
			
			// TESTING
//	    xhtmlDoc = org.docx4j.XmlUtils.neww3cDomDocument();
//	    try {
//			xhtmlDoc = XmlUtils.getNewDocumentBuilder().parse(new File("C:\\Users\\jharrop\\workspace\\docx4all\\sample-docs\\comic.html"));
//        } catch (Exception e) {
//            e.printStackTrace();
//        } 	    
			
			renderer.setDocument(xhtmlDoc, null);
			renderer.layout();
			
			renderer.createPDF(os);
		} catch (Exception e) {
			throw new Docx4JException("Failed creating PDF via HTML " ,e);
		}
		
		
	}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:82,代码来源:Conversion.java

示例2: createContent

import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
public static void createContent(MainDocumentPart wordDocumentPart ) {
	/*
	 * NB, this currently works nicely with
	 * viaIText, and viaXSLFO (provided
	 * you view with Acrobat Reader .. it 
	 * seems to overwhelm pdfviewer, which
	 * is weird, since viaIText works in both).
	 */
	
	try {
		// Do this explicitly, since we need
		// it in order to create our content
		PhysicalFonts.discoverPhysicalFonts(); 						
														
		Map<String, PhysicalFont> physicalFontMap = PhysicalFonts.getPhysicalFonts();			
		Iterator physicalFontMapIterator = physicalFontMap.entrySet().iterator();
		while (physicalFontMapIterator.hasNext()) {
		    Map.Entry pairs = (Map.Entry)physicalFontMapIterator.next();
		    if(pairs.getKey()==null) {
		    	pairs = (Map.Entry)physicalFontMapIterator.next();
		    }
		    String fontName = (String)pairs.getKey();
		    PhysicalFont pf = (PhysicalFont)pairs.getValue();
		    
		    System.out.println("Added paragraph for " + fontName);
		    addObject(wordDocumentPart, sampleText, fontName );

		    // bold, italic etc
		    PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
		    if (pfVariation!=null) {
			    addObject(wordDocumentPart, sampleTextBold, pfVariation.getName() );
		    }
		    pfVariation = PhysicalFonts.getBoldItalicForm(pf);
		    if (pfVariation!=null) {
			    addObject(wordDocumentPart, sampleTextBoldItalic, pfVariation.getName() );
		    }
		    pfVariation = PhysicalFonts.getItalicForm(pf);
		    if (pfVariation!=null) {
			    addObject(wordDocumentPart, sampleTextItalic, pfVariation.getName() );
		    }
		    
		}
	} catch (Exception e) {
		e.printStackTrace();
	}    		    
	
}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:48,代码来源:SampleDocumentGenerator.java


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