如何获取"PDF"文件SoftLayer报价的二进制数据生成文件? [英] How to get "PDF" file from the binary data of SoftLayer's quote?

查看:59
本文介绍了如何获取"PDF"文件SoftLayer报价的二进制数据生成文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过SoftLayer API的"getPdf"方法获得二进制数据的.

I got the binary data by "getPdf" method of SoftLayer's API.

参考 BillingSoftLayer_Billing_Order_Quote :: getPdf | SoftLayer开发网络- http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Order_Quote/getPdf

Ref. BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer Development Network - http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Order_Quote/getPdf

然后我要根据二进制数据创建PDF文件. 你知道如何进行吗?

Then I wanna create the PDF file from the binary data. Do you know how to proceed it?

推荐答案

该方法返回以base 64编码的二进制数据,您需要做的是对二进制数据进行解码.

the method return a binary data encoded in base 64, what you need to do is decode the binary data.

请参阅有关编码和解码二进制数据的文章.

see this article about enconde and decode binary data.

https://code. tutsplus.com/tutorials/base64-encoding-and-decoding-using-python--cms-25588

Python客户端返回xmlrpc.client.Binary对象,因此您需要在此处使用该对象使用Python客户端和Python 3进行操作

the Python client returns a xmlrpc.client.Binary object so you need to work with that object here an example using the Python client and Python 3

#!/usr/bin/env python

import SoftLayer
import xmlrpc.client
import base64
import os

USERNAME = 'set me'
API_KEY = 'set me'

quoteId = 1560845

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)

accountClient = client['SoftLayer_Billing_Order_Quote']
binaryData = accountClient.getPdf(id=quoteId)
decodeBinary = binaryData.data
file = open('test.pdf','wb')
file.write(decodeBinary)

致谢

这篇关于如何获取"PDF"文件SoftLayer报价的二进制数据生成文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆