<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Convert pdf to base64 in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaa-p/13622909#M4820158</link>
    <description>&lt;P&gt;Hi Maicon,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing same issue. Please let me know if you found any solution?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 17:49:41 GMT</pubDate>
    <dc:creator>namratharaj</dc:creator>
    <dc:date>2024-02-28T17:49:41Z</dc:date>
    <item>
      <title>Convert pdf to base64</title>
      <link>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaq-p/718358</link>
      <description>&lt;P&gt;Hello all, &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I am working on integration between Portal -&amp;gt; SAP API Management -&amp;gt; SAP Gateway and for one specific service, I need to retrieve the PDF file from Gateway. This pdf file needs to be download from portal side. &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;The service in Gateway is returning a pdf file(see below the response.content) and I need to convert it to base64 before send the response to Portal in json format. &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I am using a python script to convert the response.content to base64, which I found being used in some other SAP policies, but the conversion is not working fine. &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;After decoded in portal, the pdf does not open properly. I found some differences in the content of base64 when I compare the result of this script, with the result from a REST client which converts automatically to base64. &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Does anybody know how to resolve it? Or is there any other way to convert it using other scripts or policies? &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Any suggestion is welcome.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Python script: &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;import base64&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;encodedfile = base64.b64encode(flow.getVariable("response.content"));" &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Example of Response.Content: &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;"%PDF-1.4 %ï¿½ï¿½ï¿½ï¿½ 9 0 obj &amp;lt;&amp;lt; /Type /XObject /Subtype /Image /Name /I1 /Width 613 /Height 78 /BitsPerComponent 8 /ColorSpace /DeviceRGB /Length 5471 /Filter [ /FlateDecode ] &amp;gt;&amp;gt; stream xï¿½ï¿½kï¿½ï¿½ �ï¿½Ï�Ü�{ï¿½ï¿½�Gï¿½cï¿½ï¿½�$�ï¿½ï¿½ã¿�Vï¿½$/$\Bxï¿½ï¿½Ñ£Gï¿½�=zï¿½ï¿½Ñ£Gï¿½Ô´�ï¿½yï¿½ï¿½�ï¿½[ï¿½ï¿½ï¿½pï¿½ï¿½ï¿½ï¿½5Ï¯yzMï¿½&amp;lt;ï¿½Û��ï¿½gï¿½ï¿½^�ï¿½$ï¿½ï¿½ï¿½&amp;gt;ï¿½ï¿½ï¿½ï¿½ï¿½`ï¿½ï¿½ï¿½@ï¿½ï¿½ï¿½!ï¿½ï¿½ï¿½ï¿½ï¿½ß¿ã�§)Yrï¿½g}�ï¿½^ï¿½[ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ï¯ï¿½ï¿½k�ï¿½&amp;lt;ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½m+ï¿½iï¿½ï¿½ï¿½Oï¿½ï¿½x8-ï¿½,ï¿½ï¿½Ú­......." &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;The final response to Portal will be like this: &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;{ "mime-type": "application/PDF", "file": "JVBERi0xLjQNCi/9///9DQoNCjkgMCBvYmoNCjw8DQovVHlw..." } &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Many thanks in advance, Maicon.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 11:02:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaq-p/718358</guid>
      <dc:creator>maiconsbr</dc:creator>
      <dc:date>2018-09-17T11:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert pdf to base64</title>
      <link>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaa-p/13622909#M4820158</link>
      <description>&lt;P&gt;Hi Maicon,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing same issue. Please let me know if you found any solution?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 17:49:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaa-p/13622909#M4820158</guid>
      <dc:creator>namratharaj</dc:creator>
      <dc:date>2024-02-28T17:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert pdf to base64</title>
      <link>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaa-p/13623360#M4820203</link>
      <description>Hi, unfortunately we did not solve it from APIM side. After some discussion we agreed that sender applicatton should handle the pdf. So, this way we only transferred the pdf from Gateway to Portal without any transformation.</description>
      <pubDate>Thu, 29 Feb 2024 07:48:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/convert-pdf-to-base64/qaa-p/13623360#M4820203</guid>
      <dc:creator>maiconsbr</dc:creator>
      <dc:date>2024-02-29T07:48:28Z</dc:date>
    </item>
  </channel>
</rss>

