I have a similar problem - i was trying to run this code for IntelliJ Idea 13 and i would like to use rptdesign file to generate the report. The code looks like this:
public class ExecuteBIRTReport {
static void executeReport() throws EngineException {
EngineConfig config = null;
IReportEngine engine = null;
try {
config = new EngineConfig();
config.setLogConfig("/logs", java.util.logging.Level.WARNING);
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
IReportRunnable report = null;
String reportFilepath = "C://Users//user//workspace//TestProject//Products.rptdesign";
try {
report = engine.openReportDesign(reportFilepath);
} catch (Exception e) {
System.err.println("Report " + reportFilepath + " not found!\n");
engine.destroy();
return;
}
IRunAndRenderTask task = engine.createRunAndRenderTask(report);
PDFRenderOption options = new PDFRenderOption();
options.setOutputFormat("pdf");
options.setOutputFileName("C:/Users/user/workspace/TestProject/REPORT.pdf");
task.setRenderOption(options);
try {
task.run();
} catch (EngineException e1) {
System.err.println("Report " + reportFilepath + " run failed.\n");
System.err.println(e1.toString());
}
engine.destroy();
return;
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
executeReport();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I imported the project IntelliJ following jar-files (without them do not eceive a compilation):
com.ibm.icu_54.1.1.v201501272100.jar
org.eclipse.birt.core_4.5.0.v201506092134.jar
org.eclipse.birt.data_4.5.0.v201506092134.jar
org.eclipse.birt.report.data.adapter_4.5.0.v201506092134.jar
org.eclipse.birt.report.engine_4.5.0.v201506092134.jar
org.eclipse.birt.report.model_4.5.0.v201506092134.jar
org.eclipse.core.runtime_3.11.0.v20150405-1723.jar
org.eclipse.datatools.connectivity.oda_3.4.3.v201405301249.jar
org.eclipse.equinox.common_3.7.0.v20150402-1709.jar
org.eclipse.equinox.common_3.7.0.v20150402-1709.jar
org.eclipse.osgi_3.10.100.v20150529-1857.jar
In Eclipse version of BIRT 4.5.0. and a report is created normally. In IntelliJ at the stage of creating a file error message:The output format <...> is not supported. I tried to arrange for the withdrawal of pdf and html formats, but to no avail. Does anyone know a solution?
Related
We are able to view the screenshots locally. When we run the job in Jenkins we are unable to view the screenshots in extent reports. We are using extent reports v2.41.2. Both the screenshot and report are in the same directory. Kindly give us a solution in order to solve it.
public static String takescreenshot(WebDriver driver, String Screenshotname) throws InterruptedException {
Thread.sleep(3000);
TakesScreenshot ts = (TakesScreenshot) driver;
File src = ts.getScreenshotAs(OutputType.FILE);
String timeStamp = new SimpleDateFormat("MMMdd_yyyy_hh_mmaa").format(Calendar.getInstance().getTime());
String dest = System.getProperty("user.dir")+"\\ATOM_20Report\\"+Screenshotname + "_" + timeStamp + ".png";
try {
FileUtils.copyFile(src, new File(dest));
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("Failed to take screenshot: " + e.getMessage());
}
return dest;
}
public static void passTestwithsc(String Screenshotname, WebDriver driver) {
Assert.assertTrue(true);
String path = null;
try {
path = Helper.takescreenshot(driver, Screenshotname);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.log(LogStatus.PASS, logger.getDescription(),logger.addScreenCapture(path));
}
I am trying to develop Java web Tesseract OCR application. Following code works perfectly :
public class App {
public String getImgText(String imageLocation) {
ITesseract instance = new Tesseract();
instance.setDatapath(Thread.currentThread().getContextClassLoader().getResource("tessdata").getPath());
System.out.println("Thread.currentThread().getContextClassLoader().getResource(\"tessdata\").getPath() : "+Thread.currentThread().getContextClassLoader().getResource("tessdata").getPath());
instance.setLanguage("eng");
try {
String imgText = instance.doOCR(new File(imageLocation));
return imgText;
} catch (TesseractException e) {
e.getMessage();
return "Error while reading image";
}
}
public static void main(String[] args) {
App app = new App();
System.out.println(app.getImgText("/home/user/Desktop/1.png"));
}
}
But when I trying to use the above code in my Java web(JSF) application after the line
ITesseract instance = new Tesseract();
nothing is printed out. Below is the code of my web application :
public String uploadImage(FileUploadEvent event) {
System.out.println("webcore bean");
//get uploaded file from the event
UploadedFile uploadedFile = (UploadedFile) event.getFile();
//create an InputStream from the uploaded file
InputStream inputStr = null;
try {
inputStr = uploadedFile.getInputstream();
} catch (IOException e) {
//log error
}
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
String directory = externalContext.getInitParameter("uploadDirectory");
String filename = FilenameUtils.getName(uploadedFile.getFileName());
File destFile = new File(directory, "static" + getFileExtension(filename));
//use org.apache.commons.io.FileUtils to copy the File
try {
FileUtils.copyInputStreamToFile(inputStr, destFile);
} catch (IOException e) {
//log error
}
System.out.println("getImageText(directory) : " + getImageText(directory));
FacesMessage msg = new FacesMessage(event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
return null;
}
private String getImageText(String imageLocation) {
try {
System.out.println("Before ");
ITesseract instance = new Tesseract1();
System.out.println("After ");
//instance.setDatapath("/usr/share/tesseract-ocr/4.00/tessdata");
instance.setDatapath(Thread.currentThread().getContextClassLoader().getResource("tessdata").getPath());
instance.setLanguage("eng");
try {
String imgText = instance.doOCR(new File(imageLocation));
return imgText;
} catch (TesseractException e) {
e.getMessage();
return "Error while reading image";
}
} catch (Exception e) {
System.out.println("Before returning null");
e.printStackTrace();
return null;
}
}
The log "Before" is being printed but the log "After" is not being printed. I am using following technologies :
a) Ubuntu 18.04 64 bit OS
b) Netbeans
c) Maven
d) Glassfish 4.1
I want to delete embedded files in ms word document using java API and i tried with POI API but it is not working , please suggest best java API.
public static void modifyDocxFile(String fileName) {
try {
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(fis);
System.out.println(document.getAllEmbedds().size());
/*List<PackagePart> embeddedDocs = document.getAllEmbedds();
if (embeddedDocs != null && !embeddedDocs.isEmpty()) {
embeddedDocs.remove(0);
}*/
document.getAllEmbedds().remove(0);
document.write(new FileOutputStream(new File("D:\\study\\word\\SampleModified.docx")));
//System.out.println(document.getAllEmbedds());
fis.close();
//fis2.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
modifyDocxFile("D:\\study\\word\\Sample.docx");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//readDocFile("C:\\Test.doc");
}
I'm trying to open a pdf located in a ressource folder with my application.
It does work on the emulator but nothing happens when I try on the exported application.
I'm guessing I'm not using the rigth path but do not see where I'm wrong. The getRessource method works very well with my images.
Here is a code snippet :
public void openPdf(String pdf){
if (Desktop.isDesktopSupported()) {
try {
URL monUrl = this.getClass().getResource(pdf);
File myFile = new File(monUrl.toURI());
Desktop.getDesktop().open(myFile);
} catch (IOException ex) {
// no application registered for PDFs
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I'm referring to the pdf variable this way : "name_of_the_file.pdf"
Edit: I've pasted the whole method
Ok, solved it. The file being located in a Jar, the only way to get it was through a inputsteam/outstream and creating a temp file.
Here is my final code, which works great :
public void openPdf(String pdf){
if (Desktop.isDesktopSupported())
{
InputStream jarPdf = getClass().getClassLoader().getResourceAsStream(pdf);
try {
File pdfTemp = new File("52502HPA3_ELECTRA_PLUS_Fra.pdf");
// Extraction du PDF qui se situe dans l'archive
FileOutputStream fos = new FileOutputStream(pdfTemp);
while (jarPdf.available() > 0) {
fos.write(jarPdf.read());
} // while (pdfInJar.available() > 0)
fos.close();
// Ouverture du PDF
Desktop.getDesktop().open(pdfTemp);
} // try
catch (IOException e) {
System.out.println("erreur : " + e);
} // catch (IOException e)
}
}
You mentioned that it is running on Emulator but not on the application. There is high probability that the platform on which the application is running does not support Desktop.
Desktop.isDesktopSupported()
might be returning false. Hence no stack trace or anything.
On Mac, you can do:
Runtime runtime = Runtime.getRuntime();
try {
String[] args = {"open", "/path/to/pdfFile"};
Process process = runtime.exec(args);
} catch (Exception e) {
Logger.getLogger(NoJavaController.class.getName()).log(Level.SEVERE, "", e);
}
I used the following code to run an exe I load through my code.
private static String filelocation = "";
.
load_exe.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
try {
JFileChooser file_Choose = new JFileChooser();
file_Choose.showOpenDialog(frame);
JavaSamp.filelocation = file_Choose.getCurrentDirectory()
.toString()
+ "\\" + file_Choose.getSelectedFile().getName();
System.out.println("FileLocation" + JavaSamp.filelocation);
} catch (Exception expobj) {
// TODO Auto-generated catch block
}
Runtime rt = Runtime.getRuntime();
try {
System.out.println("File Run Location" + JavaSamp.filelocation);
proc = rt.exec(JavaSamp.filelocation);
} catch (IOException e4) {
e4.printStackTrace();
} catch (Exception e2) {
}
}
});
My problem is, the above execution of the JavaSamp.filelocation, should have to done many times. First time only I load the exe. Next time I wont. I need to store the exe in a string to run for the successive times.
Any suggestion pls
If you want remember the used file just initialize the filelocation with null and test for it. BTW: Storing it as File makes more sense and your way of constructing the absolute path is a bit intricate - compared to just calling getAbsolutePath()
private static File filelocation = null;
private static void test() {
load_exe.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Check if file-name to execute has already been set
if (filelocation != null) {
try {
JFileChooser file_Choose = new JFileChooser();
file_Choose.showOpenDialog(frame);
JavaSamp.filelocation = file_Choose.getSelectedFile();
System.out.println("FileLocation"
+ JavaSamp.filelocation.getAbsolutePath());
} catch (Exception expobj) {
}
}
Runtime rt = Runtime.getRuntime();
try {
System.out.println("File Run Location"
+ JavaSamp.filelocation.getAbsolutePath());
Process proc = rt.exec(JavaSamp.filelocation
.getAbsolutePath());
} catch (IOException e4) {
e4.printStackTrace();
}
}
};
}