- Posts: 21
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Unable to fill pdf form
9 years 6 months ago #10894
by fdelcaz
Unable to fill pdf form was created by fdelcaz
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.
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.
9 years 6 months ago #10897
by nermeen
Replied by nermeen on topic Unable to fill pdf form
ok, we will check it and get back to you as soon as possible.
9 years 6 months ago - 9 years 6 months ago #10905
by nermeen
Replied by nermeen on topic Unable to fill pdf form
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.
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.
Last edit: 9 years 6 months ago by nermeen.
9 years 6 months ago #10906
by fdelcaz
Replied by fdelcaz on topic Unable to fill pdf form
The main problem is seteditext returning null and not filling the annotation. What about that?
9 years 6 months ago #10907
by nermeen
Replied by nermeen on topic Unable to fill pdf form
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 ) {}
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 ) {}
9 years 5 months ago #10974
by fdelcaz
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.
Replied by fdelcaz on topic Unable to fill pdf form
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.
Time to create page: 0.437 seconds