From users-return-11067-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Thu May 24 18:05:12 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 3F171180636 for ; Thu, 24 May 2018 18:05:12 +0200 (CEST) Received: (qmail 773 invoked by uid 500); 24 May 2018 16:05:06 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Delivered-To: moderator for users@pdfbox.apache.org Received: (qmail 52627 invoked by uid 99); 24 May 2018 15:11:39 -0000 In-Reply-To: Subject: Re: Add Text To A PDF Document x-ponymail-agent: PonyMail Composer/0.3 References: X-Mailer: LuaSocket 3.0-rc1 Message-ID: Content-Type: text/plain; charset=utf-8 MIME-Version: 1.0 To: x-ponymail-sender: 937f226ee250af06ef7157c469b7e39abe2ba947 Date: Thu, 24 May 2018 15:11:38 -0000 From: a@awews.com I was able to get it to work. I just have to fine tune where the text goes. Here's my solution for anyone needing help in the future. Thank you for your help! If you have a moment, please let me know if there's a more efficient way to do it. `@SpringBootApplication public class Pdfbox1Application { public static void main(String[] args) throws IOException { SpringApplication.run(Pdfbox1Application.class, args); File file = new File("./i-90.pdf"); PDDocument document = null; PDDocument doc = document .load(file); PDPage page = doc.getPage(1); PDPageContentStream.AppendMode appendContent; PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true); doc.setAllSecurityToBeRemoved(true); try { contentStream.beginText(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { contentStream.setFont(PDType1Font.TIMES_ROMAN, 12); contentStream.newLineAtOffset(25, 700); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String text = "This is sample text"; // try { // contentStream = new PDPageContentStream(doc, page); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } try { contentStream.showText(text); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { contentStream.endText(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("content added"); try { contentStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { doc.save("./newi-90.pdf"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { doc.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ` On 2018/05/16 22:44:49, A Brand wrote: > I'd like to add text to an existing pdf document. I attempted it and the > current page was erased and replaced with the text I wanted to add. > I tried using the Overlay() and didn't see the text added. > > Is this a feature of pdfbox? > > Onward. > Don't Be Good. Be Great. Be Grateful. > > Please note this message was edited for brevity and clarity. > > Best regards, > Anthony McDonald > > > *602-456-9335* > http://www.idnkhtw.space > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org