'How to fix `URIError: Failed to decode param` pdf body received from backend?

So from the backend I am receiving a pdf binary like this:

"%PDF-1.3\r%����\r%PDF-Writer.NET dbAutoTrack Ltd.\r2 0 obj\r<<\r/Creator (Online)\r/CreationDate (D:20220411184728+02'00')\r/ModDate (D:20220411184728+02'00')\r>>\rendobj\r3 0 obj\r[/PDF /Text /ImageC]\rendobj\r7 0 obj\r<<\r/Type /XObject \r/Subtype /Image \r/Name /I0 \r/Length 76843 \r/Width 1545 \r/Height 2000 \r/Filter /DCTDecode \r/ColorSpace /DeviceRGB \r/Decode [0.0 1.0 0.0 1.0 0.0 1.0]\r/BitsPerComponent 8\r>>\rstream\r\n����\u0000\u0010JFIF\u0000\u0001\u0001\u0001\u0000`\u0000`\u0000\u0000��\u0000C\u0000\b\u0006\u0006\u0007\u0006\u0005\b\u0007\u0007\u0007\t\t\b\n\f\u0014\r\f\u000B\u000B\f\u0019\u0012\u0013\u000F\u0014\u001D\u001A\u001F\u001E\u001D\u001A\u001C\u001C $.' \",#\u001C\u001C(7),01444\u001F'9=82<.342��\u0000C\u0001\t\t\t\f\u000B\f\u0018\r\r\u00182!\u001C!22222222222222222222222222222222222222222222222222��\u0000\u0011\b\u0007�\u0006\t\u0003\u0001\"\u0000\u0002\u0011\u0001\u0003\u0011\u0001��\u0000\u001F\u0000\u0000\u0001\u0005\u0001\u0001\u0001

Then in my angular frontend app I do this:

 this.api
      .GetPrintedInvoice(invoiceID) 
      .then((res) => {
        console.log("RES",res)
        window.open(res);
      });
  }

EDIT:

This is how I parse it to the example response above:

parser.parseString(body, function(err, result) {
    request.get({
      url: result.feed.entry[0].content[0]['m:properties'][0]['d:Url'][0],
      headers: {
          'Authorization': auth.Item.token_type + " " + auth.Item.access_token,
          "Content-Type": "text/pdf"
      }
    }, async function(err, httpResponse, body) {
       console.log(body);
     
      console.log(typeof body)
 
      callback(null, body);
     
    });
  });

This returns me the error from the title. I want to be able to get this response and display it as PDF and eventually be able to download it but I am not sure how to do that.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source