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
Describe the bug
Generating a PNG image using drawPageAsPNG has newline after data:image/png;base64,
To Reproduce
import{createMuPdf}from"mupdf-js"letpreview=[]// Initialize mupdf and call mupdfGeneratePNGasyncfunctionmupdfPreview(file){constmupdf=awaitcreateMuPdf()constfileArrayBuffer=awaitfile.arrayBuffer()constfileBuffer=newUint8Array(fileArrayBuffer)constpdf=mupdf.load(fileBuffer)constpages=mupdf.countPages(pdf)returnawaitmupdfGeneratePNG(mupdf,pdf,file,pages)}// Generate previews for pdf pages and return array of base64 PNGsasyncfunctionmupdfGeneratePNG(mupdf,pdf,file,pages){returnnewPromise((resolve,reject)=>{try{for(leti=1;i<pages;i++){constbase64Image=mupdf.drawPageAsPNG(pdf,i,10)// issue is herepreview.push(image)}resolve(preview)}catch(error){console.log(error)reject(error)}})}// Handle file input on change eventasyncfunctiononChange(event){constfiles=event.target.filesArray.from(files).forEach(async(file)=>{if(file.type==='application/pdf'){awaitmupdfPreview(file)}})}// Listen for input file changeconstinput=document.querySelector('[type="file"]')input.addEventListener('change',onChange)
Expected behavior drawPageAsPNG should return a single line base64 string like:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
Actual behavior
base64 string has newline after data:image/png;base64,
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
# in some environments the newline would be escaped and become `%0A`, resulting to:
data:image/png;base64,%0AiVBORw0KGgoAAAANSUhEUgAA...
Log output
Paste outputs from your terminal or browser logs to help explain your problem.
Screenshots
Desktop (please complete the following information):
OS: Linux and MacOS
OS Version: Ubuntu 22.04 LTS (GNU/Linux 5.15.0-1031-aws x86_64) and MacOS Catalina version 10.15.7
Browser (or Node) Chrome and Node
Browser (or Node) version: Chrome Version 110.0.5481.177 (Official Build) (x86_64) and Node v18.14.2
Architecture: x86_64
Smartphone (please complete the following information):
Not applicable
Additional context
Nothing
The text was updated successfully, but these errors were encountered:
base64Image.replace(/\n/,"")// Edit: I realized `drawPageAsPNG` also add the new line at certain points within the base64 string,// replacing all of those by using replaceAllbase64Image.replaceAll(/\n/g,"")
I made PR #58 which could fix this problem (there was bug with null byte at the end, but in some cases it could be converted to new line when marshalling from wasm to js)
Describe the bug
Generating a PNG image using
drawPageAsPNG
has newline afterdata:image/png;base64,
To Reproduce
Expected behavior
drawPageAsPNG
should return a single line base64 string like:Actual behavior
base64 string has newline after
data:image/png;base64,
Log output
Paste outputs from your terminal or browser logs to help explain your problem.
Screenshots
Desktop (please complete the following information):
Smartphone (please complete the following information):
Not applicable
Additional context
Nothing
The text was updated successfully, but these errors were encountered: