Я получаю исключение, описанное в заголовке, когда пытаюсь печатать несколько документов непрерывно.
Первый напечатан, но для второго процесса создайте c .close () выброшенное исключение ,
1.принт методы.
private void print1(Cell header, Table table, Cell footer, int size) throws Exception {
byte[] bytes = somePrintService.getByteArray(header, table, footer, size);
somePrintService.printbytes(bytes);
}
private void print2(Cell header, Table table, Cell footer, int size) throws Exception {
byte[] bytes = somePrintService.getByteArray(header, table, footer, size);
somePrintService.printbytes(bytes);
}
2.getByteArray метод в somePrintService
public byte[] getByteArray(Cell header, Table table, Cell footer, int height) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(outputStream);
PdfDocument pdf = new PdfDocument(writer);
Rectangle rectangle = new Rectangle(135f, height);
PageSize pageSize = new PageSize(rectangle);
pdf.setDefaultPageSize(pageSize);
Document doc = new Document(pdf);
doc.setMargins(0, 0, 0, 0);
doc.add(header);
doc.add(table);
doc.add(footer);
doc.close(); ------- Exception thrown here!!!
return outputStream.toByteArray();
}
3.Текст кода ядра, выдавший исключение
private void write(PdfIndirectReference indirectReference) {
if (document != null && !indirectReference.getDocument().equals(document)) {
throw new PdfException(PdfException.PdfIndirectObjectBelongsToOtherPdfDocument);
}
...
}
PS1. I Я использую сервисы Spring для создания таблиц, шрифтов и т. д. c.
PS2. Версия Itext - 7.1.10
Спасибо.