pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "T. Groch" <t.gr...@gmail.com>
Subject Re: Edit existing PDF
Date Fri, 12 Nov 2010 11:12:55 GMT
Hi,

since there was no other option, I just splitted the three-paged-PDF file
and made an overlay to the first page. Afterwards, I merged the PDF again.
So, this is not really clean, but it works.
If anyone has a better idea, please let me know.
Thanks in advance.

Best regards,

Tobias



2010/11/10 T. Groch <t.groch@gmail.com>

> Hi Adam,
>
> thanks, the tip with try-catch-finally makes sense. My code is just one of
> some tries without being clean ;)
> I hope someone else has got another idea.
>
> Originally I tried PDFBox since I wanted to overlay two PDF files. This
> works well (generating one with the string and overlaying it to another
> one).
> But that just works with a single paged file. I got exceptions if I try to
> overlay two three-page-PDF files (since I don't want the string on every
> page).
>
> Hopefully no one will be upset if I just ask if there's another framework
> to get a string inside an already existing PDF?!
>
> Thanks in advance.
>
> Best regards,
>
> Tobias
>
>
> 2010/11/10 <Adam@swmc.com>
>
>> The code you have is replacing the old content stream with the new
>> PDPageContentStream.  So what you describe is exactly what I'd expect.  I
>> don't know how to accomplish what you're trying to do though.
>>
>> On a side note, make sure you always call PDDocument.load() in a try block
>> and have doc.close() in the finally block.  This will make sure your
>> documents are always closed properly.
>>
>> ----
>> Thanks,
>> Adam
>>
>>
>>
>> From:
>> "T. Groch" <t.groch@gmail.com>
>> To:
>> users@pdfbox.apache.org
>> Date:
>> 11/10/2010 09:49
>> Subject:
>> Re: Edit existing PDF
>>
>>
>>
>> Hi Adam,
>>
>> thank you for that tip. In the meantime I managed to get that List of
>> PDPages, too. But when I change a PDPage it will be empty (except the text
>> I
>> put in it).
>>
>> Code:
>> PDDocument doc = PDDocument.load(fileFoo);
>> PDDocumentCatalog cat = doc.getDocumentCatalog();
>> List list = cat.getAllPages();
>> PDPage page = (PDPage) list.get(0);
>> PDFont font = PDType1Font.HELVETICA_BOLD;
>> PDPageContentStream cs = new PDPageContentStream(doc, page);
>> cs.beginText();
>> cs.setFont(font, 10);
>> cs.moveTextPositionByAmount(100, 761);
>> cs.drawString("Hans Wurst");
>> cs.endText();
>> cs.close();
>> doc.save("c:\\foo.pdf");
>>
>> So, I have the String "Hans Wurst" on the first page, but the original
>> content is gone. It's just a blank page with the string.
>> Thanks in advance.
>>
>> Best regards,
>>
>> Tobias
>>
>> 2010/11/10 <Adam@swmc.com>
>>
>> > Getting the PDPage from a file is easy.  Check this out:
>> >
>> > PDDocument source = null;
>> > try {
>> >        source = PDDocument.load("/home/user/adobe1.7spec.pdf");
>> >        List<PDPage> pages = source.getDocumentCatalog().getAllPages();
>> > } finally {
>> >        if(source != null)
>> >                try { source.close(); } catch(Exception sorry) { }
>> > }
>> >
>> > I haven't needed to edit anything other than bookmarks in my PDFs, so I
>> > can't help you on that front, but I'm sure someone else on the list will
>> > chime in shortly with some helpful pointers.
>> >
>> > ----
>> > Thanks,
>> > Adam
>> >
>> >
>> >
>> >
>> >
>> > From:
>> > "T. Groch" <t.groch@gmail.com>
>> > To:
>> > users@pdfbox.apache.org
>> > Date:
>> > 11/10/2010 04:47
>> > Subject:
>> > Edit existing PDF
>> >
>> >
>> >
>> > Hi,
>> >
>> > I just followed the example code to write some text inside a created
>> > PDPage
>> > via PDPageContentStream.
>> >
>> > How can I read in an existing PDF file and edit a page (let's say the
>> > first
>> > one) in it? I can't get a PDPage from the PDDocument.
>> > Thanks in advance.
>> >
>> > Best regards,
>> >
>> > obias
>> >
>> >
>> >
>> >
>> >
>> > - FHA 203b; 203k; HECM; VA; USDA; Conventional
>> > - Warehouse Lines; FHA-Authorized Originators
>> > - Lending and Servicing in over 45 States
>> > www.swmc.com   -  www.simplehecmcalculator.com
>> > Visit  www.swmc.com/resources   for helpful links on Training,
>> Webinars,
>> > Lender Alerts and Submitting Conditions
>> >
>> > This email and any content within or attached hereto from Sun West
>> Mortgage
>> > Company, Inc. is confidential and/or legally privileged. The information
>> is
>> > intended only for the use of the individual or entity named on this
>> email.
>> > If you are not the intended recipient, you are hereby notified that any
>> > disclosure, copying, distribution or taking any action in reliance on
>> the
>> > contents of this email information is strictly prohibited, and that the
>> > documents should be returned to this office immediately by email.
>> Receipt by
>> > anyone other than the intended recipient is not a waiver of any
>> privilege.
>> > Please do not include your social security number, account number, or
>> any
>> > other personal or financial information in the content of the email.
>> Should
>> > you have any questions, please call (800) 453 7884.
>>
>>
>>
>> - FHA 203b; 203k; HECM; VA; USDA; Conventional
>> - Warehouse Lines; FHA-Authorized Originators
>> - Lending and Servicing in over 45 States
>> www.swmc.com   -  www.simplehecmcalculator.com   Visit
>> www.swmc.com/resources   for helpful links on Training, Webinars, Lender
>> Alerts and Submitting Conditions
>> This email and any content within or attached hereto from Sun West
>> Mortgage Company, Inc. is confidential and/or legally privileged. The
>> information is intended only for the use of the individual or entity named
>> on this email. If you are not the intended recipient, you are hereby
>> notified that any disclosure, copying, distribution or taking any action in
>> reliance on the contents of this email information is strictly prohibited,
>> and that the documents should be returned to this office immediately by
>> email. Receipt by anyone other than the intended recipient is not a waiver
>> of any privilege. Please do not include your social security number, account
>> number, or any other personal or financial information in the content of the
>> email. Should you have any questions, please call (800) 453 7884.
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message