Utilizing internal PDF links in a Microsoft UWP application

In the process of developing a UWP app using javascript, I have created a list of links that are connected to PDF files stored locally in the app. The ultimate goal is to offer a collection of hands-free documentation for the Hololens (Windows AR) device. To open the PDFs within the app, I use the following code:

Windows.System.Launcher.launchFileAsync(file)

Everything functions seamlessly as intended. However, a challenge arises with the hyperlinks contained within the PDF files which reference each other. While I can adjust these hyperlinks during the initial PDF generation, ensuring they still link to one another when opened in the user's default PDF application presents a dilemma. It should be noted that the default PDF application may vary between users, similar to how Adobe Acrobat works on Windows.

Below is the current working code snippet:

window.onload = function () {
    document.getElementById("#id").onclick = function (evt) {
        pdfopen("pdf.pdf")
    }

function pdfopen(pdf) {

var imageFile = "assets\\" + pdf;

// Retrieve the PDF file from the app's directory
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(imageFile).then(
  function (file) {
      // Launch the retrieved file using the default app

      var options = new Windows.System.LauncherOptions();
      Windows.System.Launcher.launchFileAsync(file)
  }
);

Any assistance in solving this hyperlink referencing issue would be greatly appreciated! <3

Answer №1

Is there a way to ensure that hyperlinks still work properly when opened in the user's default PDF app?

By using the `launchFileAsync` method without specifying `LauncherOptions`, it will always open PDF files with the default app.

If you want to specify a particular app to open PDF files, you can utilize the `LauncherOptions.TargetApplicationPackageFamilyName` property to set the package family name of the desired app. Then include these options when calling the `LaunchFileAsync(IStorageFile, LauncherOptions)` method to open the file with the specified app.

For example, to use Microsoft Edge as the default app for opening PDF files:

var options = new Windows.System.LauncherOptions();
options.TargetApplicationPackageFamilyName = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe";
Windows.System.Launcher.launchFileAsync(file, options).then(
  function(success) {
    if (success)
    {
        // File launched successfully
    }
    else
    {
        // Failed to launch file
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Webshot is unable to retain any images

I attempted to utilize the Node package Webshot. The function is being executed, "OK" is printed to the console, but no files are saved to the specified folder. What could I be overlooking? if (Meteor.isServer) { var webshot = Meteor.npmRequire(&apos ...

Retrieving objects from Firebase in a loop using promises

Seeking guidance on handling promises in AngularJS as a newcomer. Struggling with merging data from two asynchronous arrays into a single array within a for-loop. Encountering a bug where the same picture is displayed for all entries despite different user ...

Generate a CSV file using Javascript

I am working with an HTML table (table id='testTable') and a button in the HTML code: <button id="btnExport" onclick="javascript:xport.toCSV('testTable');">CSV</button> There is also JavaScript code involved: toCSV: func ...

An error has occurred in Node.js: SyntaxError - Unexpected token ]

Here is the code snippet I am working with: app.get("/posts/:slug", function(request, response) { var slug = request.params.slug; connection.query("SELECT * from `posts` WHERE slug = ?", [ slug ], function(err, rows) { var post = rows[]; ...

What is the best way to obtain the current route name within a Component?

Is it possible to retrieve the current route name in a controller? I have attempted using this.route, this.currentRoute, and this._routerRoot, but none of them seem to work. computed: { currentRoute:{ get(){ console.log(this.__routerRoo ...

What are some ways I can incorporate modular constants into my Firebase Functions?

While working with Firebase functions, I've come across the option to organize functions into separate files for easier maintenance. You can find the documentation I used here. Currently, I'm exploring how to incorporate modular string constants ...

Achieving a smooth sliding motion with the help of jQuery animation

Here is the code snippet: In HTML: <div> <div id="div1">12345</div> <div id="div2">67890</div> <div id="div3"><a href="#" id="slide">abcde</a></div> <div id="pad" style="display:non ...

Exploring the contents of a dropdown menu by navigating through a tree structure in React JS

A unique custom component has been developed, featuring a dropdown with a tree-like structure inside that allows users to search for values. However, it seems that the search function only works after reaching two levels of the tree structure. Currently, ...

Creating PDF documents using PHP

I have been working on a PHP program that extracts data from the database and creates customized sheets for each person in the database. My initial approach was to convert these sheets into PDF format to avoid issues with headers, footers, and printer marg ...

Can you explain the purpose of useEffect in React?

As a beginner in learning React, I have been able to grasp the concept of the useState hook quite well. However, I am facing some difficulties understanding the useEffect hook. I have tried looking through the documentation, searching online, and even wat ...

Encountering Uncaught Promise Rejection Warning in Node.js

I can't figure out why I am receiving this error or warning when my code appears to be correct. Below is a snippet of the UserModel that I have been working on: const fs = require('fs'); class UserModel { constructor(filename) { ...

Sorting functionality in Dyntable is not functioning properly when called from an Ajax request

I can't seem to get DynaTable with Ajax to work properly. Sorting, searching, and pagination are not functioning as expected. When I click on the column header, nothing changes in my table. Could someone please assist me? Below is my code snippet: H ...

Tips for connecting to multiple items in an md-select element from within a directive

Looking to develop a straightforward directive that displays either a textbox or dropdown based on whether an array is provided for the model property on the scope. Any value other than explicitly setting false in the directive markup such as multiple="fa ...

Oops! The regular expression flag "ajax" in Javascript is not valid and is causing

This is my function: public ActionResult RetrieveData(int id) { string name = "Jane"; return Json( new {result=name}); } I'm attempting to fetch information from this function using the code below, but I keep getting errors. Could y ...

What is the best way to implement a composite primary key in DocumentClient.batchWrite()?

I am attempting to conduct a batch delete process based on the instructions provided in this documentation. The example given is as follows: var params = { RequestItems: { /* required */ '<TableName>': [ { DeleteRequest: ...

Displaying a Countdown in a Django Loop: A Step-by-Step

Hey there, I've got a Javascript countdown nested in a Django for loop that's causing some trouble by displaying multiple instances. Currently, only the first countdown works when I click on any of the start buttons. I'd like each button to ...

Tracking the advancement of synchronous XMLHttpRequest requests

Within the client-side environment, there exists a File-Dropzone utilizing the HTML5 File-API which allows users to drop multiple files for uploading to the server. Each file triggers the creation of a new XMLHttpRequest Object that asynchronously transfer ...

React JS does not allow TextField and Select to change

I am relatively new to full stack development and I am currently working on a project to enhance my understanding of frontend development with React JS. While working on this project, I have been using Redux without any issues so far. However, I am facing ...

The value of Express session within the callback is not retained when accessed outside

I'm encountering an issue with my Express route setup. Here's the current code snippet: app.get("/route", function(req, res){ if (someBoolean){ someFunction(stuff, function(user){ ... req.session.user = user; ...

Ways to determine whether a DOM textnode is a hyperlink

Is there a more foolproof method for determining if a DOM textnode represents a hyperlink? The code snippet below currently only checks if the node is directly enclosed in an anchor tag, which may not be sufficient if the <a> element is higher up i ...