java呈现pdf时出错,PDFJS:PDF文本呈现时出错

Recently the PDF rendering get a messed up text layer where text gets duplicated with the grey colored overlay.

No idea about how to fix it as when i remove textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory() it works fine. but need this as if not is render as images which takes a lot of time for large documents

Im using pdfjsViewer.PDFPageView

my code as follows

getPdf() {

var pdfDocument;

if ( this._state !== 'inDOM' ) return false;

pdfjsLib.disableRange = true;

pdfjsLib.disableStream = true;

let self = this;

pdfDocument = pdfjsLib.getDocument(this.src);

pdfDocument.promise.then(function(pdf) {

self.set( 'pdfDocument', pdf );

self.set( 'maxNumPages', pdf.numPages );

self.set( 'prevBtnDisabled', true );

self.set( 'documentRendered', true );

self.setViewportWidth();

self.renderPdf();

});

return pdfDocument;

},

renderPdf() {

var pdf = this.pdfDocument,

maxNumPages,

pagePromise;

if ( !pdf ) return false;

maxNumPages = this.maxNumPages;

pagePromise = this.getAndRenderPage( pdf, 1 );

Array.apply( null, new Array( maxNumPages - 1 ) ).forEach( ( value, index ) => {

pagePromise = pagePromise.then( () => this.getAndRenderPage( pdf, index + 2 ) );

} );

},

getAndRenderPage( pdf, index ) {

return pdf.getPage( index ).then( page => this.renderPage( page, index ) );

},

renderPage( pdfPage, pageNum ) {

var parentWidth = this.$().parent().width(),

pageViewportScale = ( parentWidth >= this.get( 'breakpoints.mobile' ) ) ? 1.5 : 1.3,

viewport = pdfPage.getViewport( { scale: parentWidth / pdfPage.getViewport( { scale: pageViewportScale } ).width } ),

container = this.$().find( '.pdf_viewer--container' )[ 0 ],

pdfPageView;

pdfPageView = new pdfjsViewer.PDFPageView( {

container: container,

id: pageNum,

scale: viewport.scale,

defaultViewport: viewport,

textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory()

} );

var pages = this.get('pages');

// Associates the actual page with the view, and drawing it

pages.push( pdfPageView );

this.set( 'pages', pages );

this.set( 'scale', viewport.scale );z

pdfPageView.setPdfPage( pdfPage );

return pdfPageView.draw();

},

i have seen same kind of questioned asked and its for angular

Im importing his image as for the reference in here to give a more explanation about the issue

nXVJA.png

解决方案

in the new PDFjs, the CSS file needs to be added seperately from the node_modules folder. therefore i added this as

app.import( 'node_modules/pdfjs-dist/web/pdf_viewer.css' );

and you can add this as a html import as well.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值