Skip to content

Open from URL? #370

Answered by EliotJones
mattsmith321 asked this question in Q&A
Sep 20, 2021 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

You'd want to download the file before passing to the library, you can do this using HttpClient on NET 4.5+ or WebClient for earlier versions. You might be able to pass the content stream directly to PdfPig but I don't believe the stream supports seeking so you should download the bytes first, e.g. https://stackoverflow.com/a/54475013

var client = new HttpClient();
var response = await client.GetAsync("https://my-url.com/pdf");
if (!response.IsSuccessStatusCode) { /* handle the error */ }
var bytes = await response.Content.ReadAsBytesAsync();
using var pdf = PdfDocument.Open(bytes);

I haven't checked this in the IDE so some of the methods may be named differently.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mattsmith321
Comment options

@EliotJones
Comment options

@mattsmith321
Comment options

Answer selected by mattsmith321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants