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 (BOB member since 2012-05-29)