Solved

iTextSharp PDF Template how to remove empty field lines?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

*Adobe Acrobat 9 was used for this article. Particular steps may vary depending on software versions. 1. Create a framework of your form in Word, leaving space where you’d ultimately like the Adobe fields to appear.  (Note: I use the blank lines …
PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

726 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