Issues with previewing PDF files in AngularJS

I am trying to display a PDF preview on my website using the following code:

var $scope;
angular.module('miniapp', ['phonecatFilters', 'ngSanitize']);

function Ctrl($scope) {
    $scope.test = 'Example from: ';
    $scope.file = {
        pdf: true
    };
}
angular.module('phonecatFilters', []).filter('checkmark', function() {
  return function(input) {
    return input ? '\u2713' : '\u2718';
  };
}).filter('iconify', function () { 
        return function (input) {
            return '<object data="http://apps.deprigo.com/files/orders/1486031377-20022.pdf" type="application/pdf" width="100%" height="300"><embed src="http://apps.deprigo.com/files/orders/1486031377-20022.pdf" type="application/pdf" /></object>';
        }
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://code.angularjs.org/1.0.2/angular-sanitize.min.js"></script>
<div ng-app="miniapp">
  <div ng-controller="Ctrl">
      <h1>{{test}}</h1>
      <div>Preview PDF:<br /><span ng-bind-html='file.pdf | iconify'></span>
      </div>
  </div>
  <br>
  
</div>

The above code for displaying a PDF object is not working for me. Can someone please help me troubleshoot and figure out how to show the PDF on my webpage?

JSFIDDLE

Answer №1

After doing some research, I was able to find a solution. Below is the code snippet that helped me resolve the issue:

var $scope;
angular.module('miniapp', ['phonecatFilters', 'ngSanitize']);

function Ctrl($scope) {
    $scope.test = 'Example from: ';
    $scope.file = {
        pdf: true,
        doc: true
    };
}
angular.module('phonecatFilters', []).filter('iconify', function ($sce) { // Custom filter
        return function (file) {
            return $sce.trustAsHtml('<object data="http://apps.deprigo.com/files/orders/1486031377-20022.pdf" type="application/pdf" width="100%" height="300"><embed src="http://apps.deprigo.com/files/orders/1486031377-20022.pdf" type="application/pdf" /></object>');
        }
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://code.angularjs.org/1.0.2/angular-sanitize.min.js"></script>
<div ng-app="miniapp">
  <div ng-controller="Ctrl">
      <h1>{{test}}</h1>
      <div>Preview PDF:<br /><span ng-bind-html='file.pdf | iconify'></span>
      </div>
  </div>
  <br>
  
</div>

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

Forcing the execution of a filter on Angular's ng-repeat loop

Here is the code snippet I am dealing with: <div class="row" ng-repeat="(promptId, q) in (categoryFilteredObj = (categoryObj | custom:searchText:selectAllCheckbox:answeredCheckbox))"> Everything is functioning correctly. However, I have ...

What is the correct way to reference this data element in Ajax?

I am attempting to retrieve the elevation data for 732 meters from the JSON API response below: {"results":1,"data":[{"wind":{"degrees":200,"speed_kts":6,"speed_mph":7,"speed_mps":3,&quo ...

Having trouble displaying data from a MongoDB database using ng-repeat in AngularJS

Currently, I am facing an issue while trying to retrieve data from the database and display it using ng-repeat. The getAll function in the factory is fetching the data properly, returning an object with all the information. However, when I try to display t ...

The firebaseui.js code encountered an error because it was unable to read the property 'call' as it was undefined

Currently, I am facing an issue while trying to implement Firebase ui auth in my app by referring to Google's Github documentation. While the email sign-in functionality is working smoothly, I am encountering problems with the phone sign-in option. ...

NodeJS MySQL failing to retrieve the most updated data post-write

I'm struggling to solve an issue where after performing data operations (create, update, delete) and then querying for the data afterwards, I receive the previous version of the data rather than the updated version. For example: Let's say I hav ...

Ways to validate an element in an Array using Cypress dynamically

I have a question regarding the dynamic verification of Array elements. For my project, I need to suggest a price that will increase over time, and I require a script that can verify these elements dynamically. In the screenshot provided, you can see what ...

Executing ESM-Enabled Script in Forever

Is it possible to execute a script using the option -r esm in Forever? When I try to run the configuration below, I encounter an error message that reads: Unexpected token import. Here is the configuration: { "uid": "app", "script": "index.js", "s ...

Configuring a timeout for your Next.JS API can help optimize the performance

Due to restrictions on another API, my own API takes 10 minutes to return a result. When running locally, I am able to wait and successfully receive the data after 10 minutes. However, when deployed on Vercel, I encounter a timeout error (status code 504). ...

Maintain URL consistency with AngularJS's UI Router even when incorrectly typed

I am working with a standard module configuration that looks like this: app.config(function ($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/404"); $stateProvider .state('home', { url: "/home", ...

Tips for managing the State with AppContext()---Need help figuring out how to handle

Why does setting the state userHasAuthenticated to true in the login function result in isAuthenticated being logged as false (staying the same in App.js as well)? Also, when trying to use it in the Home Component, it still shows false. //-------------- ...

Toggle the Material UI checkbox based on the value received from an object input

I am facing an issue with an unchecked checkbox in my project. I am attempting to update its value based on data retrieved from an object. The object contains boolean values from an SQL query, either 'T' for true or 'F' for false. My in ...

What are the steps to effectively populate a mongoose schema?

In my application, I have a model for people: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const PersonSchema = new Schema({ name: String, cars: [{ type: Schema.types.ObjectId, ref: 'Cars' }] }); ...

Challenge encountered when redefining routes in Angular's routeProvider

Is there a definitive way to clear the definition of $routeProvider? Check out my updated plunker demo app.config(["$routeProvider", function($routeProvider) { $routeProvider .when("/forums", { templateUrl: "hotThread_forums.html", controller: "ForumsC ...

Dealing with information obtained through ajax requests

Trying to send data from modal using ajax. Below is the code snippet I am using, however, it seems that the first IF block is causing issues. If I comment it out, I can access the $_POST['id'] variable, but otherwise, it doesn't work. ...

What determines which HTML file is loaded based on the user's browser?

I've been searching online but can't find a definite answer - is it possible to load different HTML based on the type of browser being used? In my specific case, this seems to be the only solution. After trying everything else, it looks like the ...

Utilizing absolute positioning with a rotated div element

The situation I am facing involves a parent div and child div. The child div is positioned absolutely with respect to the parent div and has been rotated by an angle of 90 degrees. Due to the fact that the origin is located at the center of the child div ( ...

Navigating through the keys of a parameter that can assume one of three distinct interfaces in TypeScript: a guide

Here is a function example: function myFunc(input: A | B | C) { let key: keyof A | keyof B | keyof C; for(key in input) { let temp = input[key]; console.log(temp); } } The definitions for A, B, and C are as follows: interfa ...

How can I generate a PDF file with PHP?

Hello, I am working with PHP and MySQL. My goal is to fetch all the records from a table in my database and export them into a PDF file. Unfortunately, the code I have written only retrieves the first record from the table and not the rest of the records ...

An error occurred while trying to access properties of null during a promise, specifically when trying to read the 'parentNode' property - triggered by calling router.push({})

After updating my dependencies, I encountered an issue every time I clicked on a button to navigate to the next page. The error message Uncaught (in promise) TypeError: Cannot read properties of null (reading 'parentNode') would appear, even thou ...

What methods are available for identifying non-operational pointer-events?

According to this resource, Opera 12 does not support pointer-events, causing issues with my website. Interestingly, they do support the property in CSS but don't seem to implement it correctly. Modernizr's feature detection doesn't help in ...