Adding for others to understand how to identify the correct format of the response received from the api. Specifically when you expect a pdf file from the api. If not done correctly you will se blank pdf pages.
https://developer.salesforce.com/forums/?id=9062I000000IUKAQA4
pasting my answer below incase link breaks
HttpResponse response = h.send(req);
Its important to understand why blob.valueof(response.getBody()) did not work and response.getbodyasblob() works.
When using this
blob.valueof(response.getBody())
response.getBody() is getting the body from the response in String format. the PDF file gets corrupted here itself. We the use blob.valueof() to convert the String to Blob for saving as contentversion.attachment.
response.getbodyasblob()
this methods retrieves the body from response directly as Blob. So no conversion takes place and pdf file is intact.
Why EncodingUtil.Base64Decode(response.getBody()) does not work here is because the response from the API is not a Base64 string. If you actually check the response you will find strange characters. Base64 only supports these characters:
Uppercase letters (indices 0-25): ABCDEFGHIJKLMNOPQRSTUVWXYZ
Lowercase letters (indices 26-51): abcdefghijklmnopqrstuvwxyz
Digits (indices 52-61): 0123456789
Special symbols (indices 62-63): +/
So trying to using EncodingUtil.Base64Decode(response.getBody()) with our response will give error of invalid characters. If you dig deeper and check the response received using System.debug(response.getBody()) you will realize that it is actually a PDF file format (the PDF specification for creating pdf files here (https://resources.infosecinstitute.com/topic/pdf-file-format-basic-structure/)). So we do not have to decode or uncompress the response in any way. We have to just retrieve the file as it is (as a blob) and save it to salesforce.
Example of (response.getBody()) you will see for these api responses which return PDF files.
%PDF-1.4
%����
2 0 obj
<</ColorSpace/DeviceRGB/Subtype/Image/Height 200/Filter/FlateDecode/Type/XObject/DecodeParms<</Columns 420/Colors 3/Predictor 15/BitsPerComponent 8>>/Width 420/Length 6827/BitsPerComponent 8>>stream
x�� |���gfw�MBr�r�p1Ax)X�QZ,�*Z����h��`�XĖ��Z���)��A���A�=f�'��
�3��N�e��}?���d���;��3��
�����Bv� ;����
@AuraEnabled
but you mention trying to view in a VF page. Are you trying to show the VF page in a Aura or LWC component?