I am processing an HTML
to PDF
using itextpdf but I have a problem. The HTML
has certain parameters that should be set after transformation. When I manipulate the pdf file to set the image that has the vertical watermark, The byte[]
that generates the pdf has something like this:
[(C)-7(ódi)8(g)-3(o)16(:)-7(${)15(C)-7(O)4(D)3(_)5(D)3(O)4(C)-7(} )20(R)-3(e)-3(v)-4(i)7(s)-3(i)7(ón)15(:)-7(${)15(R)-3(E)10(V)9(_)5(D)3(O)4(C)-7(} )5(F)-3(e)-3(ch)15(a:)-5(${)15(F)-3(E)10(C)-7(H)19(A)-5(_)5(D)3(O)4(C)-7(})] TJ
this has some parameters like ${COD_DOC}
, but when I set them the problem is image linked
My question is: what does the numbers mean? because when I try to set the letter P it doesnt work.
Code:
public Image manipulatePdfTemplate(File pdfTemplate, PdfDocument pdfDoc, Map<String, Object> fileVariables)
throws Exception
{
log.info("Iniciando el procesamiento del la plantilla pdf");
PdfPage firstPage = pdfDoc.getFirstPage();
// Sustituimos las variables por los valores de los parametros
PdfObject object = firstPage.getPdfObject().get(PdfName.Contents);
if (object instanceof PdfStream) {
PdfStream stream = (PdfStream) object;
byte[] data = stream.getBytes();
// Método para escribir los bytes del contenido del pdf en un txt
// writePdfContent(data);
// Falla el caracter "5" y "X"
if (fileVariables != null) {
if (fileVariables.get("COD_DOC") != null && fileVariables.get("REV_DOC") != null
&& fileVariables.get("FECHA_DOC") != null) {
String replacedData = new String(data, StandardCharsets.ISO_8859_1)
.replace(AppConstant.COD_DOC, " (" + fileVariables.get("COD_DOC") + " )")
.replace(AppConstant.REV_DOC, " (" + fileVariables.get("REV_DOC") + " )")
.replace(AppConstant.FECHA_DOC, " (" + fileVariables.get("FECHA_DOC") + ")");
stream.setData(replacedData.getBytes(StandardCharsets.ISO_8859_1));
}
else if(fileVariables.get("VERTICAL_TEXT") != null) {
String replacedData = new String(data, StandardCharsets.ISO_8859_1)
.replace(AppConstant.VERTICAL_TEXT, "(" + fileVariables.get("VERTICAL_TEXT") + ")");
stream.setData(replacedData.getBytes(StandardCharsets.ISO_8859_1));
}
}
}
// Convertimos el resultado a imagen que añadiremos de fondo en cada página del pdf resultante
PdfFormXObject pageCopy = firstPage.copyAsFormXObject(pdfDoc);
Image image = new Image(pageCopy);
return image;
}