Код: Выделить всё
byte[] plantillaBytes = null;
File fileTemp = null;
File filePlantilla = null;
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
OutputStream os = null;
OutputStreamWriter osw = null;
// 1.Create the template
try {
RTFTemplate rtfTemplate = null;
try {
rtfTemplate = RTFTemplateBuilder
.newRTFTemplateBuilder(ApplicationContextProvider.getApplicationContext())
.newRTFTemplate(RTFTemplateBuilder.DEFAULT_FREEMARKER_RTFTEMPLATE);
} catch (UnsupportedRTFTemplate e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
String rutaTemp = this.appConfiguration.getProperty(RUTA_DATOS_TEMPORAL);
try {
fileTemp = File.createTempFile("fichero", "." + com.ejie.ad74a.constantes.Constantes.EXT_RTF,
new File(rutaTemp));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 2. Set the RTF model source
filePlantilla = new File(pathRtf);
try {
rtfTemplate.setTemplate(filePlantilla);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
// 3. add QR
// Create text for QR 00870#0X#02;TL_...
String texto = expediente.getIdProcedimiento00().substring(0,
expediente.getIdProcedimiento00().length() - 2) + "#"
+ expediente.getIdProcedimiento00().substring(expediente.getIdProcedimiento00().length() - 2)
+ "#" + TipoAportacionEnum.SUBSANACION.getTipoLeadingZero() + ";"
+ expediente.getNumExpediente00();
pathPlantilla = "/".concat(com.ejie.ad74a.constantes.Constantes.COD_APLICACION.toLowerCase())
.concat("/").concat(plantilla);
pathXML = "/".concat(com.ejie.ad74a.constantes.Constantes.COD_APLICACION.toLowerCase())
.concat("/reqSubsanacion_" + expediente.getNumExpediente00() + ".xml");
pathResultado = "/".concat(com.ejie.ad74a.constantes.Constantes.COD_APLICACION.toLowerCase())
.concat("/reqSubsanacion_" + expediente.getNumExpediente00() + ".doc");
pathRtf = this.appConfiguration.getProperty("ruta.datos.plantillas") + "/" + plantilla;
try {
byte[] image = toByteArray(generateQRCodeImage(texto), "png");
Format imageFieldFormatter = new DefaultInputStreamFormat();
rtfTemplate.put("CODIGOQR", image);
os = new FileOutputStream(rutaTemp);
osw = new OutputStreamWriter(os);
< /code>
Вот где он сбоят < /p>
rtfTemplate.merge(osw);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} finally {
try {
if (fis != null) {
fis.close();
}
if (bos != null) {
bos.close();
}
if (os != null) {
os.close();
}
if (osw != null) {
osw.close();
}
} catch (IOException e) {
DocumentosServiceImpl.logger.error(
"DocumentosServiceImpl.generarDocumentoResolucion. Error añadiendo el QR a la plantilla: "
+ e.getMessage(),
e);
}
< /code>
И это ошибка:
Введите описание изображения здесь < /p>
Я не знаю, работал ли кто -нибудь с библиотеками, которые могут быть Используется для этих функций, но если они отличаются от моих, и они работают, я переключу их без проблем. Я просто хочу, чтобы это сработало. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/793 ... atebuilder
Мобильная версия