ng2-pdfjs-viewer
Advanced tools
Comparing version 3.4.8 to 3.4.9
{ | ||
"name": "ng2-pdfjs-viewer", | ||
"version": "3.4.8", | ||
"version": "3.4.9", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -13,5 +13,10 @@ # Angular 8 PDFJS viewer with Mozilla's ViewerJS (Supports Angular 2/4/5/6/7/8) | ||
## Demo | ||
https://ng2-pdfjs-viewer.azurewebsites.net/ | ||
You may download source code for the demo here : https://github.com/intbot/ng2-pdfjs-viewer/Demo | ||
## Features | ||
Some of below features are unique to this component, which is unavailable in native viewer or other implementations. | ||
✔️ **Open pdf in new window** 🌐 - Opens pdf viewer in new window. Alos, you may set all allowable external window options. | ||
✔️ **Open pdf in new window** 🌐 - Opens pdf viewer in new window. Also, you may set all allowable external window options. | ||
✔️ **Embed pdf** 🗎 - Embeds viewer and pdf inside your web page/component. | ||
@@ -158,3 +163,3 @@ ✔️ **Blob and byte arrays** 🔟 - Have pdf as a byte array? Still works. | ||
<ng2-pdfjs-viewer | ||
#pdfViewer | ||
#pdfViewerOnDemand | ||
[externalWindow]="true" | ||
@@ -166,2 +171,6 @@ [downloadFileName]="'mytestfile.pdf'" | ||
</div> | ||
<div> | ||
<div style="width: 800px; height: 400px"> | ||
<ng2-pdfjs-viewer #pdfViewerAutoLoad></ng2-pdfjs-viewer> | ||
</div> | ||
``` | ||
@@ -171,15 +180,34 @@ | ||
<!-- your.component.ts--> | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
... | ||
export class MyComponent implements OnInit { | ||
@ViewChild('pdfViewer') pdfViewer | ||
@ViewChild('pdfViewer') pdfViewerOnDemand; | ||
@ViewChild('pdfViewerAutoLoad') pdfViewerAutoLoad; | ||
... | ||
private downloadFile(url: string): any { | ||
return this.http.get(url, { responseType: ResponseContentType.Blob }).map( | ||
(res) => { | ||
return new Blob([res.blob()], { type: "application/pdf" }); | ||
}); | ||
constructor(private http: HttpClient) { | ||
let url = "api/document/getmypdf"; // Or your url | ||
this.downloadFile(url).subscribe( | ||
(res) => { | ||
this.pdfViewerAutoLoad.pdfSrc = res; // pdfSrc can be Blob or Uint8Array | ||
this.pdfViewerAutoLoad.refresh(); // Ask pdf viewer to load/refresh pdf | ||
} | ||
); | ||
} | ||
private downloadFile(url: string): any { | ||
return this.http.get(url, { responseType: 'blob' }) | ||
.pipe( | ||
map((result: any) => { | ||
return result; | ||
}) | ||
); | ||
} | ||
public openPdf() { | ||
let url = "url to fetch pdf as byte array"; | ||
let url = "url to fetch pdf as byte array"; // E.g. http://localhost:3000/api/GetMyPdf | ||
// url can be local url or remote http request to an api/pdf file. | ||
@@ -192,3 +220,2 @@ // E.g: let url = "assets/pdf-sample.pdf"; | ||
this.downloadFile(url).subscribe( | ||
(res) => { | ||
@@ -226,11 +253,2 @@ this.pdfViewer.pdfSrc = res; // pdfSrc can be Blob or Uint8Array | ||
var bytes = reportViewer.LocalReport.Render("application/pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings); | ||
// The below content-disposition is lost when we create Blob() object in client browser. Hence commented out | ||
//var cd = new System.Net.Mime.ContentDisposition | ||
//{ | ||
// FileName = "somepdf.pdf", | ||
// Inline = true | ||
//}; | ||
//Response.Headers.Add("Content-Disposition", cd.ToString()); | ||
return File(bytes, "application/pdf") | ||
@@ -253,2 +271,13 @@ } | ||
} | ||
OR | ||
[HttpGet] | ||
[Route("GetMyPdf")] | ||
public IActionResult GetMyPdf() | ||
{ | ||
var pdfPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/assets/pdfjs/web/gre_research_validity_data.pdf"); | ||
byte[] bytes = System.IO.File.ReadAllBytes(pdfPath); | ||
return File(bytes, "application/pdf"); | ||
} | ||
``` | ||
@@ -255,0 +284,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11933675
287