[英]when creating a pdf using pdfcopy returns a empty document
當我使用pdfcopy創建pdf時,返回客戶端的pdf為空或只有1行,但是當我在資源管理器中打開它時,它具有我合並的所有數據,我使用itextsharp 5
這是我進行合並的地方:
try {
document.close();
PdfReader reader2 = new PdfReader(pdfStream.toByteArray());
//se crea el documento final
Document documentFinal= new Document(PageSize.LETTER, left, right, top, bottom);
PdfCopy pdf_copy = new PdfCopy(documentFinal, pdfStreamFinal);
PdfWriter pdfFinal = PdfWriter.getInstance(documentFinal, pdfStreamFinal);
pdfFinal.setInitialLeading(20);
documentFinal.open();
//CONTENIDO PARA PODER UNIR LOS PDFs
PdfPTable tContenido = new PdfPTable(1);
tContenido.addCell(Celda(pdfEl.textocelda(false, "DESCRIPCIÓN GENERAL", 6.0f), false, 1,1, BaseColor.WHITE));
documentFinal.add(tContenido);
//INICIAR CARGA DE DATOS EN DOCUMENTO FINAL
PdfReader readerR = new PdfReader(reader2);
int pagesR = readerR.getNumberOfPages();
for (int p = 1; p <= pagesR; p++)
pdf_copy.addPage(pdf_copy.getImportedPage(readerR, p));
readerR.close();
//se unen los demas PDFs
for (PdfReader read : readerList) {
PdfReader reader = new PdfReader(read);
int pages = reader.getNumberOfPages();
for (int p = 1; p <= pages; p++)
pdf_copy.addPage(pdf_copy.getImportedPage(reader, p));
reader.close();
}
documentFinal.close();
pdf_copy.close();
} catch (BadElementException ex) {
Logger.getLogger(Calle.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Calle.class.getName()).log(Level.SEVERE, null, ex);
} catch (DocumentException ex) {
Logger.getLogger(Calle.class.getName()).log(Level.SEVERE, null, ex);
}
return pdfStreamFinal.toByteArray();
然后我像這樣發送
return Response.ok(makePDF.makePDFEjecutivo(idalle)).header("Content-Disposition", "inline; filename=" + pdfName + ".pdf").build();
這是在文檔查看器上打開的文檔
這是在mozzila firefox上打開的同一文檔
我怎么解決這個問題? 我需要在兩個地方都顯示相同信息的同一文檔。
旁注:當我將類型“ inline”更改為“ attachment”時,它僅顯示來自第一個img的信息
您應該刪除此變量:
PdfWriter pdfFinal;
因為當您創建此變量的實例時, PdfCopy pdf_copy
引用的文檔將被覆蓋並創建一個新的空文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.