-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually positioning text on the pdf #556
Comments
I guess a simple way to rewrite the question is this: Is there a way to access the basic actions of editing a pdf? (adding a page, adding a word to a specific place on the pdf, etc.) |
OpenPdf offers lower-level APIs, too. |
Thank you so much! |
CAn you show your code so we can tell you what to change? |
` val wr = PdfWriter.getInstance(document, FileOutputStream("filepath.pdf")) val r = Rectangle(50f,50f,100f,100f) wr.setBoxSize("LETTER", r) wr.directContent.setFontAndSize(font.baseFont, font.size) wr.directContent.showTextBasic(text)` It doesn't put anything on the page. At least that I can see. |
Please be aware that you are working with a low-level API here. Thus, you have to enclose text objects with Also you do |
@Doragon-S Additionally, I'm adding a new example to the existing collection in PR #578 which extends on the above mentioned answer. This should show sufficiently how to add text in boxes at absolute positions. It also shows how to deal with possible page breaks and how to add a new page. In the most simplistic form, this is how to add a single box with some text: Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
PdfContentByte canvas = writer.getDirectContent();
ColumnText ct = new ColumnText(canvas);
ct.addElement(new Paragraph("Some text."));
ct.setSimpleColumn(200, 400, 500, 600);
ct.go();
document.close(); |
thank you |
I'd like to manually control the position of text on a pdf page.
I thought it would be convenient to have a function that adds text to the pdf starting at a specified position
someone suggested making a table, setting it to a specific point, and adding the text into there. But I haven't figured out how to do that, and I found no tutorials online.
This is the way pdfBox adds text, and since I know nothing about how to build a programming library, I'm assuming that the document.add() function ends up boiling down to something similar. If so, would it be easy to set it up as a separate accessible function?
The text was updated successfully, but these errors were encountered: