Solved

iTextSharp PDF Template how to remove empty field lines?

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

816 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

8 Experts available now in Live!

Get 1:1 Help Now