I am using ReportMill to generate a report. The following is the code which generates a pdf document.
My question is: How do I pass the generated pdf document to a filechooser in Javafx ?
This so that it enables the user to save it to a folder of his choice. ReportMill itself can save the generated pdf to a string path specified as indicated in the code snippet below.
However once the application is installed on different computers instead of finding out user home directory, I would like to use a filechooser so that the generated pdf is saved to a directory of the users choice.
RMDocument report = template.generateReport(adminRecords);
report.getBytesPDF();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Report To : ");
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("PDF files (*.pdf)", "report.pdf");
fileChooser.getExtensionFilters().add(filter);
fileChooser.showSaveDialog(stageReport);
The following line can save to the path specified:
report.writePDF("c:/Users/xyz/Desktop/Report.pdf");
But as I mentioned that is not what I want. Would appreciate any help with this thanks.
Related
I am trying to export a GUI (Student Grade Manager App) I created in eclipse as a JAR file and run it on my desktop. Nothing happens when I double click it (though it does successfully export) at the moment. Here's an screenshot:
GUI Screenshot - Click here
I'm assuming the main issue here is that in my GUI, I am using the File Input stream in the CourseSectionApp.java file (Where the main method is located). It reads a .txt file called "StudentMarks.txt" and that's where it gets all its student data from.:
BufferedReader aFile = new BufferedReader ( new FileReader("Marks.txt"));
model = CourseSection.loadFrom(aFile);
Is there anyway to get this to work? Can I have the .txt file just export with the JAR file so it loads together? OR is there a way to put a sub-window, like modern applications have where the user can go to File->New-> and say, "load from file", and then be allowed to navigate to the .txt file on his computer?
My main goal is to be able to email this to friends and have them use it, but I googled around and only found a few people having similiar issues with not-so-clear answers. And if the JAR file cannot do this, what can? Will making it a .exe change anything?
Screenshot of Marks.txt file
I tried to make this question as legible as possible and if there is any other information I can provide you guys, please let know.
If you don't need to write to the file, including the file as resource in the jar would be your best option. This way you can always be sure the file is available via jar entry name. E.g.
try (InputStream is = getClass().getResourceAsStream("/data/Marks.txt");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr)){
model = CourseSection.loadFrom(br);
}
If you also need to write to the file, you can use FileChooser to open a dialog for choosing a file:
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Marks File");
fileChooser.getExtensionFilters().add(new ExtensionFilter("Text Files", "*.txt"));
File file = fileChooser.showOpenDialog(null); // you could also pass a owner window here
if (file != null) {
// TODO: handle completed file selection by user
}
The issue described in the comments indicates that there is a problem with the classpath though. You need to make sure all required classes are available when the application is run...
I wrote a notepad in qt gui, but when I associate a file with it and click on it, the .exe is run and file is not opened, so I have to open it using
QFileDialog::getSaveFileName(
this,"Save As","",
"Text Document (*.txt)\n All Files (*.*)")
When we click on text.txt it directly opens the file in notepad. How can I make same for my app?
remark: QDir::currentpath() returns the path of file.txtq (which is associated with it) on which we clicked but I was not able to return its name.
When double-clicking the file (associated with your exe), its path is passed to your program via command line arguments. You can access them in the following way:
if (QApplication::arguments().size() > 1) {
const QString filename = QApplication::arguments().at(1);
// "filename" now contains path and name of the file to open.
}
Also, I have no idea why you are using QFileDialog::getSaveFileName(). In order to call the open file dialog, you'll need the QDialog::getOpenFileName() method.
I have an application(ASP.NET), in that I am showing different reports using the crystal report viewer.The deafult print dialog is not matching with the template I used in the page.so decided to make a differnt one.The Export option is dynamically working and exporting the report, but for printing,I use the printToPrinter method, which is not showing up the print dialog where I can seleted the printer and the print quality, paper orientation..etc...
Can anyone suggest a method to invoke the print dialog through this method
In order to configure these parameters in your code you can use:
string printerName = ""; //Insert printer name here.
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new ReportDocument();
rpt.PrintOptions.PrinterName = printerName;
rpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
And so on... I think that all the rest of your needed configuration are there, available for you to set.
I'm giving users the ability to upload an image to my Air app, then displaying this image in an image control. But I need to allow for PDF uploading in the same manner, so I need to convert the PDF to an image. I only care about the first page of the PDF they upload for now.
What I'm doing is:
1) User browses for a file with the file reference control
2) User chooses the image or PDF to upload
3) I encode said image to base64 and store it
4) I then load from that base64 with something like:
public function decodeImage(b64String:String):void{
var decoder:Base64Decoder = new Base64Decoder();
decoder.decode(b64String);
var imgLoader:Loader = new Loader();
imgLoader.loadBytes(decoder.toByteArray());
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,decodedImageLoaded);
}
private function decodedImageLoaded(event:Event):void{
var imgLoader:Loader = (event.target as LoaderInfo).loader;
var bmp:Bitmap = Bitmap(imgLoader.content);
imgLoader.removeEventListener(Event.COMPLETE, decodedImageLoaded);
var img:Image = new Image();
img.source = bmp;
this.addChild(img);
}
This method is working great for .gif, .jpg, and .png. At some point in my process, probably the initial upload I need to convert the first page of a PDF to a png so that I can use the rest of this process.
I welcome any ideas with the sole requirement being that it has to be a part of the Air app, I can't use something like ImageMagick that runs on a server, but I could use a component that I can compile in to the finished product.
I believe AlivePDF for Flash now has capabilities to read a PDF file. You might try PurePDF, as well. You could potentially use ones of these to get that desired page and convert it to an image.
Have you seen swftools? It has the ability to convert a PDF to a SWF, PNG, JPG, etc...
I'm deploying a small application with Adobe Air. My application will do batch upload from filepath which stored in a text file.
For example, in a text file name "list.txt", there is a string "C:\myfiles\IMG_0001.JPG". Now I want to upload this image file, keep tracking of upload progress :-<
I want to use FileReference to get the upload progress, but I don't know how to import from file's path. I also wonder how to use FileReference to upload this file without prompting a dialog for user to select file.
Thank you so much :)
Try the following. I have done a file upload without dialog box using following code.
var uploadURLs:URLRequest = new URLRequest("Your upload URL Here");
var params:URLVariables=new URLVariables();
params.title = "Hello";//URL Parameters if there is any
uploadURLs.data = params;
uploadURLs.method=URLRequestMethod.POST;
file = new File("Path to File");
file.addEventListener(ProgressEvent.PROGRESS , updateProgress);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, doneUpload);
file.addEventListener(IOErrorEvent.IO_ERROR,fileError);
file.upload(uploadURLs);
Hope this helps