英文:
How to open or download a raw pdf file coming from service
问题
I am having a challenge parsing a raw pdf file from frontend. The structure of the raw pdf file looks like this:
%PDF-1.3 %���� 1 0 obj << /Type /Catalog /Pages 2 0 R /PageMode /UseThumbs>>endobj2obj<</Type /Pages/Kids [ 4 0 R ]/Count 1
I tried using ng2-pdf-viewer
and pdfjs-dist
but it seems like it only takes the location of the file and not the raw file as in binary like the example above.
I've attempted this using Angular, I'd appreciate any form of help.
here's my code snippet.
<pdf-viewer [src]="pdfString" [show-all]="true"></pdf-viewer>
pdfString: string = '%PDF-1.7\n%�І�\n1 0 obj\n<</SubFilter/adbe.pkcs7.'
英文:
I am having a challenge parsing a raw pdf file from frontend. The structure of the raw pdf file looks like this
%PDF-1.3 %���� 1 0 obj << /Type /Catalog /Pages 2 0 R /PageMode /UseThumbs>>endobj2obj<</Type /Pages/Kids [ 4 0 R ]/Count 1
I tried using ng2-pdf-viewer
and pdfjs-dist
but it seems like it only takes the location of the file and not the raw file as in binary like the example above.
I've attempted this using Angular, I'd appreciate any form of help.
here's my code snippet.
<pdf-viewer [src]="pdfString" [show-all]="true"></pdf-viewer>
pdfString: string = '%PDF-1.7\n%�І�\n1 0 obj\n<</SubFilter/adbe.pkcs7.'
答案1
得分: 1
根据文档,如果您的PDF文件以BASE64编码字符串存储,可以首先使用 pdfSrc = atob(pdfString)
将其转换为二进制字符串。
另一种方法是,如果您的PDF以简单字符串存储,可以使用 pdfSrc = btoa(pdfString)
。
然后简单地使用 <pdf-viewer [src]="pdfSrc" [show-all]="true"></pdf-viewer>
。
英文:
According to the documentation, if your PDF file is stored as a BASE64-encoded string, you could use
pdfSrc = atob(pdfString)
first to convert it to a binary string.
In the other way, you can use pdfSrc = btoa(pdfString)
if your pdf is stored a s a simple string.
Then simply use <pdf-viewer [src]="pdfSrc" [show-all]="true"></pdf-viewer>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论