Streamlining Chunk Addition in ColumnText Without Storing All in JVM
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by reading ColumnText and BidiLine, which the issue identifies as handling chunk processing, and trace what happens when go() is called after each chunk. Compare that with adding multiple chunks before calling go(). The issue is resolved when streamed chunks continue on the same line where appropriate, with a test covering successive chunk additions and text flow.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hello Team,
I am working on generating a PDF book with very lengthy text (>1000 pages). Due to the large content, I encountered OutOfMemoryException when using phrase/paragraph directly and decided to use ColumnText to handle the text chunk by chunk. While this approach helps avoid memory issues, I have run into a problem where each new chunk starts on a new line within the same column. This behavior is observed when adding chunks one at a time. In contrast, adding multiple chunks before calling ct.go() works fine, with the text flowing continuously. I identified that BidiLine processes all chunks and outputs the content line by line.
Code I have tried :
public static void main(String[] args) throws Exception {
Document document = new Document(new Rectangle(842, 595));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ParagraphTest.pdf"));
document.open();
DataSupplier dataSupplier = new DataSupplier();
ColumnText ct = new ColumnText(writer.getDirectContent());
ct.setSimpleColumn(50, 50, 200, 545);
while (dataSupplier.hasMoreContent()) { // until data supplier has no more content
String text = dataSupplier.getText();
ct.addText(new Chunk(text)); // adding chunk by chunk. Each chunk may actually vary in style
while (ct.go() != ColumnText.NO_MORE_TEXT) { // if end of page is reached, creating new page and resuming
document.newPage();
ct.setSimpleColumn(50, 50, 200, 545);
}
}
document.close();
}
Is there any way to append chunks to the previous chunk on the same line? Alternatively, if there is a different class or method to achieve streaming of text, please suggest.
Thank you !
- Lingua principale
- Java
- Stelle
- 4.4k
- Fork
- 714
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di LibrePDF/OpenPDF
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
IndexOutOfBoundsException in PdfReaderForse già presa @andreasrosdalw l’ha presa 93 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
`PdfSmartCopy` can take effectively unbounded time on nested shared Form XObjectsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
Tutte le issue di LibrePDF/OpenPDF
Issue simili
-
bug web-server
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jooby-project/jooby#4035 ·
I maintainer di solito rispondono entro 1 giorno
-
L: javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
dependabot/dependabot-core#16744 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
quarkiverse/quarkus-google-cloud-services#1187 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
locationtech/jts#1250 ·
-
type/improve
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100