# Save PDF to disc from blob

**URL:** <https://forum.robotframework.org/t/save-pdf-to-disc-from-blob/4882>\
**Category:** Browser\
**Created:** [31 October 2022 08:16 UTC](https://forum.robotframework.org/t/save-pdf-to-disc-from-blob/4882 "2022-10-31T08:16:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomaspekarovic](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/tomaspekarovic/32/1368_2.png) [@tomaspekarovic](https://forum.robotframework.org/u/tomaspekarovic)\
**Post date:** [31 October 2022 08:16 UTC](https://forum.robotframework.org/t/save-pdf-to-disc-from-blob/4882/1 "2022-10-31T08:16:31Z")

</div>

Hi all, i have code as this:

```python
    @keyword
    def download_pdf_and_compare_screenshosts(self):
        promise = self.browser.promise_to(
            "Wait For Response",
            "response => response.url().includes('api/projections/outputFile') && response.status() === 200",
            "timeout=20 s")
        self.builtin.sleep(2)
        self.browser.click("xpath=//button[@class='mat-focus-indicator pl-0 mat-button mat-button-base mat-primary ng-star-inserted']")
        res = self.browser.wait_for(promise)
        self.builtin.log(res["body"])
        with open("test.pdf", "wb") as fp:
            fp.write(res["body"])

```

What this do, is it just catch the response from api call, that contains in body pdf.

Problem is, that I can’t save it. If I save it as this, PDF is blank.  
If I try to do `bytes(res["body"], encoding="utf-8")` it is the same, blank pdf

If I try to do `b64decode(res["body"], validate=True)` I got error message about non-ascii character.

I’m kind a stuck here… … Any ideas how to resolve this problem?

part of the pdf:

```python
%PDF-1.3
%����
2 0 obj
<</Subtype/Type1/Type/Font/BaseFont/Helvetica/Encoding/WinAnsiEncoding>>
endobj
1 0 obj
<</Subtype/Form/Filter/FlateDecode/Type/XObject/Matrix [1 0 0 1 0 0]/FormType 1/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 2 0 R>>>>/BBox[0 0 112.11 42.07]/Length 218>>stream
x���;N1Ds��!$M�M�����D��(o�J�do�~]vkV|�Ϥ�T�g���)$bS�M����U�G
��<ª�B�9N�E�<d�����P�$���FB!$��X'F��h%�J�CI��'m�.��>P\	��Uø).�l:�9cvi��L�2
�z�4�2Hz��������1Ư+������좖ݥM��e}�'U�kY�����V��ܗ�
endstream

```

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [7 November 2022 02:15 UTC](https://forum.robotframework.org/t/save-pdf-to-disc-from-blob/4882/2 "2022-11-07T02:15:54Z")

</div>

Hi Tomas,

- I’m no expert with this python module, but what do you get if you log the `res ` variable does it contain a key with the filenpath (`res["saveAs"]`)? you might find the file already was created and you simply need to get it’s filename so you can copy/move it or do whatever else you want with it?

- Perhaps I’m missing something? why not just use the standard browser keywords as shown in the example in the documentation for [Promise To Wait For Download](https://marketsquare.github.io/robotframework-browser/Browser.html?tag=BrowserControl#Promise%20To%20Wait%20For%20Download)?  
If you just need to control the path where the files are downloaded [New Browser](https://marketsquare.github.io/robotframework-browser/Browser.html?tag=BrowserControl#New%20Browser) has a `downloadsPath ` option for controlling that.  
Once the file is downloaded to disk by the browser you’ll have the file path (`${file_obj}[saveAs]` from the example) and with that you can do what every you need i.e. open it and read the content or pass to to a command line compare tool.

Dave.
