-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does anyone know how to handle PDF downloads/uploads? #456
Comments
Hi nhorton79. I haven't used the Xero API. But most likely the response body will just be the binary contents of the PDF file. It shouldn't need any parsing. You basically just need to write response.Body to a file, treating response,Body as a VBA Byte array. Here's some code I wrote a while ago, for downloading a file from Google Drive API:
Note that I've set the ResponseFormat to WebFormat.PlainText, which just stops VBA-Web from parsing the response. It doesn't matter whether the file contents are actually text or binary. FYI "ExecuteRequest" is my own wrapper for WebClient.Execute Try something like this. If the resulting file is not a valid PDF file, then take a closer look at it (e.g. with a hex editor) to see what you've got. |
P.S. Taking a fresh look at my code, I noticed a couple of things...
|
Hi Richard, I originally tried setting this a WebFormat.PlainText however, the Xero API didn't like this as it wouldn't accept an Accept header of "text/plain", so I may have to register a custom converter/parser that just passes the response body unaltered. One thing I can see that I don't have in the current Webhelpers or VBA-Web is "WriteBinaryFile". |
Instead of writing your own custom format, perhaps you could use request.SetHeader to override the the Accept header that VBA-Web sets. I've never tried that though. Here's my WriteBinaryFile sub...
|
Hi Richard, I tried using PlainText and then using request.SetHeader = "Accept", "application/pdf", however this didn't work. So I went with:
This download the invoice PDF file to the location specified. Regarding the ConvertToPDF and ParsePDF functions, all I did was copy what Tim had suggested in #61 Thank you for your assistance. I'll close this off shortly. |
If anyone is still interested, I have managed to get pdfs uploading to Sharepoint via the REST API and now the Graph API using an ADODB stream |
I would always be interested in checking something like that out TK-99. Do you want to open this as another "issue" and include the issue number here for those who follow? |
I'm using VBA-Web to access the Xero API and the API reference states I can download an invoice PDF by specifying "application/pdf" in the Accept header.
There doesn't appear to be anything as a standard WebFormat, so would need to be Custom.
I imagine that I would set the values like:
I imagine that this is correct?
However, I suppose my real question is how to handle the downloading of the file. How to code the two methods to parse and convert the PDF file.
Has anyone done into this before?
The text was updated successfully, but these errors were encountered: