如何打开或下载来自服务的原始PDF文件。

huangapple go评论76阅读模式
英文:

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>

huangapple
  • 本文由 发表于 2023年6月26日 20:44:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定