@Test public void findFromDOCXToPDFViaITextConverter() throws Exception { try { Options o = Options.getFrom(DocumentKind.DOCX).to(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF); // Test if converter is not null IConverter converter = ConverterRegistry.getRegistry().getConverter(o); assertNotNull(converter); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testOptionsWithURIResolver() throws Exception { Options options = Options.getFrom("DOCX"); OptionsHelper.setURIResolver( options, new IURIResolver() { public String resolve(String uri) { return null; } }); XHTMLOptions xhtmlOptions = XWPF2XHTMLConverter.getInstance().toXHTMLOptions(options); Assert.assertNotNull(xhtmlOptions); Assert.assertNotNull(xhtmlOptions.getURIResolver()); }
@Test public void testWithSubOptions() throws Exception { XHTMLOptions xhtmlOptions1 = XHTMLOptions.create() .URIResolver( new org.apache.poi.xwpf.converter.core.IURIResolver() { public String resolve(String uri) { return uri; } }); Options options = Options.getFrom("DOCX").subOptions(xhtmlOptions1); XHTMLOptions xhtmlOptions2 = XWPF2XHTMLConverter.getInstance().toXHTMLOptions(options); Assert.assertNotNull(xhtmlOptions2); Assert.assertEquals(xhtmlOptions1, xhtmlOptions2); }
public PdfOptions toPdfOptions(Options options) { if (options == null) { return null; } Object value = options.getSubOptions(PdfOptions.class); if (value instanceof PdfOptions) { return (PdfOptions) value; } PdfOptions pdfOptions = PdfOptions.create(); // Populate font encoding String fontEncoding = OptionsHelper.getFontEncoding(options); if (StringUtils.isNotEmpty(fontEncoding)) { pdfOptions.fontEncoding(fontEncoding); } return pdfOptions; }
/* (non-Javadoc) * @see fr.opensagres.xdocreport.service.rest.XDocReportService#processReport(fr.opensagres.xdocreport.document.domain.ReportAndDataRepresentation) */ @POST @Path("/processReport") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.WILDCARD) public byte[] processReport(ReportAndDataRepresentation reportAndDataRepresentation) throws RemoteInvocationException { System.err.println(reportAndDataRepresentation); FieldsMetadata fieldsMetadata = new FieldsMetadata(); List<String> fields = reportAndDataRepresentation.getFieldsMetaData(); for (String field : fields) { fieldsMetadata.addFieldAsList(field); } WSOptions wsOptions = reportAndDataRepresentation.getOptions(); Options options = null; if (wsOptions != null) { options = Options.getFrom(wsOptions.getFrom()).to(wsOptions.getTo()).via(wsOptions.getVia()); } byte[] result; try { result = delegate.process( reportAndDataRepresentation.getDocument(), fieldsMetadata, reportAndDataRepresentation.getTemplateEngine(), reportAndDataRepresentation.getDataContext(), options); } catch (XDocReportException e) { throw new RemoteInvocationException(e.getMessage(), e.getStackTrace()); } return result; }
@Test public void testNotNullOptions() throws Exception { Options options = Options.getFrom("DOCX"); XHTMLOptions xhtmlOptions = XWPF2XHTMLConverter.getInstance().toXHTMLOptions(options); Assert.assertNotNull(xhtmlOptions); }