Click here to Skip to main content
15,860,943 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Weird problem. Any suggestions or links would be appreciated.
I need to serve PDFs that are good for [90] days to links in user emails.
The 90 day restriction rules out simple S3 serving as does the fact that because of HIPPA considerations, everything is encrypted up the wazoo. The problem is compounded by a bunch of weird security and content restrictions on the company AWS network (PMI and PHI there so everything is locked down tighter than a 360 Kb floppy).
I want to make a page that the link directs to that will read the PDF as a Byte Stream from the S3. I can probably do that, but then how do I serve it? Thanks much, M
... I see that, as usual, trying to ask a weird question is difficult in this forum... If it wasn't a weird question, I wouldn't need to ask about it here.

What I have tried:

I did consider URL Redirect and URL Rewrite but in both cases, the URL would be in the header and it would be re-routing to an encrypted file.
Using AWS is conceptually weird. An S3 is out as is Cloudfront probably. I found something that serves images this way and am going to see what I can do with it but I'd like more resources if I can find them. c# - Serve file in byte[] as URL - Stack Overflow[^]
Just to make it more fun, my "Internet Server" is going to be a Lambda. That shouldn't be the difficulty but it means there is no way I can write it to a localish file and serve it. I've done that for an Intranet app where I write the PDF temporarily to the D: drive to avoid the ... same disk file serving whatever problem you hit..
Posted
Updated 9-Aug-20 13:59pm

I'd ask the question : How complex is this PDF ? can you build in 'on the fly' using iTextSharp or such ??

That would then do away with issues you have with the PDF being 'at rest' on a server somewhere and then having to find the 'at rest' file/representation.

If you CAN build the PDF on demand, then you can use some of the info from here c# - How to return PDF to browser in MVC? - Stack Overflow[^] to return the stream with the correct header, content disposition.

BTW, the 90 day limit could be handled by adding a date (created) + 90 days to the data source table, like a 'not valid after'
 
Share this answer
 
Comments
Michael Breeden 9-Aug-20 21:02pm    
Actually, as a side issue, these PDFs are not just complicated, they are non-standard and there was trouble converting them to PostScript using Ghost Script.
... I do suspect that the link you gave me though should be what I need, so how about that... I'll test it in the morning. I have a simplified PDF document and I should be able to convert it to a memory stream easily. If it serves it, then I can instead read the PDF from an S3 bucket as a Base64 string into a memory stream. Thanks. I can't wait to try this.
...Thinking about it, I made a widget that would convert from a JSON object to a PDF object. I know the same method can be used to read the PDF objects in a PDF file. I wonder if I could map a PDF file, but that is the equivalent of the PDF file itself so that doesn't seem an improvement. ... Of course, I could read that as JSON from a DynamoDB but I'd still be back where I started and need to generate a memory stream from the JSON to serve... Oh well. Cloud programming seems really weird.
The link Garth offered led to the solution. c# - Display ASP.NET generated pdf byte[] to web page without saving the file - Stack Overflow[^]
There were a few others offered for how to do it with an MVC web site but only that page led me to how to do it with a normal ASP.Net Razor page. Essentially the solution, for anyone that might find this, worked both as an object and as an embed. My C# code was something like:
byte[] bPDF = File.ReadAllBytes("filename.pdf");
string base64PDF = System.Convert.ToBase64String(bPDF, 0, bPDF.Length);
wrapped in string str = "<embed src="data:application/pdf;base64, " + ...getPDFAsBase64() + "" type="application/pdf" width="100%" height="800px" />";
My Razor code was [html][body] @Html.Raw(PDFModel.strReturnPDF()) [/body][/html].
It displayed the full height PDF, 51 pages.
Now I just need to read it from an S3 bucket and serve it from a Lambda encased "web site".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900