本文整理匯總了Java中com.openhtmltopdf.util.XRLog類的典型用法代碼示例。如果您正苦於以下問題:Java XRLog類的具體用法?Java XRLog怎麽用?Java XRLog使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XRLog類屬於com.openhtmltopdf.util包,在下文中一共展示了XRLog類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onStartup
import com.openhtmltopdf.util.XRLog; //導入依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
configureSessionCookie(servletContext);
CharacterEncodingFilter cef = new CharacterEncodingFilter();
cef.setEncoding("UTF-8");
cef.setForceEncoding(true);
Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", cef);
characterEncodingFilter.setAsyncSupported(true);
characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");
//force log initialization, then disable it
XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING);
XRLog.setLoggingEnabled(false);
}
示例2: export
import com.openhtmltopdf.util.XRLog; //導入依賴的package包/類
public byte[] export(InputStream template, Map<String, Object> arguments) {
XRLog.setLoggerImpl(new Slf4jLogger());
try {
String resultHtml = templater.transform(template, arguments);
byte[] colorProfile = Utils.resourceBytes("srgb_profile.icm");
PdfBoxRenderer renderer = new PdfRendererBuilder()
.usePdfVersion(1.4f)
.usePdfAConformance("A")
.useColorProfile(colorProfile)
.defaultTextDirection(PdfRendererBuilder.TextDirection.LTR)
.withHtmlContent(resultHtml, "http://localhost:" + serverPort + "/")
.buildPdfRenderer();
PdfBoxFontResolver fontResolver = renderer.getFontResolver();
byte[] fontBytesArial = resourceBytes("arial.ttf");
byte[] fontBytesTahoma = resourceBytes("tahomar.ttf");
byte[] fontBytesTahomaBold = resourceBytes("tahomabd.ttf");
byte[] fontBytesTahomaItalic = resourceBytes("verdanait.ttf");
fontResolver.addFont(() -> new ByteArrayInputStream(fontBytesArial), "Ariel", null, null, false);
fontResolver.addFont(() -> new ByteArrayInputStream(fontBytesTahoma), "Tahoma", null, null, false);
fontResolver.addFont(() -> new ByteArrayInputStream(fontBytesTahomaBold), "Tahoma", 700, null, false);
fontResolver.addFont(() -> new ByteArrayInputStream(fontBytesTahomaItalic), "Tahoma", null, IdentValue.ITALIC, false);
renderer.layout();
ByteArrayOutputStream out = new ByteArrayOutputStream();
renderer.createPDF(out);
return out.toByteArray();
} catch (IOException ex) {
throw new GeneralException(ex);
}
}
示例3: PdfUtilExport
import com.openhtmltopdf.util.XRLog; //導入依賴的package包/類
public PdfUtilExport(String titleContent, String authorContent, String srcHtmlPath, String destPdfPath) {
this.titleContent = titleContent.toUpperCase();
this.authorContent = authorContent;
this.srcHtmlPath = srcHtmlPath;
this.destPdfPath = destPdfPath;
XRLog.setLoggingEnabled(false);
}