Giter Site home page Giter Site logo

vadimdez / ng2-pdf-viewer Goto Github PK

View Code? Open in Web Editor NEW
1.3K 31.0 402.0 100.13 MB

๐Ÿ“„ PDF Viewer Component for Angular

Home Page: https://vadimdez.github.io/ng2-pdf-viewer/

License: MIT License

HTML 14.26% TypeScript 50.19% JavaScript 2.92% CSS 1.37% SCSS 31.26%
pdf-viewer-component pdf pdf-viewer angular2 angular angular12

ng2-pdf-viewer's Introduction

Angular PDF Viewer

downloads npm version Gitter PayPal donate button

PDF Viewer Component for Angular 5+

Demo page

https://vadimdez.github.io/ng2-pdf-viewer/

Stackblitz Example

https://stackblitz.com/edit/ng2-pdf-viewer

Blog post

https://medium.com/@vadimdez/render-pdf-in-angular-4-927e31da9c76

Overview

Install

Angular >= 12

npm install ng2-pdf-viewer

Partial Ivy compilated library bundles.

Angular >= 4

npm install ng2-pdf-viewer@^7.0.0

Angular < 4

npm install ng2-pdf-viewer@~3.0.8

Usage

In case you're using systemjs see configuration here.

Add PdfViewerModule to your module's imports

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';

import { PdfViewerModule } from 'ng2-pdf-viewer';

@NgModule({
  imports: [BrowserModule, PdfViewerModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})

class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);

And then use it in your component

import { Component } from '@angular/core';

@Component({
  selector: 'example-app',
  template: `
  <pdf-viewer [src]="pdfSrc"
              [render-text]="true"
              [original-size]="false"
              style="width: 400px; height: 500px"
  ></pdf-viewer>
  `
})
export class AppComponent {
  pdfSrc = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
}

Options

[src]

Property Type Required
[src] string, object, UInt8Array Required

Pass pdf location

[src]="'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf'"

For more control you can pass options object to [src]. See other attributes for the object here.

Options object for loading protected PDF would be:

{
 url: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
 withCredentials: true
}

[page]

Property Type Required
[page] or [(page)] number Required with [show-all]="false" or Optional with [show-all]="true"

Page number

[page]="1"

supports two way data binding as well

[(page)]="pageVariable"

If you want that the two way data binding actually updates your page variable on page change/scroll - you have to be sure that you define the height of the container, for example:

pdf-viewer {
    height: 100vh;
}

[stick-to-page]

Property Type Required
[stick-to-page] boolean Optional

Sticks view to the page. Works in combination with [show-all]="true" and page.

[stick-to-page]="true"

[render-text]

Property Type Required
[render-text] boolean Optional

Enable text rendering, allows to select text

[render-text]="true"

[render-text-mode]

Property Type Required
[render-text-mode] RenderTextMode Optional

Used in combination with [render-text]="true"

Controls if the text layer is enabled, and the selection mode that is used.

0 = RenderTextMode.DISABLED - disable the text selection layer

1 = RenderTextMode.ENABLED - enables the text selection layer

2 = RenderTextMode.ENHANCED - enables enhanced text selection

[render-text-mode]="1"

[external-link-target]

Property Type Required
[external-link-target] string Optional

Used in combination with [render-text]="true"

Link target

  • blank
  • none
  • self
  • parent
  • top
[external-link-target]="'blank'"

[rotation]

Property Type Required
[rotation] number Optional

Rotate PDF

Allowed step is 90 degree, ex. 0, 90, 180

[rotation]="90"

[zoom]

Property Type Required
[zoom] number Optional

Zoom pdf

[zoom]="0.5"

[zoom-scale]

Property Type Required
[zoom-scale] 'page-width'|'page-fit'|'page-height' Optional

Defines how the Zoom scale is computed when [original-size]="false", by default set to 'page-width'.

  • 'page-width' with zoom of 1 will display a page width that take all the possible horizontal space in the container

  • 'page-height' with zoom of 1 will display a page height that take all the possible vertical space in the container

  • 'page-fit' with zoom of 1 will display a page that will be scaled to either width or height to fit completely in the container

[zoom-scale]="'page-width'"

[original-size]

Property Type Required
[original-size] boolean Optional
  • if set to true - size will be as same as original document
  • if set to false - size will be as same as container block
[original-size]="true"

[fit-to-page]

Property Type Required
[fit-to-page] boolean Optional

Works in combination with [original-size]="true". You can show your document in original size, and make sure that it's not bigger then container block.

[fit-to-page]="false"

[show-all]

Property Type Required
[show-all] boolean Optional

Show single or all pages altogether

[show-all]="true"

[autoresize]

Property Type Required
[autoresize] boolean Optional

Turn on or off auto resize.

!Important To make [autoresize] work - make sure that [original-size]="false" and pdf-viewer tag has max-width or display are set.

[autoresize]="true"

[c-maps-url]

Property Type Required
[c-maps-url] string Optional

Url for non-latin characters source maps.

[c-maps-url]="'assets/cmaps/'"

Default url is: https://unpkg.com/[email protected]/cmaps/

To serve cmaps on your own you need to copy node_modules/pdfjs-dist/cmaps to assets/cmaps.

[show-borders]

Property Type Required
[show-borders] boolean Optional

Show page borders

[show-borders]="true"

(after-load-complete)

Property Type Required
(after-load-complete) callback Optional

Get PDF information with callback

First define callback function "callBackFn" in your controller,

callBackFn(pdf: PDFDocumentProxy) {
   // do anything with "pdf"
}

And then use it in your template:

(after-load-complete)="callBackFn($event)"

(page-rendered)

Property Type Required
(page-rendered) callback Optional

Get event when a page is rendered. Called for every page rendered.

Define callback in your component:

pageRendered(e: CustomEvent) {
  console.log('(page-rendered)', e);
}

And then bind it to <pdf-viewer>:

(page-rendered)="pageRendered($event)"

(pages-initialized)

Property Type Required
(pages-initialized) callback Optional

Get event when the pages are initialized.

Define callback in your component:

pageInitialized(e: CustomEvent) {
  console.log('(pages-initialized)', e);
}

And then bind it to <pdf-viewer>:

(pages-initialized)="pageInitialized($event)"

(text-layer-rendered)

Property Type Required
(text-layer-rendered) callback Optional

Get event when a text layer is rendered.

Define callback in your component:

textLayerRendered(e: CustomEvent) {
  console.log('(text-layer-rendered)', e);
}

And then bind it to <pdf-viewer>:

(text-layer-rendered)="textLayerRendered($event)"

(error)

Property Type Required
(error) callback Optional

Error handling callback

Define callback in your component's class

onError(error: any) {
  // do anything
}

Then add it to pdf-component in component's template

(error)="onError($event)"

(on-progress)

Property Type Required
(on-progress) callback Optional

Loading progress callback - provides progress information total and loaded bytes. Is called several times during pdf loading phase.

Define callback in your component's class

onProgress(progressData: PDFProgressData) {
  // do anything with progress data. For example progress indicator
}

Then add it to pdf-component in component's template

(on-progress)="onProgress($event)"

Render local PDF file

In your html template add input:

<input (change)="onFileSelected()" type="file" id="file">

and then add onFileSelected method to your component:

onFileSelected() {
  let $img: any = document.querySelector('#file');

  if (typeof (FileReader) !== 'undefined') {
    let reader = new FileReader();

    reader.onload = (e: any) => {
      this.pdfSrc = e.target.result;
    };

    reader.readAsArrayBuffer($img.files[0]);
  }
}

Set custom path to the worker

By default the worker is loaded from cdn.jsdelivr.net.

In your code update path to the worker to be for example /pdf.worker.js

(window as any).pdfWorkerSrc = '/pdf.worker.js';

This should be set before pdf-viewer component is rendered.

If you ever have a (super rare) edge case where you run in an environment that multiple components are somehow loaded within the same web page, sharing the same window, but using different versions of pdf.worker, support has been added. You can do the above, except that you can append the specific version of pdfjs required and override the custom path just for that version. This way setting the global window var won't conflict.

(window as any)["pdfWorkerSrc2.14.305"] = '/pdf.worker.js';

Search in the PDF

Use eventBus for the search functionality.

In your component's ts file:

  • Add reference to pdf-viewer component,
  • then when needed execute search() linke this:
@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;

search(stringToSearch: string) {
  this.pdfComponent.eventBus.dispatch('find', {
    query: stringToSearch, type: 'again', caseSensitive: false, findPrevious: undefined, highlightAll: true, phraseSearch: true
  });
}

Contribute

See CONTRIBUTING.md

Donation

If this project help you reduce time to develop, you can give me a cup of tea :)

paypal

License

MIT ยฉ Vadym Yatsyuk

ng2-pdf-viewer's People

Contributors

adrienfery avatar antonioda avatar arturovt avatar borys-kupar avatar colint avatar dependabot[bot] avatar fengerzh avatar ftaffelt avatar ghetolay avatar greenkeeper[bot] avatar jain-amit avatar johnwest80 avatar johnwesta avatar khattaksd avatar mix5003 avatar mmaclach avatar paulvandenburg avatar quentinchaumont avatar rahulrajsr2714 avatar rlesavre avatar seopei avatar sihu avatar snyk-bot avatar srizzon avatar stranne avatar stygian-desolator avatar timothyblue avatar vadimdez avatar victorbjorn avatar zlepper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng2-pdf-viewer's Issues

Error: Invalid XRef stream header

I need to load dynamic pdf, But i was getting error but it was working while loading file

Error: Invalid XRef stream header main.js:115144:6
XRef_readXRef@http://localhost:8100/build/main.js:161171:10
XRef_parse@http://localhost:8100/build/main.js:160817:22
PDFDocument_setup@http://localhost:8100/build/main.js:167869:7
PDFDocument_parse@http://localhost:8100/build/main.js:167765:7
LocalPdfManager_ensure/<@http://localhost:8100/build/main.js:168032:19
t@http://localhost:8100/build/polyfills.js:3:11329
LocalPdfManager_ensure@http://localhost:8100/build/main.js:168027:14
BasePdfManager_ensureDoc@http://localhost:8100/build/main.js:167979:14
loadDocument/</<@http://localhost:8100/build/main.js:168460:9
O</d</t.prototype.invoke@http://localhost:8100/build/polyfills.js:3:9092
NgZone</NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvoke@http://localhost:8100/build/main.js:36644:28
O</d</t.prototype.invoke@http://localhost:8100/build/polyfills.js:3:9030
O</v</e.prototype.run@http://localhost:8100/build/polyfills.js:3:6462
h/<@http://localhost:8100/build/polyfills.js:3:4581
O</d</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9712
NgZone</NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvokeTask@http://localhost:8100/build/main.js:36635:28
O</d</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9640
O</v</e.prototype.runTask@http://localhost:8100/build/polyfills.js:3:7064
i@http://localhost:8100/build/polyfills.js:3:3664
t/this.invoke@http://localhost:8100/build/polyfills.js:3:10876

How to avoid the 'Access-Control-Allow-Origin' error?

Hi!

I'm trying to show a pdf from google drive and I have this error:

XMLHttpRequest cannot load https://drive.google.com/uc?export=download&id=0B6YhVF9p-y2AbUJlcEI5ZGZ5Z2c. Redirect from 'https://drive.google.com/uc?export=download&id=0B6YhVF9p-y2AbUJlcEI5ZGZ5Z2c' to 'https://doc-0s-7s-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7dโ€ฆ82732000000/13929360962754196313/*/0B6YhVF9p-y2AbUJlcEI5ZGZ5Z2c?e=download' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Any idea?

Unit tests fails on "Binding to event attribute 'on-load-complete' is disallowed for security reasons"

I am using Angular 2.0.0, I am trying to write a unit test, I have [on-load-complete]="onLoadComplete" in my HTML template when i try to run my test the error

Binding to event attribute 'on-load-complete' is disallowed for security reason

my test is basically trying to create the component that the viewer is impeded in.

it('should create an instance', () => { expect(profileResumeComponent).toBeTruthy(); });

Any suggestions?

background-color css causes PDF text to become invisible.

If either the containing div specifies a background-color css property, or the pdf-viewer element itself contains this property, the PDF text is no longer visible. I can tell it is still there as I can select it, but you can't see it.

Specifically, in either of the following examples, the text and background color will both be red and thus, the text will not be visible:

        <div>
           <pdf-viewer  [src]="pdfSrc"
                        [(page)] = "page"
                        [original-size]="true"
                        style="display: block;background-color: red;">
           </pdf-viewer>
        </div>
        <div style="background-color: red;">
           <pdf-viewer  [src]="pdfSrc"
                        [(page)] = "page"
                        [original-size]="true"
                        style="display: block;">
           </pdf-viewer>
        </div>

pdfjsLib is undefined

Hello,

I'm trying to use the #master version in my project, and I got this error when website is loaded :
pdfjsLib is undefined

I'm not sure but it looks like it comes from the angular-cli I updated in my project.

Someone already got this problem ?

404 Error with /node_modules/pdfjs-dist/build/pdf.combined during npm start

I am getting this error during npm start without .js extension - but the pdf.combined.js is in that directory.
if I added "pdf.combined" with ".js" in node_modules/ng2-pdf-viewer/dist/pdf-viewer.component.min.js, the app can start.

Please kindly advise the issue.

Thanks!

16.08.27 18:40:16 404 GET /node_modules/pdfjs-dist/build/pdf.combined

[show-all] is showing first two page only.

show-all is showing first two page only.

<pdf-viewer [src]="pdfSrc"
[page]="page"
[original-size]="false"
[render-text]="false"
[show-all]="true"
style="display: block;">

pdfSrc: string = "../assets/pdf/Cuelinks_SDK-Integration_Guide.pdf"
page: number = 5;

I dont know what value give in page.

Accessing PDF properties typescript example

Is there a typescript example for accessing the pdf properties? Specifically i'd like to get the numPages property so i can restrict the previous and next buttons and only show them if there is a next or previous page. I noticed the app.component.js does this through an onLoadComplete binding to a "pdf" variable and is accessed by doing it thru {{ pdf?.numPages }}. Could we get an example of this using typescript? Thanks much!

Support text-to-speech

sir,if u tell me how to create i will definitely try to build and do a pull request.......

EXCEPTION: Error: Uncaught (in promise): No Directive annotation found on PdfViewerComponent

pdf.html

<ion-header>
  <ion-toolbar>
    <ion-title>
      {{pdf.name}}
    </ion-title>
    <ion-buttons start>
      <button (click)="dismiss()">
        <span primary showWhen="ios">Cancel</span>
        <ion-icon name="md-close" showWhen="android,windows"></ion-icon>
      </button>
    </ion-buttons>
  </ion-toolbar>
</ion-header>

<ion-content>
  <pdf-viewer src="{{pdf.url}}" [original-size]="false" [show-all]="true"></pdf-viewer>
</ion-content>

pdf.ts

import { Component } from '@angular/core';
import { Platform, NavParams, ViewController } from 'ionic-angular';
import { PdfViewerComponent } from 'ng2-pdf-viewer';

@Component({
  templateUrl: 'build/pages/pdf/pdf.html',
  directives: [PdfViewerComponent]
})

export class PDFContentPage {
  pdf;

  constructor(
      public platform: Platform,
      public params: NavParams,
      public viewCtrl: ViewController
  ) {
    this.pdf = {
      name: this.params.get("name"),
      url:  this.params.get("url"),
    }
  }

  dismiss() {
    this.viewCtrl.dismiss();
  }
}

Got stuck when using @0.0.9, error stack:
1
2
3
4
5

Really have no idea what's going on this time.

'initialPage' since it isn't a known property of 'pdf-viewer'.

I import the library and use the HTML example, but get the following error

Can't bind to 'initialPage' since it isn't a known property of 'pdf-viewer'.
1. If 'pdf-viewer' is an Angular component and it has 'initialPage' input, then verify that it is part of this module.
2. If 'pdf-viewer' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message.
 ("
  </div>
  <pdf-viewer [src]="pdfSrc" 
              [ERROR ->][initialPage]="page" 
              [original-size]="true" 
              style="display: block;">

Search in the code effectively this property does not exist, is a error in the documentation?

Load Local file

Hi

How can I load local file in pdf-viewer Like you loading in your DEMO. It showing me below error.

XMLHttpRequest cannot load file:///home/shabbir/Desktop/20-0226-02FMBS.nagar.pdf. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Ability to create a preview/thumbnail

Thank you very much for sharing this library!

I've followed this tuto in order to create a pdf preview (thumbnail). Unfortunately, it is not yet possible to do that with your library... I would realy appreciate if someone could help add this feature to the project!

Is it possible to enable hyperlinks in the rendered PDF?

https://github.com/mozilla/pdf.js/blob/master/examples/components/simpleviewer.js#L37

// (Optionally) enable hyperlinks within PDF files.
var pdfLinkService = new PDFJS.PDFLinkService();

Is it possible to show the hyperlinks in proper annotated PDF ?

other related post:
http://stackoverflow.com/questions/37016124/display-annotations-hyperlinks-using-pdf-js

http://stackoverflow.com/questions/33813373/pdf-js-how-to-open-hyperlinks-in-a-new-tab-window

nativeElement.offsetWidth is 0 with bootstrap v4.0.0-alpha.6

After updating bootstrap to v4.0.0-alpha.6 from alpha.5, I see a problem with the code below.

if (!this._originalSize) { viewport = page.getViewport(this.element.nativeElement.offsetWidth / viewport.width, this._rotation); }

In my case, the offsetWidth is 0 so canvas width/height become 0 too which leads to no pdf page displayed.

I use ng-bootstrap
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.18"

and bootstrap.min.css in index.html

(problem, offsetWidth is 0. )
image

(same code, just take out bootstrap.min.css from index.html then offsetWidth is there so no problem to see pdf pages.)
image

@VadimDez, I am not sure this is an issue of the bootstrap 4 version or you can fix with your code. And, if you need a re-pro, I will try to create one.

Limit [page]

Limit [page] when it goes beyond first and last page

Trying to implement on ionic2 apps but failed

I followed your instruction for installation, and can import PdfViewerComponent in typescript file

pdf.ts

import {Component} from "@angular/core";
import {Platform, NavParams, ViewController} from 'ionic-angular';
import {PdfViewerComponent} from 'ng2-pdf-viewer';

@Component({
  templateUrl: 'build/pages/pdf/pdf.html',
  directives: [PdfViewerComponent]
})

export class PDFContentPage {
  pdf;

  constructor(
      public platform: Platform,
      public params: NavParams,
      public viewCtrl: ViewController
  ) {
    this.pdf = {
      name: this.params.get("name"),
      url:  this.params.get("url"),
    }
  }

  dismiss() {
    this.viewCtrl.dismiss();
  }
}

pdf.html

<ion-header>
  <ion-toolbar>
    <ion-title>
      {{pdf.name}}
    </ion-title>
    <ion-buttons start>
      <button (click)="dismiss()">
        <span primary showWhen="ios">Cancel</span>
        <ion-icon name="md-close" showWhen="android,windows"></ion-icon>
      </button>
    </ion-buttons>
  </ion-toolbar>
</ion-header>

<ion-content>
  <pdf-viewer src="{{pdf.url}}" original-size="true" show-all="true"></pdf-viewer>
</ion-content>

And the chrome dev tools shows the following

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8100/build/js/app.bundle.worker.js

cap1

If I copy the pdf.worker.js file from node_modules/pdfjs-dist/build/pdf.worker.js to www/js/ and rename the file to app.bundle.worker.js, it works fine.

cap2

But ionic will recompile the js before build so this is not a solution. I try to trace the error stack and find some clue:

pdf.js (line 9565)

var PDFWorker = (function PDFWorkerClosure() {
  var nextFakeWorkerId = 0;

  function getWorkerSrc() {
    if (typeof workerSrc !== 'undefined') {
      return workerSrc;
    }
    if (getDefaultSetting('workerSrc')) {
      return getDefaultSetting('workerSrc');
    }
    if (pdfjsFilePath) {
      return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
    }
    error('No PDFJS.workerSrc specified');
  }

Ionic2 will compile all js and ts to a single js file called app.bundle.js. The reason why getting "app.bundle.worker.js" is because of the

if (pdfjsFilePath) {
      return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
    }

trying to change pdf.js -> pdf.worker.js but failed in this scenario and changed app.bundle.js -> app.bundle.worker.js

That what I knew so far and got stuck. Got no idea how to solve this. Any help or guidance would be appreciated.

Disable print and download button

Hi,
Is there a way I can disable the download and print button on the pdf viewer. I would like the pdfs to be view only and not possible to be downloaded or printed. Thanks

Make text selectable ?

Hello,

I don't know if it's because ng2-pdf-viewer use a canvas, but we can't select text in the pdf viewer.
Someone has an idea to make it available ?

Thanks

Hyperlinks are not working

I am able to view the pdf on the browser but none of the hyperlink works. Is there any option to enable it as I am already using [render-text]="true" and that did not enable hyperlinks?

Is it possible to not load first page initially

I'm using angular 2.0.0 and would like to load a page of a pdf file on any possible page number. It doesn't take the [page] input till the pdf is loaded and displayed. I used setTimeout to delay the event of reassigning the page number to [page] by 1 second, and it works.
But the pdf viewer still displays first page initially and goes to that page 1 second later, which is not so ideal.

Another attempt tried is the call back function
[after-load-complete]="loadComplete", but in loadComplete function the scope of the object is lost and this was referring to the ng2-pdf-viewer library, instead of the Component object. So it's not possible to reassign page there either.

Is the feature of ng2-pdf-viewer to allow only first page load initially? Is there a better solution if I want to load any page initially by using this?

Access to component context through Output ?

Issue : Could not access to my component variables on after-load callback function.

// my-component.ts
onLoaded(pdf) {
  this.loading = false // <- loading unknown
}

Proposal: Use Output instead of Input with pdf as return value.

// pdf-viewer.component.ts
@Output() afterLoadCompleteEmitter = new EventEmitter()
...
if (this.afterLoadComplete && typeof this.afterLoadComplete === 'function') {
  this.afterLoadComplete(pdf);
}
...
afterLoadComplete(pdf) {
  this.afterLoadCompleteEmitter.emit({ value: pdf })
}


// my.component.html
<pdf-viewer [src]="selected.value"
            (afterLoadComplete)="onLoaded($event)"
            [show-all]="true"
            [page]="1" 
            [original-size]="true">
</pdf-viewer>

// my-component.ts
onLoaded(event) {
  const pdf = event.value
  this.loading = false // <- loading known
}

Can't seem to scroll

I have the following code:

<pdf-viewer [src]="pdfSrc"
            [page]="page"
            [original-size]="false"
            [show-all]="true"
            style="display: block;"></pdf-viewer>

Now then, the first page of the PDF is displaying, but the page isn't scrollable. I have tried applying the following CSS:

pdf-viewer {
  border: 1px solid red;
  overflow: scroll;
}

The border is appearing, but the page isn't scrolling. What am I missing?

PDF is drawn behind the container

I updated ng2-pdf-viewer to 0.1.5. After that update the pdf is drawn behind the container. I inspected the HTML using Google Chrome developer tools. Then I noticed that the z-index of the canvas (pdf-viewer -> div -> div -> canvas) is -1. When I removed that style it works properly. The canvas looks like follows.

height="684" width="913" style="position: absolute; top: 0px; left: 0px; z-index: -1;"

This is my template code.
<pdf-viewer
*ngIf="(getCurrentDocumentType() === 'PDF' && isPreviewAvailable)"
[src]="data"
[page]="currentPage"
[render-text]="true"
[zoom]="zoom"
[original-size]="false"
[show-all]="false"
[after-load-complete]="callBackFn">

Please provide me a solution for this. Thank you.

Unable to declare in App Module

Uncaught Error: Unexpected value 'PdfViewerComponent' declared by the module 'AppModule'
at http://localhost:3000/vendor.bundle.js:12183:31
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/vendor.bundle.js:12170:49)
at RuntimeCompiler._compileComponents (http://localhost:3000/vendor.bundle.js:18476:47)
at RuntimeCompiler.compileModuleAndComponents (http://localhost:3000/vendor.bundle.js:18414:37)
at RuntimeCompiler.compileModuleAsync (http://localhost:3000/vendor.bundle.js:18405:21)
at PlatformRef
.bootstrapModuleWithZone (http://localhost:3000/vendor.bundle.js:26818:25)
at PlatformRef
.bootstrapModule (http://localhost:3000/vendor.bundle.js:26800:21)
at HTMLDocument.main (http://localhost:3000/main.bundle.js:89232:10)
at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.bundle.js:15379:38)
at Zone.runTask (http://localhost:3000/polyfills.bundle.js:15279:48)
at HTMLDocument.ZoneTask.invoke (http://localhost:3000/polyfills.bundle.js:15447:34)

First page always bigger

Hello,

With [original-size]="false",
first page is always bigger than others.
With [original-size]="true",
first page has the same size than others.

I tried this with 3 differents pdf.

Webpack Compatibility

Hi!

Looks like a really great project, thanks for your effort! If I understand it correctly, the module is currently only working when using System.js and not with Webpack. Do you have any plans to add compatibility with Webpack?

Need to Pass cookies with request for document src

We have an authentication cookie that our API requires before returning a PDF response.
When trying to use our url in the src attribute the pdf viewer fails because it gets a 401 status code from the url. How can we send the current cookies with the request for the pdf?

In an object data attribute the cookies are automatically sent.
In http.get there is a withCredentials attribute that can be sent as true.
But what is the correct way to send cookies using pdf viewer?

Default Rotation

Is there a way to predict the default rotation of a file? Is it the same orientation that the pdf is in on the system?

Some PDFs open up -90 rotated, and I have to set the rotation to 90, while others open normally and I have to set rotation back to 0. On the system, they both appear to be oriented properly.

Return pdf info

Make pdf information accessible from outside of component itself

Cannot find module 'pdfjs-dist'

Hi,
When I cloned the repo I encountered that issue. "Cannot find module 'pdfjs-dist'." in the module.
What more I need to do beside npm install, typings and gulp compiler?

image

image

Thanks,
Lukasz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.