Note that there are some explanatory texts on larger screens.

plurals
  1. POC# .net Writing Content from POST Request as PDF Producing blank PDF
    text
    copied!<p>I'm handling POST requests that include a PDF and am trying to re-construct the file and save it to the server on my end. Here's the code I'm using for that, pdfString is from the request body:</p> <pre><code>string myPath = @"C:\mypath\mypdf.pdf"; byte[] byteArray = Encoding.UTF8.GetBytes(pdfString); MemoryStream stream = new MemoryStream(byteArray); using (var writeStream = File.OpenWrite(myPath)) { stream.CopyTo(writeStream); writeStream.Close(); } </code></pre> <p>This gives me a file that is the correct size and number of pages as compared to the original, but all of the pages are blank.</p> <p>In case this is useful, here is the beginning of the request body where some of the PDF's meta data looks to be stored:</p> <pre><code>Content-Disposition: form-data; name="file" %PDF-1.3 % %100230[584] 1 0 obj &lt;&lt; /Filter/Standard /R 2 /V 1 /O&lt;ad6a15e8126b8f8185e4db64f2a41b8bd94a79eed4f6fd1e6b17da57ea2d8ba9&gt; /U&lt;e1f8eabd02255525f1eb0c68575189d08e577035a6905adeb50d84e67779a066&gt; /P 4 &gt;&gt; endobj 2 0 obj &lt;&lt; /Producer(sZT\310]!\354w\244\214) /Author(zS[\315D\002\332\005\252\263\b$\375f]\334) /Title() /Subject(\007\004\017\233\0260\203g\205\260\016/\375`J\324x"8v) /Keywords() /CreationDate(t\014\017\233\007T\222\024\330\346Qr\2539\037\210) /ModDate(t\014\017\233\007T\222\024\330\346Qr\250=\033\214) /Creator(Gfy\355\026\005\332\005\236\257"7\371lK\230[o\bZ) &gt;&gt; endobj 3 0 obj &lt;&lt; /Type/XObject/Subtype/Image /Name/wpt1 /Width 640 /Height 480 /BitsPerComponent 8 /ColorSpace/DeviceRGB /Length 23713 /Filter [/FlateDecode/DCTDecode] &gt;&gt; </code></pre> <p>Nothing after that is plain-text. Until the PDF is closed.</p> <p>Is there some other way to read the request into memory that I should be using or something?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload