cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Java script to select from locally saved PDFs

Visitor

Java script to select from locally saved PDFs

I want to select a file with the file widget similar to how the code below changes images:

$scope.view.wdg['part_img']['imgsrc'] = 'app/resources/Uploaded/1606XLB.png';

 

I think the script should look similar to this:
$scope.view.wdg['part_file']['fileurl'] = 'app/resources/Uploaded/1606-in006_-en-e.pdf';

 

Where 'fileurl' is used, what is the correct call out?

This needs be used completely offline. We want locally saved user manual PDFs to associate with clickable parts.

 

 

This is a script related to the file widget and source of the File URL.

2 REPLIES 2

Re: Java script to select from locally saved PDFs

Hi @ForrestA ,

I did some  tests , where tried   to display  PDFs on mobile devices. 

I observered thre  a difference between the behavior in  preview mode and on mobile devices /tested on IOS IPad and on Android Samsung Galaxy S9+

2020-02-11_15-24-30.gif

2020-02-11_15-37-15.gif

 

Here in preview mode in the one test - studio  displays the  pdf directly on the studio panel but this is different on the mobile device (both ios and android) there all 3 tests  will display the pdf in external pdf applicaiton.

I used the following definiton /in Home.json / to see the relevant  properties  settings of the widgets:

 

 

Here the defintion of the Hyperlink and the file Widgets
....
                                          "name": "twx-col",
                                          "children": [
                                            {
                                              "name": "twx-container-content",
                                              "children": [
                                                {
                                                  "attributes": {
                                                    "twx-widget": "",
                                                    "widget-id": "hyperlink-1",
                                                    "widget-name": "hyperlink-1",
                                                    "click-expression": "hyperlinkclick();",
                                                    "text": "sample PDF link",
                                                    "url": "https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf"
                                                  },
                                                  "name": "twx-hyperlink"
                                                }
                                              ]
                                            }
                                          ]
                                        },
                                        {
                                          "attributes": {
                                            "twx-widget": "",
                                            "widget-id": "column-4",
                                            "widget-name": "column-4",
                                            "is-widget-container": "true"
                                          },
                                          "name": "twx-col",
                                          "children": [
                                            {
                                              "name": "twx-container-content",
                                              "children": [
                                                {
                                                  "attributes": {
                                                    "twx-widget": "",
                                                    "widget-id": "file-1",
                                                    "widget-name": "file-1",
                                                    "click-expression": "filelinkclick();",
                                                    "text": "fileURL",
                                                    "url": "Uploaded/[BD-Logbuch]20190208-20190310.pdf"
                                                  },
                                                  "name": "twx-file"
                                                }
....
and here the definiton of the toggle
....
 {
                              "name": "twx-container-content",
                              "children": [
                                {
                                  "attributes": {
                                    "twx-widget": "",
                                    "widget-id": "toggle-1",
                                    "widget-name": "toggle-1",
                                    "click-expression": "toggleLink();",
                                    "label": "Show PDF"
                                  },
                                  "name": "twx-toggle"
                                }

 

And the code was something like this:

 

//////////////////////////////////////////////////////////////////
 $scope.toggleLink = function() {
    
   if ( $scope.view.wdg['toggle-1']['value']==true) {

     $scope.clickLink1();
     $scope.clickFile1();
     window.location=$scope.view.wdg['file-1']['url']
   }
   
 }

///////
$scope.hyperlinkclick = function() {console.log("INFO -> Hyperlink click was called")}
$scope.filelinkclick  = function() {console.log("INFO -> File click was called")}

$scope.clickLink =function () { 
  console.log("click----Link ---> start"); return;
   
  twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="hyperlink-1"]'), 'app.view["Home"].wdg["hyperlink-1"].svc.click');
  twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="file-1"]'), 'app.view["Home"].wdg["file-1"].svc.click');
  console.log("click----Link ---> finish");                             
}
$scope.clickLink1= function(){twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="hyperlink-1"]'), 'click');};
$scope.clickFile1= function(){twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="file-1"]'), 'click');};

//////////////
 $scope.toggleButton = function() {
    
   if ( $scope.view.wdg['toggleButton-1']['pressed']==true) {
      
     window.location='app/resources/Uploaded/%5BBD-Logbuch%5D20190208-20190310.pdf'
     console.log($scope.view.wdg['file-1']['url'])
   }
   $timeout(function () { $scope.view.wdg['toggleButton-1']['pressed']=false;}, 1500); 
 }
//////////////////

 

I attached also the studio project where I tested it

 

 

Re: Java script to select from locally saved PDFs

This is amazing and very impressive, but I need it to work when the device is in airplane mode. A Network connection will slow processing down too much.

 

After testing without a network, the widgets return blank web pages or are unresponsive. 

Announcements
Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection