Unable to fill pdf form - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: Unable to fill pdf form

Unable to fill pdf form 2 years 4 months ago #10894

  • fdelcaz
  • fdelcaz's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 21
  • Thank you received: 0
Hi:

I´m trying to fill a pdf form on background. This is the sample code

public void fillPdf(String rutaPdf, Map<String, String> valores, Activity actividad){
try{
Log.d("GXC", "archivo a abrir: " + rutaPdf);
// obtengo el documento
Global.Init(actividad);

Document m_doc = new Document();
int ret = m_doc.Open(rutaPdf, "");


// Me quedo con el numero de paginas que tiene el documento
int i = m_doc.GetPageCount();
Page p;
int currentPage;
String property, value;
Map.Entry<String, String> entity;
Page.Annotation an;
// Recorro los diferentes valores
Iterator<Map.Entry<String, String>> it = valores.entrySet().iterator();
while (it.hasNext()) {
entity = it.next();
property = (String) entity.getKey();
value = (String) entity.getValue();
currentPage = 0;
an = null;
// Recorro las diferentes paginas
while (currentPage < i) {

Log.d("GXC", "property: " + property);
p = m_doc.GetPage(currentPage);
p.ObjsStart();

Log.d("GXC", "Arranco " + p.toString());
Log.d("GXC", "cantidad de paginas: " + m_doc.GetPageCount());
Log.d("GXC", "cantidad de anotaciones: " + p.GetAnnotCount());

int numAnotaciones = p.GetAnnotCount();

for(int j = 0; j<numAnotaciones; j++){
Page.Annotation annot = p.GetAnnot(j);
String name = annot.GetFieldFullName();

if(valores.containsKey(name)){
String valor = valores.get(name);
int type = annot.GetType();
Boolean resultado = annot.SetEditText(valor);
}
}
currentPage++;
}
}
Boolean canSave = m_doc.CanSave();
boolean salvo = m_doc.Save();
m_doc.Close();
Log.d("GXC", "se supone que salvo " + salvo);
}catch(Exception ex){
String error = ex.getMessage();
}

}



Annot.SetEditText always returns false. page.getAnnotByName is also unable to retrieve the annotation so I´m looping over all the annotations in the page and see if it´s one of which I have to fill up... The library was updated on June 2016


We have a premium license that activates correctly. The document can be filled with adobe DC. Anyway, Im giving you a pair of example files I´m trying to fill.
Attachments:

Please Log in or Create an account to join the conversation.

Unable to fill pdf form 2 years 4 months ago #10897

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
ok, we will check it and get back to you as soon as possible.

Please Log in or Create an account to join the conversation.

Unable to fill pdf form 2 years 4 months ago #10905

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
There are 2 names.
1 called annotation name, mostly defined by user, this name is optional.
another called field name, this is defined by designer, this name is document level.

GetAnnotByName is a loop to match annotation name, not field name, that's way it return's null in your case (as Annotation.GetName returns empty string)

there is no method call GetAnnotByFieldName().
so, you can implement this method, something like your above code.

Please Log in or Create an account to join the conversation.

Last edit: by nermeen.

Unable to fill pdf form 2 years 4 months ago #10906

  • fdelcaz
  • fdelcaz's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 21
  • Thank you received: 0
The main problem is seteditext returning null and not filling the annotation. What about that?

Please Log in or Create an account to join the conversation.

Unable to fill pdf form 2 years 4 months ago #10907

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
Actually this part is working in the demo project using your code..

Make sure that you are setting the edit text correctly respecting it's format...as mentioned in the java doc

/**
* set contents of edit-box.<br/>
* you should re-render page to display modified data.<br/>
* this method valid in premium version.<br/>
* Notice: this method not check format as GetEditTextFormat. developers shall check format by developer self.
* @param text contents to be set.<br/>in MultiLine mode: '\r' or '\n' means change line.<br/>in password mode the edit box always display "*".
* @return true or false.
*/
final public boolean SetEditText( String text ) {}

Please Log in or Create an account to join the conversation.

Unable to fill pdf form 2 years 4 months ago #10974

  • fdelcaz
  • fdelcaz's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 21
  • Thank you received: 0

nermeen wrote: Actually this part is working in the demo project using your code..

Make sure that you are setting the edit text correctly respecting it's format...as mentioned in the java doc

/**
* set contents of edit-box.<br/>
* you should re-render page to display modified data.<br/>
* this method valid in premium version.<br/>
* Notice: this method not check format as GetEditTextFormat. developers shall check format by developer self.
* @param text contents to be set.<br/>in MultiLine mode: '\r' or '\n' means change line.<br/>in password mode the edit box always display "*".
* @return true or false.
*/
final public boolean SetEditText( String text ) {}


Hi

I´m respecting the fields format. Here is an example. It shows field type 2 (text field),l edittype 1 (single line) and I´m trying to set a plaint text value. SetEditText is returning false. I have previously called init and activated my premium license (it returns ok).. Whats the problem? CanSave() also returns true.
Attachments:

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum