You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Thiruppathi M." <th...@sps.co.in> on 2016/06/02 10:15:07 UTC

RE: Replace text and adjust text positon

Hi,

Sorry for the delay. Please download the file using the below link,

Input file:

https://www.dropbox.com/s/vsvpiiyvgwgzexn/input.pdf?dl=0

output file:

https://www.dropbox.com/s/hikjsy7ayjg3ful/after_replace.pdf?dl=0


here i need to replace and adjust the text (refer input and output file)

"2015 Elsevier Ltd. All rights reserved." To "2016 The Author. Production and hosting by Elsevier B.V. on behalf of King Saud University. This is an
open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/)."


Case1:

If content length is small, set text based on end position of pdf text area content length.

For example:

						                  			   "2015 Elsevier Ltd. All rights reserved."
 
			                    		    "2015 Civil-Comp Ltd and Elsevier Ltd. All rights reserved."



Case2: 

If the content length is large, set the text based on start position and end position of pdf text area content length and wrap the text to next line.

For example:

"2016 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://
										     creativecommons.org/licenses/by-nc-nd/4.0/)."

Please advice.

Regards
Thiruppathi M.

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: 24 May 2016 AM 01:05
To: users@pdfbox.apache.org
Subject: Re: Replace text and adjust text positon

Hi,

You attached a .docx file, no idea why this got through. I never open 
.docx files from people I don't know.

Please upload screenshots as images somewhere, e.g. imageshack. PDF 
files can be uploaded to a sharehoster, eg. filedropper.com

Tilman

Am 23.05.2016 um 09:00 schrieb Thiruppathi M.:
> Hi,
>
> Please find the attached docx.
>
>
> Regards
> Thiruppathi M.
>
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: 21 May 2016 PM 04:41
> To: users@pdfbox.apache.org
> Subject: Re: Replace text and adjust text positon
>
> Hi,
>
> Attachments don't go through, please upload them somewhere.
>
> Replacing text is difficult, sometimes impossible, see "Why was the
> ReplaceText example removed"https://pdfbox.apache.org/2.0/migration.html
>
> It can be done only if the formats are similar, i.e. from the same source.
>
> Tilman
>
> Am 21.05.2016 um 08:45 schrieb Thiruppathi M.:
>> Hi,
>>
>> We are using Pdfbox for our internal pdf file automation.
>>
>> We struck in line adjustment.
>>
>> Refer the below input pdf file screen shot:
>>
>> For example:
>>
>> Here we need to replace the content "2016 Elsevier Ltd. All rights
>> reserved." To below mention format
>>
>> Case1:
>>
>> Case2:
>>
>> Please advice how to achieve.
>>
>> Regards
>>
>> Thiruppathi M.
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Replace text and adjust text positon

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 03.06.2016 um 12:19 schrieb Thiruppathi M.:
> Hi,
>
> I tried one way to solve this. But i can't set the exact the value for match with pdf text line start and end position.
>
> For example input.pdf content
>   
> COSName{F8}, COSInt{1}, PDFOperator{Tf}, COSFloat{18.4316}, COSFloat{-1.3357}, PDFOperator{TD}, COSString{}, PDFOperator{Tj}, COSName{F3}, COSInt{1}, PDFOperator{Tf}, COSFloat{1.1159}, COSInt{0}, PDFOperator{TD}, COSArray{[COSString{2015}, COSFloat{-326.5}, COSString{Elsevier}, COSFloat{-332.7}, COSString{Ltd.}, COSFloat{-324.8}, COSString{All}, COSFloat{-325.4}, COSString{rights}, COSFloat{-326.5}, COSString{reserved.}]}

That part is in the middle of the document.

/F8 1 Tf
18.4316 -1.3357 TD
(\001) Tj
/F3 1 Tf
1.1159 0 TD
[ (2015) -326.5 (Elsevier) -332.7 (Ltd.) -324.8 (All) -325.4 (rights) 
-326.5 (reserved.) ] TJ


TD is relative, so you would have to calculate the current position 
based on previous TDs and Tm operators (and others that may change the 
current transformation matrix or the text matrix (see in the PDF spec 
what this means))

One way to do this would be to extend PDFStreamEngine... see in the 
source code how to get the current transformation matrix, and the text 
matrix. The best would be to debug to see what is done.

>
> Here the text position is changed while i reduce the COSFloat{18.4316} value to COSFloat{-11.2842}.
> 	
> The replacement is done through the pdfbox coding.(Refer after_replace.pdf).
>
> How to find increase or decrease the value?

This is tricky because
1) You have no guarantee that the pdf has a content like the one above
2) even if it has, you would have to know what transformations (scaling, 
translating, rotating) are done before.

at the bottom of the document it is a bit easier:

6.548 0 0 6.376 42.5197 57.0898 Tm
0 0.5 0.68 rg
(http://dx.doi.org/10.1016/j.bmc.2015.11.045) Tj
0 0 0 rg
0 -1.3426 TD
(0968-0896/) Tj
/F8 1 Tf
5.4026 0 TD
(\001) Tj
/F3 1 Tf
1.1169 0 TD
[ (2015) -328.4 (Elsevier) -322.2 (Ltd.) -327.7 (All) -324.4 (rights) 
-320.7 (reserved.) ] TJ
ET

I also looked at the rest, I found no other transformation (Tm "sets" 
only, it isn't relative to a previous TD or Td).
6.548 0 0 6.376 42.5197 57.0898 Tm
means that it is scaled by about 6.5 and then moved to (42.5197 
57.0898). One unit is 1/72 inch.

Sorry I can't come up with a quick solution. If this had been my 
assignment, I would
- ask for all files
- then need several hours to decide what strategy, if any
. implement it (might take a day)
- then check all files whether the strategy works (i.e. that I "catch" 
all occurences)

Tilman

>
> Please advice.
>
> Regards
> Thiruppathi M.
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: 02 June 2016 PM 11:41
> To: users@pdfbox.apache.org
> Subject: Re: Replace text and adjust text positon
>
> Am 02.06.2016 um 12:15 schrieb Thiruppathi M.:
>> Hi,
>>
>> Sorry for the delay. Please download the file using the below link,
>>
>> Input file:
>>
>> https://www.dropbox.com/s/vsvpiiyvgwgzexn/input.pdf?dl=0
>>
>> output file:
>>
>> https://www.dropbox.com/s/hikjsy7ayjg3ful/after_replace.pdf?dl=0
>>
>>
>> here i need to replace and adjust the text (refer input and output file)
>>
>> "2015 Elsevier Ltd. All rights reserved." To "2016 The Author. Production and hosting by Elsevier B.V. on behalf of King Saud University. This is an
>> open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/)."
>>
>>
>> Case1:
>>
>> If content length is small, set text based on end position of pdf text area content length.
>>
>> For example:
>>
>> 						                  			   "2015 Elsevier Ltd. All rights reserved."
>>    
>> 			                    		    "2015 Civil-Comp Ltd and Elsevier Ltd. All rights reserved."
> Try the PrintTextLocations example, this shows where the text is. But it
> will be tricky... you could try to limit it to an area, and then decide
> which part is relevant.
>
> As I said, you can't replace the text. You could draw a blank rectangle
> over the existing text.
>
> To create a link, see the AddAnnotations.java example in the source code
> download.
>
> To see how to output text, see the EmbeddedFonts.java example.
>
> To append a content stream to an existing stream, use the constructor of
> PDPageContentStream with the fifth parameter set to true to avoid surprises.
>
> Tilman
>
>>
>>
>> Case2:
>>
>> If the content length is large, set the text based on start position and end position of pdf text area content length and wrap the text to next line.
>>
>> For example:
>>
>> "2016 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://
>> 										     creativecommons.org/licenses/by-nc-nd/4.0/)."
>>
>> Please advice.
>>
>> Regards
>> Thiruppathi M.
>>
>> -----Original Message-----
>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>> Sent: 24 May 2016 AM 01:05
>> To: users@pdfbox.apache.org
>> Subject: Re: Replace text and adjust text positon
>>
>> Hi,
>>
>> You attached a .docx file, no idea why this got through. I never open
>> .docx files from people I don't know.
>>
>> Please upload screenshots as images somewhere, e.g. imageshack. PDF
>> files can be uploaded to a sharehoster, eg. filedropper.com
>>
>> Tilman
>>
>> Am 23.05.2016 um 09:00 schrieb Thiruppathi M.:
>>> Hi,
>>>
>>> Please find the attached docx.
>>>
>>>
>>> Regards
>>> Thiruppathi M.
>>>
>>>
>>> -----Original Message-----
>>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>>> Sent: 21 May 2016 PM 04:41
>>> To: users@pdfbox.apache.org
>>> Subject: Re: Replace text and adjust text positon
>>>
>>> Hi,
>>>
>>> Attachments don't go through, please upload them somewhere.
>>>
>>> Replacing text is difficult, sometimes impossible, see "Why was the
>>> ReplaceText example removed"https://pdfbox.apache.org/2.0/migration.html
>>>
>>> It can be done only if the formats are similar, i.e. from the same source.
>>>
>>> Tilman
>>>
>>> Am 21.05.2016 um 08:45 schrieb Thiruppathi M.:
>>>> Hi,
>>>>
>>>> We are using Pdfbox for our internal pdf file automation.
>>>>
>>>> We struck in line adjustment.
>>>>
>>>> Refer the below input pdf file screen shot:
>>>>
>>>> For example:
>>>>
>>>> Here we need to replace the content "2016 Elsevier Ltd. All rights
>>>> reserved." To below mention format
>>>>
>>>> Case1:
>>>>
>>>> Case2:
>>>>
>>>> Please advice how to achieve.
>>>>
>>>> Regards
>>>>
>>>> Thiruppathi M.
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: Replace text and adjust text positon

Posted by "Thiruppathi M." <th...@sps.co.in>.
Hi,

I tried one way to solve this. But i can't set the exact the value for match with pdf text line start and end position.

For example input.pdf content 
 
COSName{F8}, COSInt{1}, PDFOperator{Tf}, COSFloat{18.4316}, COSFloat{-1.3357}, PDFOperator{TD}, COSString{}, PDFOperator{Tj}, COSName{F3}, COSInt{1}, PDFOperator{Tf}, COSFloat{1.1159}, COSInt{0}, PDFOperator{TD}, COSArray{[COSString{2015}, COSFloat{-326.5}, COSString{Elsevier}, COSFloat{-332.7}, COSString{Ltd.}, COSFloat{-324.8}, COSString{All}, COSFloat{-325.4}, COSString{rights}, COSFloat{-326.5}, COSString{reserved.}]}

Here the text position is changed while i reduce the COSFloat{18.4316} value to COSFloat{-11.2842}.
	
The replacement is done through the pdfbox coding.(Refer after_replace.pdf).

How to find increase or decrease the value?

Please advice.

Regards
Thiruppathi M.

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: 02 June 2016 PM 11:41
To: users@pdfbox.apache.org
Subject: Re: Replace text and adjust text positon

Am 02.06.2016 um 12:15 schrieb Thiruppathi M.:
> Hi,
>
> Sorry for the delay. Please download the file using the below link,
>
> Input file:
>
> https://www.dropbox.com/s/vsvpiiyvgwgzexn/input.pdf?dl=0
>
> output file:
>
> https://www.dropbox.com/s/hikjsy7ayjg3ful/after_replace.pdf?dl=0
>
>
> here i need to replace and adjust the text (refer input and output file)
>
> "2015 Elsevier Ltd. All rights reserved." To "2016 The Author. Production and hosting by Elsevier B.V. on behalf of King Saud University. This is an
> open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/)."
>
>
> Case1:
>
> If content length is small, set text based on end position of pdf text area content length.
>
> For example:
>
> 						                  			   "2015 Elsevier Ltd. All rights reserved."
>   
> 			                    		    "2015 Civil-Comp Ltd and Elsevier Ltd. All rights reserved."

Try the PrintTextLocations example, this shows where the text is. But it 
will be tricky... you could try to limit it to an area, and then decide 
which part is relevant.

As I said, you can't replace the text. You could draw a blank rectangle 
over the existing text.

To create a link, see the AddAnnotations.java example in the source code 
download.

To see how to output text, see the EmbeddedFonts.java example.

To append a content stream to an existing stream, use the constructor of 
PDPageContentStream with the fifth parameter set to true to avoid surprises.

Tilman

>
>
>
> Case2:
>
> If the content length is large, set the text based on start position and end position of pdf text area content length and wrap the text to next line.
>
> For example:
>
> "2016 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://
> 										     creativecommons.org/licenses/by-nc-nd/4.0/)."
>
> Please advice.
>
> Regards
> Thiruppathi M.
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: 24 May 2016 AM 01:05
> To: users@pdfbox.apache.org
> Subject: Re: Replace text and adjust text positon
>
> Hi,
>
> You attached a .docx file, no idea why this got through. I never open
> .docx files from people I don't know.
>
> Please upload screenshots as images somewhere, e.g. imageshack. PDF
> files can be uploaded to a sharehoster, eg. filedropper.com
>
> Tilman
>
> Am 23.05.2016 um 09:00 schrieb Thiruppathi M.:
>> Hi,
>>
>> Please find the attached docx.
>>
>>
>> Regards
>> Thiruppathi M.
>>
>>
>> -----Original Message-----
>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>> Sent: 21 May 2016 PM 04:41
>> To: users@pdfbox.apache.org
>> Subject: Re: Replace text and adjust text positon
>>
>> Hi,
>>
>> Attachments don't go through, please upload them somewhere.
>>
>> Replacing text is difficult, sometimes impossible, see "Why was the
>> ReplaceText example removed"https://pdfbox.apache.org/2.0/migration.html
>>
>> It can be done only if the formats are similar, i.e. from the same source.
>>
>> Tilman
>>
>> Am 21.05.2016 um 08:45 schrieb Thiruppathi M.:
>>> Hi,
>>>
>>> We are using Pdfbox for our internal pdf file automation.
>>>
>>> We struck in line adjustment.
>>>
>>> Refer the below input pdf file screen shot:
>>>
>>> For example:
>>>
>>> Here we need to replace the content "2016 Elsevier Ltd. All rights
>>> reserved." To below mention format
>>>
>>> Case1:
>>>
>>> Case2:
>>>
>>> Please advice how to achieve.
>>>
>>> Regards
>>>
>>> Thiruppathi M.
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Replace text and adjust text positon

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 02.06.2016 um 12:15 schrieb Thiruppathi M.:
> Hi,
>
> Sorry for the delay. Please download the file using the below link,
>
> Input file:
>
> https://www.dropbox.com/s/vsvpiiyvgwgzexn/input.pdf?dl=0
>
> output file:
>
> https://www.dropbox.com/s/hikjsy7ayjg3ful/after_replace.pdf?dl=0
>
>
> here i need to replace and adjust the text (refer input and output file)
>
> "2015 Elsevier Ltd. All rights reserved." To "2016 The Author. Production and hosting by Elsevier B.V. on behalf of King Saud University. This is an
> open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/)."
>
>
> Case1:
>
> If content length is small, set text based on end position of pdf text area content length.
>
> For example:
>
> 						                  			   "2015 Elsevier Ltd. All rights reserved."
>   
> 			                    		    "2015 Civil-Comp Ltd and Elsevier Ltd. All rights reserved."

Try the PrintTextLocations example, this shows where the text is. But it 
will be tricky... you could try to limit it to an area, and then decide 
which part is relevant.

As I said, you can't replace the text. You could draw a blank rectangle 
over the existing text.

To create a link, see the AddAnnotations.java example in the source code 
download.

To see how to output text, see the EmbeddedFonts.java example.

To append a content stream to an existing stream, use the constructor of 
PDPageContentStream with the fifth parameter set to true to avoid surprises.

Tilman

>
>
>
> Case2:
>
> If the content length is large, set the text based on start position and end position of pdf text area content length and wrap the text to next line.
>
> For example:
>
> "2016 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://
> 										     creativecommons.org/licenses/by-nc-nd/4.0/)."
>
> Please advice.
>
> Regards
> Thiruppathi M.
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: 24 May 2016 AM 01:05
> To: users@pdfbox.apache.org
> Subject: Re: Replace text and adjust text positon
>
> Hi,
>
> You attached a .docx file, no idea why this got through. I never open
> .docx files from people I don't know.
>
> Please upload screenshots as images somewhere, e.g. imageshack. PDF
> files can be uploaded to a sharehoster, eg. filedropper.com
>
> Tilman
>
> Am 23.05.2016 um 09:00 schrieb Thiruppathi M.:
>> Hi,
>>
>> Please find the attached docx.
>>
>>
>> Regards
>> Thiruppathi M.
>>
>>
>> -----Original Message-----
>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>> Sent: 21 May 2016 PM 04:41
>> To: users@pdfbox.apache.org
>> Subject: Re: Replace text and adjust text positon
>>
>> Hi,
>>
>> Attachments don't go through, please upload them somewhere.
>>
>> Replacing text is difficult, sometimes impossible, see "Why was the
>> ReplaceText example removed"https://pdfbox.apache.org/2.0/migration.html
>>
>> It can be done only if the formats are similar, i.e. from the same source.
>>
>> Tilman
>>
>> Am 21.05.2016 um 08:45 schrieb Thiruppathi M.:
>>> Hi,
>>>
>>> We are using Pdfbox for our internal pdf file automation.
>>>
>>> We struck in line adjustment.
>>>
>>> Refer the below input pdf file screen shot:
>>>
>>> For example:
>>>
>>> Here we need to replace the content "2016 Elsevier Ltd. All rights
>>> reserved." To below mention format
>>>
>>> Case1:
>>>
>>> Case2:
>>>
>>> Please advice how to achieve.
>>>
>>> Regards
>>>
>>> Thiruppathi M.
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org