Draw on existing PDDocument?
Hi,
I'm trying to create a document that have a table in it:
/-----------------------
| text text text |
| text text text |
|---|
| ------------------ |
| text text text |
| -----------------------/ |
I'm using pdfbox-layout for the first text paragraph than https://github.com/dhorions/boxable for the table, when I want to use pdfbox-layout again I'm encountering an issue. I cannot use pdfbox on an existing pddocument, there is no api for setting one, just creating one.
so if I do doc.getPDDocument() I receive a document without pages, adding a page manually and drawing the table and continuing adding paragraphs before the actual render gives me a table on the first page and all the text in the next pages. if I do doc.render() I can put the table on the same page as the first text but I can't draw after the table since rendering twice removes the table I drew on the previously rendered document...
My workaround was to render the text, then the table, then the text after the table end position, then render the table again on the PDDocument...
Hello ronzeidman, I face a similar problem. Can you please show me the piece of code for adding text after inserting the table for the first time? Thanks and best regards Carsten
Something like this:
Document doc = new Document(...);
float yPos = topMargin;
doc.add(paragraph1);
yPos += paragraph1.getHeight()
doc.add(paragraph2);
yPos += paragraph2.getHeight()
doc.add(paragraph3);
yPos += paragraph3.getHeight()
int pageNum = 0;
PDDocument noTableDoc = doc.render();
PDDocument tableDoc = null;
while (yPos > PDRectangle.A4.getHeight()) {
yPos -= PDRectangle.A4.getHeight();
pageNum++;
}
//The drawTable does returns "table.draw();" (new BaseTable(PDRectangle.A4.getHeight() - yPos,... ,... ,... ,... ,document.getPage(pageNum), ...))
float tableYPos = PDRectangle.A4.getHeight() - drawTable(noTableDoc, pageNum, yPos, boldFont, font, info);
int numberOfPages = noTableDoc.getNumberOfPages() - 1 - pageNum;
float newTopMargin = numberOfPages * PDRectangle.A4.getHeight() + tableYPos - yPos;
doc.add(...);
doc.add(...);
doc.add(...);
doc.add(...);
tableDoc = doc.render();
drawTable(tableDoc, pageNum, yPos, boldFont, font, info);
Hi, I'm trying to create a document that have a table in it: /----------------------- | text text text |
text text text
text text text -----------------------/ I'm using pdfbox-layout for the first text paragraph than https://github.com/dhorions/boxable for the table, when I want to use pdfbox-layout again I'm encountering an issue. I cannot use pdfbox on an existing pddocument, there is no api for setting one, just creating one. so if I do
doc.getPDDocument()I receive a document without pages, adding a page manually and drawing the table and continuing adding paragraphs before the actual render gives me a table on the first page and all the text in the next pages. if I dodoc.render()I can put the table on the same page as the first text but I can't draw after the table since rendering twice removes the table I drew on the previously rendered document...My workaround was to render the text, then the table, then the text after the table end position, then render the table again on the PDDocument...
What did you do to load the PDDocument content inside a Document of pdf-box? I want to add a paragraph of a Document inside a defined PDDocument but it just showed white page...
Did anyone resolve this issue?
It would be awesome if it would be possible to get the original org.apache.pdfbox.pdmodel.PDDocument from the rst.pdfbox.layout.elements.Document class.
Anyone combined ralfstuckert's lib with the boxable?