Solved

iTextSharp PDF Template how to remove empty field lines?

Posted on 2015-01-09
5
649 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I need those empty lines to suppress so the lines would move up.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

762 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

11 Experts available now in Live!

Get 1:1 Help Now