How can I open PDF files inside a Mac node-webkit application? - html

I'm trying to add support for PDFs in my Mac node-webkit app. I tried using "PDF.js" but it requires the use of a web server so this won't help me.
I've already solved this issue for the PC version of the node-webkit app by installing "Adobe Acrobat Reader" and adding the "nppdf32.dll" file inside the plugins folder of the root directory of the PC application.
Now I'm trying to solve this issue for the Mac version. How can I open PDF files inside my Mac node-webkit application?

If you still want to try PDF.js, this is how I have gotten it working.
After downloading all the files, the main ones that do all the work are viewer.html and viewer.js. You can point to viewer.html from anywhere in your node-webkit app by doing something like:
$(".some-pdf").on("click", function(){
window.location.href = "path-to-pdfjs/viewer.html";
});
To determine which file it opens, there's a variable in view.js.
var DEFAULT_URL = 'pdfs/something.pdf';
Since you're using node-webkit, it won't have any issues accessing the file system.
I made it a little more dynamic, where the link can point to any specific pdf, by doing the following. In any file, the link adds a hash with the file name:
$(".some-pdf").on("click", function(){
window.location.href = "path-to-pdfjs/viewer.html#specific.pdf";
});
Then in viewer.js:
var DEFAULT_URL = 'pdfs/' + window.location.hash.replace("#", "");
Then it is a bit reusable through your app, if there are multiple pdf files involved.

Related

What is the correct way to display a HTML file downloaded and saved in the file system using codename one?

What is the correct way to display a HTML file downloaded and saved in the file system? I am able to download and save the html page in the .cn1 folder on Simulator but it doesn't display. I tested using the Page.html sample file found in the old Kitchen Sink demo.
Also, how can I use hardcoded paths like file:///storage/emulated/0/Folder/Page.html instead? I have tried but nothing appears in common folders in the phone e.g. the Android folder. Below is what I have done so far!
`Form fm_brw = new Form();`
`fm_brw.setLayout(new BorderLayout());`
`FileSystemStorage fs = FileSystemStorage.getInstance();`
`fs.mkdir(fs.getAppHomePath() + "SampleFolder");`
`Util.downloadUrlToFile("http://somesite.com/Page.html", fs.getAppHomePath() + "SampleFolder/Page.html", true);`
`BrowserComponent browser = new BrowserComponent();`
`browser.setURL(fs.getAppHomePath() + "SampleFolder/Page.html);`
`fm_brw.addComponent(BorderLayout.CENTER, browser);`
`fm_brw.show();`
You can't hardcode paths on phones as those differ even on the same phone for new installs to keep app isolation.
Your approach is correct but I'm assuming the html refers to images and other resources which are now unavailable so the process of downloading an HTML file for offline viewing is more complex as you would need to download all the resources then edit the HTML source to reference local files instead of server files.
#Shai Almog - Happy 2018 and please accept my apologies for the delayed reply. I figured out the reason for the webpage not diplaying... apparently, you have to add the "file://" when setting the url i.e. browser.setURL("file://"+str_homePath+str_filePath);
If this is not by your design then I can file an RFE.

Cordova/Phonegap build fails to find HTML templates

I'm building my angularjs application to Phonegap Android application. I have builded the project using Yeoman/Grunt and I get it to work on webserver after that, but When build with Cordova/Phonegap to Android .apk file and installed on device I get only this to console:
GET file:///android_asset/www/app/_main/main.tpl.html net::ERR_FILE_NOT_FOUND
When I debug the application with Chrome android debugging and look the source it sohws index.html as empty (but it can be can it? Since it has to load the angularjs to try to get to the main template, and that happens in the index.html) and I can't find any of the other .html files from there.
\platforms\android\assets\www
In cordovas android project folder everything seems to be just as it's upposed to be.
Figured it out by myself. It was due to the folder name.
"_main"
So the '_' -character broke it. :)

Air App will not read local text file using openAsync/readUTFBytes on user (non-admin) mode

I am running an Air App I did for the desktop, from the actual installed executable already deployed in the machine (Not from Flash Pro / Flex dev. environment). For some reason the app will not read a text file stored in the same application folder unless I run my app as administrator from the OS.
When I run the app as admin, or within the development environment it works fine. Maybe this is related to some security issue? I read the adobe air documentation, and this should work...
I am using openAsync/readUTFBytes on user as shown here:
var continueGamesConnection:FileStream();
var continueFile:File = new File(File.applicationDirectory.resolvePath("continueGames.txt").nativePath.toString());
continueGamesConnection.addEventListener(Event.COMPLETE, openSavedGames);
continueGamesConnection.openAsync(continueFile, FileMode.UPDATE);
function openSavedGames(event:Event):void
{
continueGamesConnection.removeEventListener(Event.COMPLETE, openSavedGames);
var content:URLVariables = new URLVariables();
var loadedContent:String = new String();
loadedContent = continueGamesConnection.readUTFBytes(continueGamesConnection.bytesAvailable);
content.decode(loadedContent);
variableX = content. variableX
//etc, etc.
continueGamesConnection.close();
}
By the way, I have also, tried using FileMode.READ, and others, and it still gives me the same problem. Only works if ran on admin mode or from the dev. environment.
It's very frustrating, I tried reading other posts without any luck... What solutions do people use for this kind of problem?
I have seen that you can set the app to run as admin somehow, and I guess that could work. However, this should work just fine, since it doesn't seem to violate any of the security APIs of Air. Seems like an overkill. But even so, how do I do that?
You help is greatly appreciated!
Typically for security reasons, applications do not have write permissions to the File.applicationDirectory.
It is recommended you use File.applicationStorageDirectory instead as that is the most appropriate place to save user data (such as a save game file).
Alternatively, you could also let the user browse to a directory with the FileReference class which may or not have permission.
Assuming that you are using a Windows SO, the problem that you have is about user access restrictions to folders C:\Program Files and C:\Program Files (x86) and there is nothing you can do from Flash or AIR to solve it. You could modify you security settings by right click on the folder or you should simply avoid using the app folder to store anything

Windows Phone 8 ApplicationSettings - Get settings in Universal app

I'm upgrading windows phone 8 application. I created Universal app (Windows.Phone 8.1).
The settings in old WP8.0 application are saved in following way:
IsolatedStorageSettings.ApplicationSettings.Add("MY_SETTINGS", value);
Question:
How can i get this settings when app is upgraded to WP8.1 (Universal app).
I try the following:
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
var isContains1 = localSettings.Values.ContainsKey("MY_SETTINGS");
var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
var isContains2 = roamingSettings.Values.ContainsKey("MY_SETTINGS");
But no "MY_SETTINGS" are found. (isContains1, isContains2 == false):\
Many Thanks for help
LocalSettings in WP8.1 works differently than those in WP8.0 - where settings were saved in a file (after serialization). The file is __ApplicationSettings - take a look at it (via IS explorer tool) and you will see its structure - part of it is a serialized dictionary. I've made some research once, which showed that all the old files are preserved during the update - which means that the settings are still there.
Once you update your WP8.0 app to WP8.1 and you want to read your old settings, you can retrive the values from the file.
This blog post has your exact answer, including the code needed to deserialize the migrated settings file!
You can use ApplicationData.LocalSettings It would Get you the application settings container in the local app data store. here is a Dev center link in which its Described how to use it.

Open PDF in PDF Reader from AIR Desktop Application

I'been trying to open a pdf document from inside of an Adobe Air Desktop application created with Adobe Flash CS 6.
I Used this code:
import flash.filesystem.*;
var thePDF = "mypdf.pdf";
var realFile:File = File.applicationDirectory.resolvePath(thePDF);
var destination:File = File.documentsDirectory;
destination = destination.resolvePath(thePDF);
realFile.copyTo(destination,true);
destination.openWithDefaultApplication();
This works fine when I am testing inside Flash CS6, but stops to work when I publish the application in an .exe file (Same case in MACOS with .app file).
I tryied with all the resources I found in google, nothing works!!!
Actualy I found a code from a AS3 library called Shu (com.cjt.Shu) but there is no any documentation recorded in the web.
If any body knows about this Shu or some other alternative even no Open Source. Please let me know.
Thank you all in advance, regards from México.
Are you sure that your PDF content is in the folder of the actual published AIR?
It looks like the PDF is out of scope.
EDIT: Here´s some code to explain a bit more:
file1.addEventListener(MouseEvent.CLICK, pdf1, false, 0, true);
function pdf1(e:MouseEvent):void{
navigateToURL(new URLRequest(File.applicationDirectory.nativePath + "/files/My_PDF_File.pdf" ));
}
Double check the route of your target file. In my case, it is in the local folder of my published AIR folder in the "files" folder.
Hope this can help you.