PDFSharp使用记录: 从网络获取文档数据

public async Task<PdfDocument> GetHttpPdfAsync()
{
    // PDF URI
    string PdfUri = "http://www.pdf995.com/samples/pdf.pdf";

    // Create HTTP client and get stream from the URI
    var httpClient = new HttpClient();
    Stream stream = await httpClient.GetStreamAsync(PdfUri);

    // Create memory stream and copy stream data to memory stream
    using MemoryStream memoryStream = new MemoryStream();
    stream.CopyTo(memoryStream);
    memoryStream.Seek(0, SeekOrigin.Begin);

    // Create PDF document
    PdfDocument document = PdfReader.Open(memoryStream, PdfDocumentOpenMode.Modify);

    // Check document version and page count
    if (document.Version < 14)
    {
        // Only documents with version 14 or higher can ensure 
        // that transparent background images are rendered correctly
        document.Version = 14;
    }
    if (document.PageCount == 0)
    {
        document.AddPage();
    }

    // Log
    await Console.Out.WriteLineAsync("Get PDF document successfully!");
    return document;
}