Solved

iTextSharp PDF Template how to remove empty field lines?

Posted on 2015-01-09
5
786 Views
Last Modified: 2015-01-26
Hello all,

I have a PDF Template I am using the PDF Reader and AcroFields to do SetFields of the form.   It works and fills the data but I need to somehow collapse if for example an Address 2 or Address 3 line is empty on the form.   Is that possible and if so accomplished in the template itself or via iTextSharp?   I tried RemoveField but doesn't seem to do anything.
0
Comment
Question by:sbornstein2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 12

Accepted Solution

by:
Ammar Gaffar earned 500 total points
ID: 40543775
If removing fields is accepted solution for your case, then this can be done, but there is an important point, you need to have a copy of original template every time you fill it using iTextSharp, because if you removed the field you need to save the template (overwrite if you didn't use a copy of original template). Here if the next form contains address for example which is removed already from the first filling process then you have an error.

RemoveFields() method will not work when your PDF template is created using Adobe LifeCycle, there is limitation for iTextSharp with this kind of files (XFA), but if you created your template in Adobe Acrobat then it must work.

Check this link:
https://pthok.wordpress.com/2010/12/16/itextsharp-removing-fields-from-pdf-templates/

Good Luck
0
 

Author Comment

by:sbornstein2
ID: 40544236
I created the file in adobe acrobat but the remove field does not remove the empty line on the page.  So for example I have Address Line 2 and Line 3 below it.  Nothing else on the pdf to the right of these fields.  When Line 2 is null it calls the remove field on the textbox and the empty line still shows.
0
 

Author Comment

by:sbornstein2
ID: 40544367
Here is an example where you can see the lines are still blank.  I tried RemoveField and also tried this:

PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
                    newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;

pdfFormFields.SetFieldProperty("txtBillToLine2", "setfflags", PdfAnnotation.FLAGS_HIDDEN, null);
pdfFormFields.SetFieldProperty("txtBillToLine3", "setfflags", PdfAnnotation.FLAGS_HIDDEN, null);

also tried:
pdfFormFields.SetFieldProperty("txtBillToLine2", "setfflags", PdfAnnotation.FLAGS_INVISIBLE, null);
pdfFormFields.SetFieldProperty("txtBillToLine3", "setfflags", PdfAnnotation.FLAGS_INVISIBLE, null);

still no luck   Here is the image:
Capture.PNG
0
 

Author Comment

by:sbornstein2
ID: 40544383
The remove field seems to work but its the shifting to get rid of the empty lines that does not work.
0
 

Author Comment

by:sbornstein2
ID: 40544384
I need those empty lines to suppress so the lines would move up.
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update 21-May-2015: I temporarily removed the source code to make major changes to the program. Regards, Joe In a previous Experts Exchange article, How To Rename-Move a Batch of PDF Files Based on Contents of the Files (http://www.experts-exchan…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question