ITEXTSHARP FIND AND REPLACE TEXT IN PDF

A Developer. An Eweek. Long time no see. I have been given a task to replace text within an existing PDF file.

Author:Kaganris Dailkis
Country:Martinique
Language:English (Spanish)
Genre:Travel
Published (Last):23 March 2013
Pages:204
PDF File Size:7.26 Mb
ePub File Size:13.57 Mb
ISBN:273-8-16037-551-6
Downloads:19648
Price:Free* [*Free Regsitration Required]
Uploader:Moogushakar



A Developer. An Eweek. Long time no see. I have been given a task to replace text within an existing PDF file. I played around with iTextSharp and is halfway.

I did come accross an excellent sample on the CodeBank by stanav, which I have been using. Now, I know that you cannot replace the existing text on the file, because a PDF document is not a Word document as such.

So my way of thinking is to draw a block around the existing text, and resave the file. For this, I need help. This is my code: Code: Imports System. IO Imports System. Text Imports System. Generic Imports System. Linq Imports iTextSharp. Object, ByVal e As System.

EventArgs Handles Button1. Click ParsePdfText Application. Append token. Show "Exception occured. Message Return String. Empty End Try Return sb. Create ' step 3 document. Open ' step 4 document. Add New Paragraph "Hello World! Convert Encoding. UTF8, Encoding. GetBytes currentText text.

Append currentText pdfReader. Close Next End If Return text. Can any one help an old dumb guy out please? After doing a Google search and reading lots of answers saying "it can't be done" I found this one.

The idea in the answer given there is just taking Class LocationTextExtractionStrategy from iTextSharp sourcecode to your Project, because it contains these coordinates you need.

I don't have time right now to investigate further, but i'll take a look later, having these coordinates the rest should be easy. Last edited by jcis; Jun 6th, at PM. Thanks for all your kind help. StringValue RichTextBox1. Close reader. Text Imports iTextSharp. Append chunk. Append " "c End If sb. Append ControlChars. Lf sb. PrintDiagnostics Console. RenderListener renderText com.

GetText , segment. GetStartPoint , segment. GetEndPoint , renderInfo. GetSingleSpaceWidth locationalResult. Subtract startLocation. Truncate Math. Atan2 orientationVector Vector. I2 , orientationVector Vector. Subtract origin. Cross orientationVector Vector. Comparable compareTo java. IComparable Of TextChunk. I am missing a trick somewhere. Any advice? Doing this would be easier just by making some modifications in iTextSharp dll but i don't want to give a solution that would require recompiling this dll sourcecode.

But i'm getting closer, i'll post back just after I get this part about placing blank blocks over words or phrases. About the Replace idea that comes after all this adding other text over this blank rectangles , this has known limitations like: the text you add in the Overcontent layer won't be available when the user searches the document, and also, if you replace a large word or phrase with another much shorter word or phrase there will be a big portion of the blank rect not being covered, not a very nice visual effect.

Last edited by jcis; Jun 13th, at PM. Add the reference to your iTextSharp dll. See the comments in code. In the call you should specify the text to search, compare method, source and destination file paths. I'm not sure what's the best way to make solid white rectangles but If you remove line cb. Report back if you find an error or any weird behavior, or if there is something else to add, for example adding different text where the words have been removed or whatever.

Attached Files Test. Words cannot describe your kindness. Your way of doing things are way more simpler than mine. I'm getting old. My brain is not what it used to be. Thank you for helping me! I need little help from you in this regard that i am using VS i. C also getting complie errors in below code. Error 1 SameLine ThisLineChunks. Last Then Error 2 :- ElementAt is.

ElementAt LastChunk. FontIndex So could you please help me in sharing c i. Framework 2. Your code will be of great help. I am using a modified version of the test solution which creates the new file where i need it to be but when i go to open it i get the error There was an error opening this document.

NET VB. Register Help. Remember Me? Advertiser Disclosure. Advanced Search. Results 1 to 10 of This is my code: Code:. Reply With Quote. Just in case you didn't consider this alternative here is a link where it's explained: Using a template to programmatically create PDFs with C and iTextSharp. Re: "replace" Words in PDF file using iTextSharp And about the method you described placing blocks to blanking words using OverContent layer , the only thing that's going to be difficult to accomplish is getting the matching words x,y coordinates in the document.

This is what I have done so far : Code:. Last edited by jcis; Jul 30th, at PM. Thanks, RK Tech. The file is damaged and could not be repaired. Quick Navigation Visual Basic. Better understand the signs that your business has outgrown its current database.

TRATADO DE PATOLOGIA QUIRURGICA SABISTON PDF

Subscribe to RSS

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I' ve been searching the Internet for 2 Weeks and found some interesting solutions for my Problem, but nothing seems to give me the answer. I would like to keep the design of the content. Is it really that hard? This keeps the formatation of the rest of text and does only change my searched text. I need a solution for text which is NOT in a Textfield.

ARCHIVOS LACERTA PDF

How to replace specific word in pdf using itextsharp C#.net

.

Related Articles