You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello.
my all pdf file only have one page.
when I click one name, it will show the corresponding pdf file.
but sometimes the pdf show will roate 180,sometimes normal.
and they are calling the same function.
this is my code:
<div class="pdfViewer" [ngStyle]="{'height': pdfHeight+'px'}">
<div class="page" [ngStyle]="{'height': pageConfig.height+'px','width':pageConfig.width+'px'}">
<!-- pdf canvas -->
<div class="canvasWrapper">
<canvas #page width="{{pageConfig.width}}" height="{{pageConfig.height}}"></canvas>
</div>
<!-- pdf text -->
<div #textLayer class="textLayer" [ngStyle]="{'height': pageConfig.height+'px','width':pageConfig.width+'px'}"></div>
</div>
</div>
@ViewChild("textLayer") textLayer:ElementRef;
@ViewChild("page") page:ElementRef;
//draw pdf
drawPdf(data:any) {
//this.currentPdfShow = data;
let pdfjsDist = require("pdfjs-dist");
let PDFJS = pdfjsDist.PDFJS;
let loadingTask = PDFJS.getDocument('src/app/theme/components/spPdfShowNew/pdf/yb/wenshu/'+data+'.pdf');
let self = this;
loadingTask.promise.then((pdf) => {
//pdf always have one page 永远都只是一页
pdf.getPage(1).then((page) => {
let pdfScale = (self.pafWidth * 0.8 - 80) / page.getViewport(1).width; //根据传过来的宽度来获取放大的倍数
let viewport = page.getViewport(pdfScale,0);
let canvas = self.page.nativeElement;
let context = canvas.getContext('2d');
context.clearRect(0,0,viewport.width,viewport.height);
let renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
self.pageConfig['width'] = viewport.width;
self.pageConfig['height'] = viewport.height;
self.pdfHeight = viewport.height + 20;
page.getTextContent({
normalizeWhitespace: true,
}).then((textContent) => {
let textDivs = [];
let textLayerFrag = document.createDocumentFragment();
let textLayerRenderTask = pdfjsDist.renderTextLayer({
textContent: textContent,
container: textLayerFrag,
viewport: viewport,
textDivs: textDivs,
timeout: self.TEXT_LAYER_RENDER_DELAY,
enhanceTextSelection: false,
});
textLayerRenderTask.promise.then(function () {
if (textLayerFrag) {
self.textLayer.nativeElement.innerHTML = '';
self.textLayer.nativeElement.appendChild(textLayerFrag);
}
}.bind(this), function (reason) {});
})
});
}, function (reason) {console.error(reason);});
}
The text was updated successfully, but these errors were encountered:
Configuration:
angular:4.0.2
pdfjs-dist:1.8.213
Hello.
my all pdf file only have one page.
when I click one name, it will show the corresponding pdf file.
but sometimes the pdf show will roate 180,sometimes normal.
and they are calling the same function.
this is my code:
The text was updated successfully, but these errors were encountered: