Solved

iTextSharp PDF Template how to remove empty field lines?

Posted on 2015-01-09
5
673 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a complete list of ASP.NET page load events 3 26
Error in page 3 45
Anyway to make "All" the default in the dropdown? 6 34
Data is not showing from images 15 37
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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now