简体   繁体   English

如何从PDF转换为base64

[英]How to convert from PDF to base64

I am making a request get and is returning a pdf. 我正在请求获取并返回pdf。 I have received the pdf encoded in base64 and I have not had any problems showing it. 我已经收到以base64编码的pdf文件,并且显示它没有任何问题。 In this case I have a problem because what the get returns is the following: 在这种情况下,我有一个问题,因为get返回的内容如下:

%PDF-1.4 %äüöß 2 0 obj <> stream x��YKo���W��{YŇ$�!��v�m99�&?,2 f/���E�Aٞ��` ��b����#%�3t�}��9�� �~���<��?Ý¿>u_:�9v=��C�=��O����h�������?����O�dϹ���ן�^��dػ��w/?u?ܡ���^L=^N1]��zqa ��E�OS��O�� 2g��xq�2�4%�mu�*�n��q��˟�_>�!�� %PDF-1.4%äüöÃ2 0 obj <> streamx��YKo���W��{YŇ$�!��v�m99�&?, 2 f /���E�Aٞ�½¿½½ï¿½ï¿½bï¿½ï¿½ï¿½ï¿ ¿½〜���<��ݿ?> U_:�9v=��C�=��O����hï¿½ï¿ ½ï¿½ï¿½ï¿½ï¿½ï¿½?����O�dϹ���ן�^��dػ��w/?ü?ü ¡¡¿½ï¿½ï¿½^ L = ^ N1]��zqa��E�OS��O��2g��xqï¿ ï¿½n��q��˟�_>�!��

As I have seen what I am getting is a pdf in its pure format, it can be seen in: http://www.printmyfolders.com/understanding-pdf . 正如我所看到的,我得到的是纯格式的pdf,可以在以下网址中看到它: http : //www.printmyfolders.com/understanding-pdf

So how can this format be converted to base64 or in what form could the pdf be displayed? 那么如何将这种格式转换为base64或以什么形式显示pdf?

what do you mean by displaying it? 显示它是什么意思? im assuming since you've tagged this with javascript, that you want it to be downloadable from the browser? 即时通讯假设,因为您已经用javascript标记了它,您希望它可以从浏览器下载?

Note that when you download a PDF, browsers in general will open it for you in a new tab/window, which makes it seem like it's being "displayed", when it's actually just downloading first then displaying it for you. 请注意,当您下载PDF时,通常浏览器会在新的标签页/窗口中为您打开它,这看起来像是在“显示”,实际上是先下载然后为您显示。

To allow the PDf to be downloaded, you'll need your backend server to provide a file stream so the browser will know to download it (ie pop open the download file dialog) 要允许下载PDf,您需要后端服务器提供文件流,以便浏览器知道要下载它(即,弹出打开“下载文件”对话框)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM