How to hide confirmConversion dialog when open docx file with help 2003 - java

I use eclipse swt in my application. It allows me open word files (doc, docx, rtf).
But I cannot hide "Confirm Conversion at Open" dialog programmaticaly when open docx file (doc or rtf open fine). Windows XP SP3, Microsoft Word 2003 SP3 and FileFormatConverters installed on machine.
In VBA this dialog hides when set property Application.Options.ConfirmConversions = false. Or sets property when open file:
Documents.Open FileName:="file_path_name", ConfirmConversions = false.
I set this property with help OleAutomation, but this doesn't work.
Bellow part of code that I use:
shell = SWT_AWT.new_Shell(SwtHelper.display, canvas);
shell.setLayout(new FillLayout());
try {
frame = new OleFrame(shell, SWT.NONE);
clientSite = new OleClientSite(frame, SWT.NONE, "Word.Document", file);
clientSite.doVerb(OLE.OLEIVERB_SHOW);
} catch (SWTException e) {}
This code work fine
How I can hide Confirm Conversion dialog when open docx using swt and word 2003?
Thanks.

You should try Word.Application instead of Word.Document.
There is huge difference whether you use Word.Document or Word.Application.
Word.Application will let you pass arguments to ole.
Please have a look at my comment given here: https://stackoverflow.com/a/17021512/1285811

Related

PDF with forms to simple image PDF

How can I transform a PDF with forms made in Adobe Livecycle to a simple image PDF using Java?
I tried using Apache PDFBox but it can't save as image a PDF with forms.
This is what I tried(from this question: Convert PDF files to images with PDFBox)
String pdfFilename = "PDForm_1601661791_587488.pdf";
try (PDDocument document = PDDocument.load(new File(pdfFilename))) {
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
ImageIOUtil.writeImage(bim, pdfFilename + "-" + (page+1) + ".png", 300);
}
} catch (IOException ex) {
Logger.getLogger(StartClass.class.getName()).log(Level.SEVERE, null, ex);
}
But is not working, the result is an image where it writes that "The document you are trying to load requires Adobe Reader 8 or higher.
I guess is not possible, I tried many libraries and none worked.
This is how I solved the problem:
I used an external tool - PDFCreator.
In PDFCreator I created a special printer that prints and saves the PDF without asking any questions(you have these options in PDFCreator).
This is simple to reproduce in PDFCreator because in the Debug section you have an option to load a config file, so I have this file prepared, I just install PDFCreator and load the config file.
If you will use my INI file in the link above you should know that the resulted PDF is automatically saved in the folder: "current user folder/Desktop/temporary".
The rest of the job is done from Java using Adobe Reader, the code is in my case:
ProcessBuilder pb = new ProcessBuilder(adobePath, "/t", path+"/"+filename, printerName);
Process p = pb.start();
This code opens my PDF in AdobeReader, prints the PDF to the specified virtual printer, and exists automatically.
"adobePath" is the path to the adobe executable
path+"/"+filename is the path to my PDF.
"printerName" is the name of the virtual printer created in PDFCreator
So this is not a pure Java solution and in the future, I intend to use Apache PDFBox to generate my PDF's in a format that is compatible with browsers and all readers...but this works also.

using java not javascript, open URL in same tab of default browser

I have written a java script whose work is to open URL's mentioned in the text file and it should repeat this process continuously but the problem is as soon as it reads the new URL mention in next line of text file it opens that URL in new tab but I want to open all the URL's in same tab of chrome browser.
Code what I have written:
while(true){
BufferedReader buf = new BufferedReader(new FileReader("C:\\link.txt"));
String currentLine = null;
while((currentLine = buf.readLine())!=null){
System.out.print(currentLine+"\n");
Desktop.getDesktop().browse(new URL(currentLine).toURI());
Thread.sleep(10000);
}
}
}
Is there any other option then Desktop.getDesktop() that will also work
My text file has two links like this:
https://www.google.co.in/?gfe_rd=cr&ei=y8a_WPTUFLOl8weF8bK4DQ
https://in.yahoo.com/
How to open them in same tab?
Desktop.getDesktop().browse()
Does NOT support this, as seen in Can Java's Desktop.browse provide an HTML Target in order to reuse a browser window?
Though, alternatives for this are the use of Process as seen in
Process oProc = Runtime.getRuntime().exec( currentLine );
And then make use of this process to send more commands to.
Or make use of a library / API such as Browserlaunch
The issue with Chrome, however is that Chrome likes to open new tabs in a new screen. If you hit ctrl + N (new tab on a lot of browsers) on Chrome, it'll open up a new screen instead

How can I open a file from the explorer and copy to a directory?

I have a little problem,
I need to do a program that open the file explorer and copy the selected file in a specified directory.
I've only found how to open the explorer :
File file = new File ("c:\\<directory>");
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
but I need to get the selected file and copy in a default directory, and I really don't know how to do it.
Thanks a lot!!
I assume you have a SWT Java Application. Then you can use FileDialog to show a file chooser where the user selects a file. Without a GUI it wouldn't be easy to show a file choosing dialog to the user.
This code snippet uses FileUtils from Apache Commons IO:
FileDialog dlg = new FileDialog(frame, "Choose a file to copy", FileDialog.OPEN);
dlg.setVisible(true); // blocks until user completes the action
String fileToCopyString = dlg.getFile();
if (fileToCopyString != null) {
File fileToCopy = new File(fileToCopyString);
if (fileToCopy.isFile()) {
FileUtils.copyFile(fileToCopy, new File(tmpDir, fileToCopy.getName());
}
}
References:
FileDialog Javadoc
FileUtils Javadoc
How to use FileDialog?
Try read the file and write it to another directory. You can use FileReader() and FileWriter() methods.

Open a large html file on browser

I have a desktop bassed eclipse plugin application. In which, for a case I am opening html report file in browser.
for which I am using this:
try {
browser = new Browser(shell, SWT.NONE);
browser
.setUrl(path);
shell.open();
}
catch (SWTError e) {
e.printStacktrace();
}
But in one case I am having html file of 90 MB which is not able to get open by it. It got hanged.
So request you for any action around it need to be done.
On any other optimized way to open it.
Instead of loading the whole file, load it on demand.
Window onscroll event is your friend.

JEditorPane.setPage() method works only once during runtime

I am currently working on a project that allows the user to input a url, such as http://www.google.com and the user is able to edit the html code of the page. So far I save the edited file as an html document when the JTextArea has a key released. Here is the source code that I use:
String s = jTextArea1.getText();
PrintStream ps = new PrintStream(new FileOutputStream(new File("HTML.htm")));
ps.print(s);
ps.close();
this.resetPage();
The last line of code calls this bit of source code (this is actually where I attempt to update the page with the user's input:
File f = new File("HTML.htm");
URL u =f.toURI().toURL();
jEditorPane1.setPage(u);
All the proper exceptions are caught. It updates the text on the page once. All the images are blank (which I expected because the paths were all local) but that should have no real effect on the other html in the document.
When I open the HTML.htm file in notepad++ the file IS being updated but the jEditorPane is not getting updated with the new html script.
Also, the JEditorPane has its Editable vale set to false.
When I open the file in Chrome, it gets the fully updated script.
From the JEditorPane setPage(URL) API description:
To force a document reload it is necessary to clear the stream description property of the document. The following code shows how this can be done:
Document doc = jEditorPane.getDocument();
doc.putProperty(Document.StreamDescriptionProperty, null);
try this
File f = new File("HTML.htm");
URL u =f.toURI().toURL();
jEditorPane1.setPage(u);
jEditorPane1.updateUI();

Categories

Resources