[JAVA] save a report of a document BO in pdf format

hello,

My objective is to generate a set of pdf files of BO report from a document by filtering with a list of value of a dimension.
I ve looked in some forums to get clues but I’m stoped by the backup of a report in pdf format.
In fact i export a pdf whith only one page when it should be quite more…

Sure that i miss something but i don’t see for the moment and i will appreciate any help on the topic.

The code is the following:


public class BOconnect {
	   @SuppressWarnings("resource")
	public static void main(String[] args) {
	      IEnterpriseSession enterpriseSession = null;
	      ReportEngines reportEngines = null;
try {
System.out.println("Connecting...");
// Connexion au CMS
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
enterpriseSession = sessionMgr.logon("Administrator","xxxxx", "xxxxxx", "secEnterprise");

// Récupération des infos du document BO sur l'infostore
IInfoStore infoStore = (IInfoStore) enterpriseSession.getService("InfoStore"); 
String query = "SELECT * FROM CI_INFOOBJECTS WHERE SI_KIND= 'Webi' AND SI_INSTANCE=0 AND SI_NAME=test'"; 
IInfoObjects infoObjects = (IInfoObjects) infoStore.query(query); 


IInfoObject infoObject = (IInfoObject) infoObjects.get(0); 
System.out.println("infoObject" + infoObject); 
int docID = infoObject.getID(); 
String docType = infoObject.getKind(); 
System.out.println("Document: " + "Type=" + docType + " " + "ID="+ String.valueOf(docID) + "Titre=" + infoObject.getTitle() ); 


//*Instanciation du report engine approprié*/ 
ReportEngines RepEngines = (ReportEngines) enterpriseSession.getService("ReportEngines"); 
ReportEngine webiReportEngine = RepEngines.getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE); 

/*Traitement du document*/ 
DocumentInstance boDocumentInstance = webiReportEngine.openDocument(docID); 
System.out.println("Propriété du document :" +boDocumentInstance.getProperties()); 
System.out.println(); 

/* requete + univers*/ 
DataProviders dataProviders = boDocumentInstance.getDataProviders(); 
DataProvider dataProvider = dataProviders.getItem(0);
String dataProviderName = dataProvider.getName();
System.out.println("Nom du dataprovider " + dataProviderName );
System.out.println("Nom de l'univers " + dataProvider.getDataSource().getName());


/*Actualisation des données du document*/ 
boDocumentInstance.refresh(); 

// Initialisation des prompts
Prompts p = boDocumentInstance.getPrompts(); 
Prompt invit1 = p.getItem(0);
Prompt invit2 = p.getItem(1); 
System.out.println("Nombre d'invit : " + p.getCount()); 
System.out.println("Invit 1 : " + invit1.getName());
System.out.println("Invit 2 : " + invit2.getName());
System.out.println();

String [] vals1 = new String[1];
String [] vals2 = new String[1];

vals1[0] = "Mensuel";
vals2[0] = "Décembre 2012";


invit1.enterValues(vals1);
invit2.enterValues(vals2);

String [] val=invit1.getCurrentValues();
System.out.println("Invit 1 val : " + val[0]);
val=invit2.getCurrentValues();
System.out.println("Invit 2 val : " + val[0]);
System.out.println();
System.out.println("avant set prompt" );

boDocumentInstance.setPrompts(); 

// sauvegarde du document webi
boDocumentInstance.applyFormat(); 
boDocumentInstance.save();


/* liste de rapports */

Reports refreports=boDocumentInstance.getReports();
System.out.println("Nombre des rapport: " + refreports.getCount());
System.out.println();
Report listepdf = refreports.getItem(0);
Report agent = refreports.getItem(1);
Report listeexcel = refreports.getItem(2);

System.out.println("Nom du rapport 1: " + listepdf.getName());
System.out.println("Nom du rapport 2: " + agent.getName());
System.out.println("Nom du rapport 3: " + listeexcel.getName());
System.out.println();


/* sauvegarde en pdf/
BinaryView binaryView = (BinaryView) agent.getView(OutputFormatType.PDF);
String vFilePath="C://Users//david//workspace//"+ infoObject.getTitle()+ "201212" + ".pdf";
File vFile = new File(vFilePath); 
vFile.setWritable(true); 
vFile.setReadable(true); 
FileOutputStream fstream;
fstream = new FileOutputStream(vFilePath);
fstream.write(binaryView.getContent());
fstream.close();

//Sauvegarde local
IFiles myFiles= infoObject.getFiles(); 
IRemoteFile myLocalFile= (IRemoteFile) myFiles.get(0); 

//Download of the .wid from the server and save it locally. 
myLocalFile.download("C://Users//david//workspace//temp.wid"); 
myLocalFile.commit(); 


/*Fermeture du document*/ 
boDocumentInstance.closeDocument(); 
boDocumentInstance = null; 
}


catch (SDKException ex) {
ex.printStackTrace();
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

finally {
if (reportEngines != null)
reportEngines.close();
if (enterpriseSession != null)
enterpriseSession.logoff();
}
System.out.println("Finished!");
}
}

Thanks


dav_tlse :fr: (BOB member since 2012-05-29)

Look at the example in the documentation:
http://help.sap.com/javadocs/boe/xi31/re/en/com/businessobjects/rebean/wi/DocumentInstance.html#setPrompts()
You are definitely missing runQueries()

The call of applyFormat() is perhaps redundant

The rest seems to be fine.


Dmytro Bukhantsov :norway: (BOB member since 2011-10-14)

First, thank you for your response and thank you for your web site which helps me to start my little programme.

Finally I found the solution on this forum.

I don’t have to run the query through runquery because i call refresh.

The definition of the pagination of the report solve my problem.
The code becomes:


/* liste de rapports et définition du mode de pagination */
             
             Reports refreports=boDocumentInstance.getReports();
             System.out.println("Nombre des rapport: " + refreports.getCount());
             System.out.println();
             Report listepdf = refreports.getItem(0);
             listepdf.setPaginationMode(PaginationMode.Listing);
             Report agent = refreports.getItem(1);
             agent.setPaginationMode(PaginationMode.Listing);
             Report listeexcel = refreports.getItem(2);
             listeexcel.setPaginationMode(PaginationMode.Listing);

dav_tlse :fr: (BOB member since 2012-05-29)

Ah did not notice refresh…

Interesting. Maybe it is a BO bug?

I just checked. Exporting a report in PDF indeed produces one page

(BinaryView) agent.getView(OutputFormatType.PDF)

But if you export the document, all pages are saved:

(BinaryView) boDocumentInstance.getView(OutputFormatType.PDF); 

Dmytro Bukhantsov :norway: (BOB member since 2011-10-14)

Hello,

It’s not a bug but you have to define the mode of pagination of your report before getting the view.

To get all the report in pdf, you put the folowing line after the definition of your report

 
agent.setPaginationMode(PaginationMode.Listing); 

dav_tlse :fr: (BOB member since 2012-05-29)

Ok, why then do not I need to define the mode of pagination when exporting the document instance view (not a single report)?


Dmytro Bukhantsov :norway: (BOB member since 2011-10-14)

Yes, it doesn’t seem very logical and i don’t have any response about this point.
Hopefully, my need was about reports
Whatever thanks for your help.


dav_tlse :fr: (BOB member since 2012-05-29)