我已经提出要求查看xamarin froms中的pdf。但内容是一个字符串缓冲区,我不知道如何将其转换为PDF格式,以便我以后可以在我的应用程序中查看它。我可以通过两种方式查看pdf,本地和网址。
这是我收到请求后的内容:
%PDF-1.5 % 1 0 obj <>>> endobj 2 0 obj <> endobj 3 0 obj <> / ExtGState<> / ProcSet [/ PDF / Text / ImageB / ImageC / ImageI]>> / MediaBox [0 0 595.32 841.92] / Contents 4 0 R / Group<> / Tabs / S / StructParents 0>> endobj 4 0 obj <> 流 许 0F @ЛO`6qjS'JV);> 8 @ P / ,Q55 :khMl Rhp< O.np)wuRpR12 |ipDzcyKx> DLP } 71 endstream endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> endobj 9 0 obj < #4 线程完成:#8
这是我的代码:
public async void getPdfForProduct(String productId)
{
var baseUrl = "http://";
var pdfUrl = baseUrl + productId + "/sds";
try
{
var baseAddress = new Uri(pdfUrl);
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
validToken = System.Net.WebUtility.UrlEncode(validToken);
cookieContainer.Add(baseAddress, new Cookie("access_token", string.Format(validToken)));
var result = client.GetAsync(pdfUrl).Result;
result.EnsureSuccessStatusCode();
if (result.IsSuccessStatusCode)
{
var content = await result.Content.ReadAsStringAsync();
Debug.WriteLine(content);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(@" ERROR {0}", ex.Message);
}
}