We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const mupdfjs = await import(/* @vite-ignore */ mupdfScript); const url = '/test.pdf' let response = await fetch(url) if (!response.ok) { console.error(`Cannot fetch document: ${response.statusText}`) return } let arrayBuffer = await response.arrayBuffer() let document = await mupdfjs.Document.openDocument( arrayBuffer, 'application/pdf' ); document.setLanguage('zh-Hans') let font_res = await fetch('/QingNiaoHuaGuangJianMeiHei-2.ttf') let font_buffer = await font_res.arrayBuffer() const font = await new mupdfjs.Font('青鸟华光简美黑', font_buffer) console.log(`Character encoding for '帅': ${font.encodeCharacter('帅')}`); // print 2337, 验证是否正确创建Font await document.addCJKFont(font, 'zh-Hans') const page = document.loadPage(0); let freeText = page.createAnnotation("FreeText") freeText.setContents("我是大帅哥") freeText.setLanguage('zh-Hans') // 如果使用默认值, 无法显示 '帅' 字 console.log(font.getName()) // print 青鸟华光简美黑 freeText.setDefaultAppearance(font.getName() , 16, [0,1,0]); console.log(freeText.getDefaultAppearance()) // print {font: 'Helv', size: 16, color: Array(3)} freeText.setRect([0,0,200,50]) freeText.update() page.update() const scale = (window.devicePixelRatio * 96) / 72 let pixmap = await page.toPixmap([scale, 0, 0, scale, 0, 0], mupdfjs.ColorSpace.DeviceRGB, false, true) let pngImage = await pixmap.asPNG() base64Image.value = URL.createObjectURL(new Blob([pngImage], { type: 'image/png' }));
页面上显示为 我想要的显示为
The text was updated successfully, but these errors were encountered:
Thank you for this report and the code sample - I don't think you are doing anything wrong. At the moment setDefaultAppearance can only use the in-built fonts as explained here: https://mupdfjs.readthedocs.io/en/latest/classes/PDFAnnotation.html#setDefaultAppearance
setDefaultAppearance
We will hopefully rectify this in the next release.
Sorry, something went wrong.
@ccxvii Another one to consider for the start of 2025! 🎆
No branches or pull requests
页面上显示为
我想要的显示为
The text was updated successfully, but these errors were encountered: