My appcelerator alloy app has a section that displays a list of protocols used by employees in a listview(There are about 25), when a row is tapped, it should open the corresponding PDF document in the assets/protocol_pdf folder. In iOS 11.2.1, the document viewer opens, but the PDF is not displayed, only the filename followed by PDF document(see image). Everything works just fine in iOS 10 and prior.
I used the code example from http://www.appcelerator.com/blog/2015/08/appcelerator-pdf-viewer-demo/ to open the PDF.
Additionally, using the exact code from the appcelerator documentation(http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.DocumentViewer) in a new test project results in the same problem.
At this point i'm not sure how to solve the issue. I can only guess that something in where the file is saved and how it is accessed is different. Any suggestions are appreciated.
My Code:
function onItemClick(e){
var item = $.listView.sections[e.sectionIndex].items[e.itemIndex];
Ti.API.info('Opening ' + item.properties.file);
if(OS_IOS){
openResourcePDF(item.properties.file);
} else{
Alloy.Globals.Navigator.open("androidPDF", {file: item.properties.file});
}
}
function openResourcePDF(fileName){
var appFile;
appFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);
var appfilepath = appFile.nativePath;
viewPDF(appfilepath);
}
function viewPDF(appfilepath){
docViewer = Ti.UI.iOS.createDocumentViewer({url:appfilepath});
docViewer.show();
}
Image showing how viewer brings it up:
I guess you just want to use that on iOS. Try this:
function openResourcePDF(fileName) {
var appFile;
appFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, fileName);
var appfilepath = appFile.nativePath;
viewFile(appfilepath);
}
Related
please refer above link for reference.
I am using drive rest API for interacting with files from google drive.
my problem is when tries to load thumbnail images (which is got from google drive meta data) i got following error in response.
(Reload the page to get source for: https://lh6.googleusercontent.com/PIkXnvV5LN71K8UdvltrFIS7WpKOiXHnJCIvPRsq0ma_XU_gzEFKrfnc6hYFIojM_4_kNA
=w100-h100)
however it works fine sometimes and loads the image perfectly.
Also i checked the link in new tab which is also works perfectly.
here is my code for java script
--link used for meta data
var googleLink = 'https://www.googleapis.com/drive/v2/files?q="'+attachmentId+'" in parents and mimeType != "application/vnd.google-apps.folder"&access_token='+that.getAccessToken();
--code for render image links in browser
for(var i = 0; i < files.items.length; i++){
var div = $('<div class="row">');
var link = $('<a href="'+files.items[i]['downloadUrl']+"&access_token="+upload.getAccessToken()+'">');
if(files.items[i]['thumbnailLink'] != undefined){
var thumbnailUrl = files.items[i]['thumbnailLink'].split("=");
var linkUrl = thumbnailUrl[0]+"=w100-h100";
var image = $('<img src="'+files.items[i]['iconLink']+'" data-src="'+linkUrl+'" style="padding:2px; float:left; height:auto; width:auto;" onload="loadPreviewImage(this)">');
link.append(image);
}else{
div.append($('<img src="'+files.items[i]['iconLink']+'" style="padding:2px; float:left;">'));
}
link.append(files.items[i]['originalFilename']);
div.append(link);
td.append(div);
}
//function for loading thumbnail image
function loadPreviewImage(element){
var img = $(element);
img.src = img.dataset.src;
}
You error 403 may occur if you disable the Google Drive setting called Allow users to install Google Drive apps. This might be a good thing to check if you are certain that Google Drive is already enabled.
It is also suggested to clear your cache first. If that doesn't work, try running a malware scan using a malware/virus scanner.
You may check these related threads:
Getting a 403 - Forbidden for Google Service Account
403 Forbidden error when accessing Google Drive API downloadURL
The issue I was having was not seeing the Google Doc icon and instead seeing a broken image. But I was able to resolve it by realizing I was having the same request issue from a third-party so I went into the internet settings of the computer and resetting them to the default.
Start > Control Panel > Internet Options > Tabs (Security/Privacy/Advanced) = Default
I am trying to get the icon url/name corresponding to document retrieved from a SharePoint document library using the following javascript code (i am using JSOM):
function GetIcon(filename)
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var iconName;
iconName = web.mapToIcon(filename, '', SP.Utilities.IconSize.Size16);
var iconUrl = "/_layouts/images/" + iconName.get_value();
alert(iconUrl);
}
i cant observe any problem in the code but it always shows icon name as '0' than displaying the real icon name (i.e. icdoc.gif, ictxt.gif etc).
Am i missing something here?
Please guide me through this.
Your code works fine for me. It even works if the file does not exist and with an unrecognized file extension. Also, permissions do not appear to be involved.
If you browse to the page using Chrome and look on the Network tab of the Developer Tools (F12), you can view the raw response of the request. The name of the request is "Process Query". The image below shows the area I am referring to. This should give you some more insight on the problem.
iconName will be only populated after calling executeQueryAsync
context.executeQueryAsync(function() {
var iconUrl = "/_layouts/images/" + iconName.get_value();
alert(iconUrl);
}, function() { alert("Errors"); });
I would like to change (or add if it doesn't exist) to a PDF file with multiple pages the setting that will force the PDF to be opened in two page mode (PageLayout : TwoPageLeft for example).
I tried with that kind of JavaScript (given with Enfocus FullSwitch as example) :
if(($error == null) && ($doc != null))
{
try
{
$outfile = $outfolder + '/' + $filename + ".pdf";
$doc.layout = "TwoPageLeft";
$doc.saveAs( {cPath : $outfile, bCopy : true});
$outfiles.push($outfile);
}
catch(theError)
{
$error = theError;
$doc.closeDoc( {bNoSave : true} );
}
}
But it doesn't work as I would like (it will be opened with Acrobat Pro and saved as a new file without including the setting about the layout).
Does anyone can help me to correct that code to let JS open the PDF file, set the layout inside the PDF datas and save it out?
The readable information inside the PDF file should looks like this:
PageLayout/TwoPageLeft/Type/Catalog/ViewerPreferences
For information, I'm using FullSwitch (Enfocus) to handle files in a workflow, with Acrobat Pro, and at this time, it's only saving the file without adding the setting.
I can't find myself the answer over all the Web I searched recently, so I askā¦
Thanks in advance!
I think you copied the "this.layout = ..." line out of the Acrobat JavaScript reference documentation, correct?
When you write a JavaScript for Switch to execute (or rather for Switch to instruct Acrobat to execute for you), you should use the "$doc" variable to refer to the document Switch is processing.
So try changing the line:
$this.layout = "TwoColumnLeft";
to
$doc.layout = "TwoColumnLeft";
As you say the rest of the code works and the document is saved without errors I assume the rest of your code is correct. The change proposed here will make the adjustment in the document you're looking for.
I'm using Andrew Valums' Ajax Upload plugin (GitHub link). Here is some code from it:
qq.getUniqueId = (function(){
var id = 0;
return function(){ return id++; };
})();
It's kind of a long story, but I'm in a situation where, under certain circumstances, I'd like the qq.getUniqueId function to start with an ID other than 0. It can still increment by one; it just has to start with something other than 0. What's the best way to do that?
Here are the steps to create a test environment:
Download the plugin: http://github.com/valums/file-uploader/zipball/master
Unzip it and move the "client" folder onto a web server.
Open the "demo.htm" file in a text editor, search for action: 'do-nothing.htm', and add onComplete: function(id, fileName, responseJSON) {alert(id)}, right after that.
Open the "demo.htm" file in a web browser. Be sure to access it through a web server (as opposed to just opening the local file) or else it won't work.
Upload a file. It should alert a "0" after the upload finishes. See if you can modify it so that I can pass in a different starting number.
Thanks!
Try replacing the function with one that calls the original, but adds an offset:
function offsetUniqueId(n) {
var old = qq.getUniqueId;
qq.getUniqueId = function() {
return old() + n;
}
}
See http://jsfiddle.net/alnitak/gWjqX/
In our web site we have embedded PDFs, and we would like to make sure that when the user clicks a link inside the PDF, it opens in a new tab or window. We have no control over the PDFs so we cannot do anything with the links themselves.
Is it possible to intercept the request in some way, for example with onbeforeunload, and force the new page to open in a separate window?
No sorry, there is no way of doing this.
This is by design.
If it was possible it would be a major security breach.
You can manipulate the links inside the PDF document to run a javascript to open links in a new window/tab. Heres how I did it with C# and iTextSharp
public static MemoryStream OpenLinksInNewWindow(MemoryStream mySource)
{
PdfReader myReader = new PdfReader(mySource);
int intPageCount = myReader.NumberOfPages;
PdfDictionary myPageDictionary = default(PdfDictionary);
PdfArray myLinks = default(PdfArray);
//Loop through each page
for (int i = 1; i <= intPageCount; i++)
{
//Get the current page
myPageDictionary = myReader.GetPageN(i);
//Get all of the annotations for the current page
myLinks = myPageDictionary.GetAsArray(PdfName.ANNOTS);
//Make sure we have something
if ((myLinks == null) || (myLinks.Length == 0))
continue;
//Loop through each annotation
foreach (PdfObject myLink in myLinks.ArrayList)
{
//Convert the itext-specific object as a generic PDF object
PdfDictionary myLinkDictionary = (PdfDictionary)PdfReader.GetPdfObject(myLink);
//Make sure this annotation has a link
if (!myLinkDictionary.Get(PdfName.SUBTYPE).Equals(PdfName.LINK))
continue;
//Make sure this annotation has an ACTION
if (myLinkDictionary.Get(PdfName.A) == null)
continue;
//Get the ACTION for the current annotation
PdfDictionary myLinkAction = (PdfDictionary)myLinkDictionary.Get(PdfName.A);
//Test if it is a URI action
if (myLinkAction.Get(PdfName.S).Equals(PdfName.URI))
{
//Replace the link to run a javascript function instead
myLinkAction.Remove(PdfName.F);
myLinkAction.Remove(PdfName.WIN);
myLinkAction.Put(PdfName.S, PdfName.JAVASCRIPT);
myLinkAction.Put(PdfName.JS, new PdfString(String.Format("OpenLink('{0}');", myLinkAction.Get(PdfName.URI))));
}
}
}
//Next we create a new document add import each page from the reader above
MemoryStream myMemoryStream = new MemoryStream();
using (Document myDocument = new Document())
{
using (PdfCopy myWriter = new PdfCopy(myDocument, myMemoryStream))
{
myDocument.Open();
for (int i = 1; i <= myReader.NumberOfPages; i++)
{
myWriter.AddPage(myWriter.GetImportedPage(myReader, i));
}
// Insert JavaScript function to open link
string jsText = "function OpenLink(uri) { app.launchURL(uri, true); }";
PdfAction js = PdfAction.JavaScript(jsText, myWriter);
myWriter.AddJavaScript(js);
myDocument.Close();
}
}
return new MemoryStream(myMemoryStream.GetBuffer());
}
I got most code from this answer: https://stackoverflow.com/a/8141831/596758
According to Aaron Digulla's answer, you can't actually do this without modifying the PDF reader. Sorry!
I think you can't do this without changing Acrobat Reader... I suggest ... some other PDF reader which doesn't use a "single document" UI. [Foxit Reader] uses tabs and can display several PDF documents.
Could this be of interest: JS to open pdf's in new window? I'm assuming that you can at least add JavaScript to the page. You shouldn't have to modify the PDF's themselves in order to open them in a new window, and even though you might not be able to modify the url's themselves you should be free to open those links in any fashion you want on your page. Or am I completely misunderstanding your question? :)