You are viewing limited content. For full access, please sign in.

Question

Question

Java with Laserfiche

SDK
asked on August 29, 2014 Show version history

I'm using java to work with laserfiche but I don't find out how to set a template to Document when i create it.  

 

C#

                    int docID = Document.Create("\\" + item.n_empregados, "DEFAULT", EntryNameOption.AutoRename, ConexaoRepositorio.Session);
                    DocumentInfo docinfo = (DocumentInfo)Entry.GetEntryInfo(docID, ConexaoRepositorio.Session);
                    docinfo.SetTemplate("EMPREGADOS");

                    FieldValueCollection fvc = new FieldValueCollection();

                    fvc.Add("IDEMPREGADOS", item.empregadosid);
                    fvc.Add("EMPREGADOS", item.n_empregados);

                    docinfo.SetFieldValues(fvc);
                    docinfo.Save();

In Java

 

	public void pageCreatorWithTemplate(String caminho){
		try {
			Document doc = null;
			Folder dirRaiz = Folder.getByPath("\\", RepositoryConnection.getInstancia());
			
			doc = Document.create(dirRaiz, "Meu Documento Java II", EnumSet.of(EntryNameOption.AUTORENAME), RepositoryConnection.getInstancia());
			Page p = Page.create(doc, 1);
			p.write(new File(caminho), PagePart.IMAGE);						
			
			Template t = new Template("EMPREGADOS", RepositoryConnection.getInstancia());			
			System.out.println("Setando template...! " + t.getName());			
			
			doc.save();
			t.save();
			System.out.println("Imagem Criada...!");
			
			RepositoryConnection.getInstancia().logOut();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

As you can see how can i link the template to the document???....In Java has no DocumentInfo

0 0

Answer

SELECTED ANSWER
replied on August 29, 2014

Create a FieldValueCollection object using the new operator, then call FieldValueCollection.assignTemplate(), then call Entry.setFields() on the Document object, then call Entry.save()

0 0
replied on September 1, 2014 Show version history

Thanks for the help...Now i'm trying to set fields to the template, fields that already exists in the laserfiche server.

 

	public void pageCreatorWithTemplate(String caminho){
		try {
			Document doc = null;
			Folder dirRaiz = Folder.getByPath("\\", RepositoryConnection.getInstancia());
			
			doc = Document.create(dirRaiz, "Meu Documento Java II", EnumSet.of(EntryNameOption.AUTORENAME), RepositoryConnection.getInstancia());
			Page p = Page.create(doc, 1);
			p.write(new File(caminho), PagePart.IMAGE);						
			
			Template t = new Template("PENDENCIA", RepositoryConnection.getInstancia());			
			System.out.println("Setando template...! " + t.getName());	
			
			FieldValueCollection fvc = new FieldValueCollection();
			fvc.assignTemplate(t);
			
			Entry entry = doc;
			entry.setFields(fvc);
			entry.save();
			
			doc.save();
			System.out.println("Imagem Criada...!");
			
			RepositoryConnection.getInstancia().logOut();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

The above code is fully functional and I hope it helps other people.

0 0

Replies

replied on September 1, 2014

I hope that code help others with the same difficulty !

 

	public void pageCreatorWithTemplate(String caminho){
		try {
			
			Empregado emp = new Empregado();
			emp.setEmpregado("ALLAN G. DE FREITAS");
			emp.setId(10);
			
			Document doc = null;
			Folder dirRaiz = Folder.getByPath("\\", RepositoryConnection.getInstancia());
			
			doc = Document.create(dirRaiz, "Meu Documento Java II", EnumSet.of(EntryNameOption.AUTORENAME), RepositoryConnection.getInstancia());
			Page p = Page.create(doc, 1);
			p.write(new File(caminho), PagePart.IMAGE);						
			
			Template t = new Template("EMPREGADOS", RepositoryConnection.getInstancia());			
			System.out.println("Setando template...! " + t.getName());	
			
			FieldValueCollection fvc = new FieldValueCollection();
			fvc.assignTemplate(t);	
			
			//Add Field IDEMPREGADOS
			Field idEmpregados = new Field("IDEMPREGADOS", RepositoryConnection.getInstancia());
			fvc.add(idEmpregados, emp.getId());
			
			//add Field NOME CREDOR
			Field nomeCredor = new Field("NOME CREDOR", RepositoryConnection.getInstancia());
			fvc.add(nomeCredor, emp.getNome());
			
			Entry entry = doc;
			//SAVE TEMPLATE AND FIELD
			entry.setFields(fvc);
			entry.save();
			
			doc.save();
			System.out.println("Imagem Criada...!");
			
			RepositoryConnection.getInstancia().logOut();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.