2
pdf文書のすべてのページにヘッダーとフッターを追加するイベントを生成すると、ページに新しい画像を追加すると新しいヘッダーの下に新しい画像が表示される画像。私は解決策を見つけようとしましたが、見つけることができません。アルファチャンネルが設定されたpngの画像で試しましたが、問題は消えません。ヘッダーの画像の後にiTextに画像を挿入
class PieCabecera extends PdfPageEventHelper{
public int numeroPagina;
public Image imagen;
public PdfPTable tabla;
public PdfTemplate tpl;
public Phrase cabecera;
Font smallBold = new Font(Font.FontFamily.HELVETICA, 1, Font.BOLD);
/**
*
* @param writer
* @param documento
*/
@Override
public void onStartPage(PdfWriter writer, Document documento){
numeroPagina++;
try{
imagen = Image.getInstance("D:/Users/Operador/Documents/NetBeansProjects/ServiciosWeb-dev/web/img/logoPDF.jpg");
imagen.setAbsolutePosition(50, 0);
PdfContentByte cbCabecera = writer.getDirectContent();
tpl = cbCabecera.createTemplate(600, 250);
tpl.addImage(imagen);
cbCabecera.addTemplate(tpl, 0, 750);
cabecera = new Phrase(cbCabecera + ".", smallBold);
documento.add(cabecera);
Paragraph parrafo0 = new Paragraph();
parrafo0.setSpacingBefore(12);
parrafo0.setSpacingAfter(14);
documento.add(parrafo0);
/*Línea de separación*/
LineSeparator ls = new LineSeparator();
documento.add(new Chunk(ls));
Paragraph parrafo = new Paragraph();
parrafo.setSpacingBefore(4);
documento.add(parrafo);
}catch(BadElementException e){
LOGGER.log(Level.SEVERE, "Error: {0}", e.getStackTrace());
}catch(IOException e){
LOGGER.log(Level.SEVERE, "Error: {0}", e.getStackTrace());
}catch(DocumentException e){
LOGGER.log(Level.SEVERE, "Error: {0}", e.getStackTrace());
}
}
/**
*
* @param writer
* @param documento
*/
@Override
public void onEndPage(PdfWriter writer, Document documento){
Rectangle rect = writer.getBoxSize("art");
//header
ColumnText.showTextAligned(writer.getDirectContent(),Element.ALIGN_CENTER, cabecera, rect.getRight(), rect.getTop(), 0);
//footer
ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(String.format("Página %d", numeroPagina)), (rect.getLeft() + rect.getRight())/2, rect.getBottom() - 18, 0);
}
}
ご協力いただきありがとうございます。
はい、この瞬間に私はあなたの助けに感謝しています。 – lfergon
それは間違いでした、数ピクセルで、ありがとうございました。 – lfergon
あなたは大歓迎です! –