-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
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
the pdf.js cannot load the .cmap file in node.js #8881
Comments
I'm afraid that you may have misunderstood the purpose of that PR, since what it does is allow you to provide a custom factory for reading CMap files when using PDF.js in for example Node.js (such that you don't have to try and mock e.g. Lines 135 to 138 in 9b14f8e
The correct way to use this, is to in your code define e.g. a pdf.js/test/unit/test_utils.js Lines 47 to 76 in 9b14f8e
let loadingTask = pdfjsLib.getDocument({
data: pdfData,
CMapReaderFactory: NodeCMapReaderFactory,
});
loadingTask.promise.then((pdfDocument) => {
// Your code here...
}); Provided that you've also set |
Link to PDF file (or attach file here): https://github.com/WeiFei365/pdfjs-node-cmap/blob/master/test.pdf
Configuration:
Steps to reproduce the problem:
My terminal show: e2
After these two commands above, I got two different string content. I think the second one should be right, because I open pdf file with pdf.js in Chrome, the output string like this:
When I debug by Visual Studio Code, I find some error information while debug index.js. I attach the screeshot below: e1. For solving this, I found an issue #8064 among Issues. But as I debug, the program didn't check out the environment as Node.js correctly and the PDFJS.cMapUrl is null. I thought there is something wrong in the program.
In idnex-mine.js, you can check the codes L12 that I mock a XMLHttpRequest Class to get the string content I expected. But I'm not sure if my solution has any flaws.
What is the expected behavior? (add screenshot)
the string content is expected to be output:
'268新華人壽保險股份有限公司 2015 年年度報告第十四節附件合併財務報表附註(續)截至2015年12月31日止年度(除特別標註外,金額單位為人民幣百萬元)38 資產負債表日後事項(1) 利潤分配根據2016年3月29日董事會通過的2015年度利潤分配方案,本公司擬向全體股東派發現金股利人民幣873百萬元,按已發行股份計算每股人民幣0.28元(含稅)。上述利潤分配方案尚待股東大會批准。(2) 籌建新華卓越養老保險股份有限公司2015年4月23日,保監會批復同意本公司和本公司附屬公司資產管理公司共同發起籌建新華卓越養老保險股份有限公司,註冊資本人民幣5億元,註冊地北京市,截至本財務報表批准報出日,籌建工作仍在進行中。(3) 發行資本補充債券本公司於2016年3月4日召開的2016年度第一次臨時股東大會審議批准的《關於公司2016年資本補充債券募集方案的議案(修訂)》,同意本公司2016年發行總額不超過人民幣50億元或不超過人民幣50億元等值美元的資本補充債券。本公司2016年資本補充債券發行事宜尚待監管部門批准。39 合併財務報表批准本合併財務報表於2016年3月29日經本公司董事會審議通過並批准報出。'
What went wrong? (add screenshot)
the pdf.js program didn't check out the environment as Node.js correctly, So I use XMLHttpRequest to load file 'Adobe-CNS1-UCS2.bcmap'. But the XMLHttpRequest is the object in DOM.
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
Please download my source code: https://github.com/WeiFei365/pdfjs-node-cmap. Please separately run the two files: index.js and index-mine.js, then check the output in the terminal.
Or if you also installed the Visual Studio Code, then you can debug index.js directly and check the error information.
Thank you very much.
The text was updated successfully, but these errors were encountered: