65570

itext pdf verify if signature is visible or invisible

Question:

I am currently using Itext 5.4.4 and I would like to know if it is possible to check if a signature in my current PDF is visible or invisible. Is this possible? Or do I have to upgrade to a newer versión of Itext?

Answer1:

You can do it like the code below. Other flags are easily added..

PdfReader reader; //instantiate AcroFields acroFields = reader.getAcroFields(); Map<String, Item> fieldNames = acroFields.getFields(); Set<Entry<String, Item>> entries = fieldNames.entrySet(); Iterator<Entry<String, Item>> it = entries.iterator(); while(it.hasNext()){ Entry<String, Item> entry = it.next(); //Check flags boolean invisible = isInvisible(entry.getValue()); boolean mandatory = isMandatory(entry.getValue()); boolean noView = isNoView(entry.getValue()); boolean hidden = isHidden(entry.getValue()); ... } public static boolean isInvisible(Item item) { //Add a nullcheck! if(item.size()>0) { PdfDictionary d = item.getMerged(0); PdfNumber num = (PdfNumber) d.get(PdfName.F); return num == null ? false : ((num.intValue() & PdfAnnotation.FLAGS_INVISIBLE) == PdfAnnotation.FLAGS_INVISIBLE); } return false; } public static boolean isMandatory(Item item) { //Add a null check here! if(item.size()>0) { PdfDictionary d = item.getMerged(0); PdfNumber num = (PdfNumber) d.get(PdfName.FF); return num == null ? false : ((num.intValue() & PdfFormField.FF_REQUIRED) == PdfFormField.FF_REQUIRED); } return false; } public static boolean isNoView(Item item) { //nullcheck! if(item.size()>0) { PdfDictionary d = item.getMerged(0); PdfNumber num = (PdfNumber) d.get(PdfName.F); return num == null ? false : ((num.intValue() & PdfAnnotation.FLAGS_NOVIEW) == PdfAnnotation.FLAGS_NOVIEW); } return false; } public static boolean isHidden(Item item) { //Nullcheck! if(item.size()>0) { PdfDictionary d = item.getMerged(0); PdfNumber num = (PdfNumber) d.get(PdfName.F); return num == null ? false : ((num.intValue() & PdfAnnotation.FLAGS_HIDDEN) == PdfAnnotation.FLAGS_HIDDEN); } return false; }

Recommend

  • Add image to iText dynamically on PDF file
  • itextsharp setting the stamper FormFlatttening=true results in no output
  • LTV of Certifying Signatures
  • How to insert a PdfPTable into an existing PDF template?
  • Using iText to fill text field background
  • How do I get a TextField from AcroFields using iText/Sharp?
  • How to get font size of form field on iText7?
  • iTextSharp PDF form field validation
  • ITextsharp to edit existing pdf
  • Making editable cells of a table readonly having Scroll Bar with itext
  • How to populate mongoose with a large data set
  • Perl-Using same variable for nested loops considered improper?
  • Is boost::filesystem::directory_iterator invalidated by deletion?
  • Run-time error when deleting a named range
  • How to remove the marker in Google map v2?
  • Index of vector iterator
  • java.lang.NullPointerException: No FileItemFactory has been set
  • check if numbers have the same sign
  • Sorting a HashMap, while keeping duplicates
  • Simplify where clause with repeated associated type restrictions
  • Can Jackson SerializationFeature be overridden per field or class?
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • script to move all files from one location to another location
  • AT Commands to Send SMS not working in Windows 8.1
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • apache spark aggregate function using min value
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • Running Map reduces the dimensions of the matrices
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Android Heatmap on canvas or ImageView
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How to push additional view controllers onto NavigationController but keep the TabBar?