日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

PDF.JS教程 - A general-purpose, web standards-based platform for parsing and rendering PDFs.

發布時間:2024/3/24 javascript 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PDF.JS教程 - A general-purpose, web standards-based platform for parsing and rendering PDFs. 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

官方Example:

Hello World Walkthrough

Full source

PDF.js heavily relies on the use of?Promises. If promises are new to you, it’s recommended you become familiar with them before continuing?on.

This tutorial shows how?PDF.js can be used as a library in a web browser.?examples/?provides more examples, including usage in Node.js (at?examples/node/).

Document

The object structure of?PDF.js loosely follows the structure of an actual?PDF. At the top level there is a document object. From the document, more information and individual pages can be fetched. To get the?document:

pdfjsLib.getDocument('helloworld.pdf')

Remember though that?PDF.js uses promises, so the above will return a promise that is resolved with the document?object.

pdfjsLib.getDocument('helloworld.pdf').then(function(pdf) {// you can now use *pdf* here });

Page

Now that we have the document, we can get a page. Again, this uses?promises.

pdf.getPage(1).then(function(page) {// you can now use *page* here });

Rendering the Page

Each?PDF?page has its own viewport which defines the size in pixels(72DPI) and initial rotation. By default the viewport is scaled to the original size of the?PDF, but this can be changed by modifying the viewport. When the viewport is created, an initial transformation matrix will also be created that takes into account the desired scale, rotation, and it transforms the coordinate system (the 0,0 point in?PDF?documents the bottom-left whereas canvas 0,0 is?top-left).

var scale = 1.5; var viewport = page.getViewport(scale);var canvas = document.getElementById('the-canvas'); var context = canvas.getContext('2d'); canvas.height = viewport.height; canvas.width = viewport.width;var renderContext = {canvasContext: context,viewport: viewport }; page.render(renderContext);

Alternatively, if you want the canvas to render to a certain pixel size you could do the?following:

var desiredWidth = 100; var viewport = page.getViewport(1); var scale = desiredWidth / viewport.width; var scaledViewport = page.getViewport(scale);

Interactive examples

Hello World with document load error?handling

The example demonstrates how promises can be used to handle errors during loading. It also demonstrates how to wait until page loaded and?rendered.

Hello World using base64 encoded?PDF

The?PDF.js can accept any decoded base64 data as an?array.

Previous/Next example

The same canvas cannot be used to perform to draw two pages at the same time – the example demonstrates how to wait on previous operation to be?complete.

?

?

CSDN博主Example:

https://blog.csdn.net/m0_38021128/article/details/70868407

總結

以上是生活随笔為你收集整理的PDF.JS教程 - A general-purpose, web standards-based platform for parsing and rendering PDFs.的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。