PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Need help to store my pdf file in variable http://forum.pdfsharp.com/viewtopic.php?f=2&t=4352 |
Page 1 of 1 |
Author: | noodlesincup [ Tue Jul 12, 2022 11:37 pm ] |
Post subject: | Need help to store my pdf file in variable |
Hello, so currently right now i am converting a text file to pdf file but i do not want to save it on my desktop i want to store the pdf file in a variable and use it somewhere else in my program. how would I do this? i am following this guide http://csharp.net-informations.com/file/txttopdf.htm The part i am questioning on string pdfFilename = "txttopdf.pdf"; pdf.Save(pdfFilename); thank you in advance |
Author: | TH-Soft [ Wed Jul 13, 2022 6:24 am ] |
Post subject: | Re: Need help to store my pdf file in variable |
Hi! You can invoke "pdf.Save()" with a stream. Use a MemoryStream and you will have the PDF file in it. Use GetBytes for the stream to get a byte array. See lines 21 through 26 in the first code block here: http://pdfsharp.net/wiki/Clock-sample.ashx |
Author: | noodlesincup [ Wed Jul 13, 2022 5:26 pm ] |
Post subject: | Re: Need help to store my pdf file in variable |
TH-Soft wrote: Hi! You can invoke "pdf.Save()" with a stream. Use a MemoryStream and you will have the PDF file in it. Use GetBytes for the stream to get a byte array. See lines 21 through 26 in the first code block here: http://pdfsharp.net/wiki/Clock-sample.ashx Thank you for the reply, I am trying to incorporate this into my code, just to clarify. If I just want to store the pdf file in a variable how would I proceed from here? this is my code right now MemoryStream stream = new MemoryStream(); document.Save(stream, false); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "output/pdf"; HttpContext.Current.Response.AddHeader("content-length", stream.Length.ToString()); HttpContext.Current.Response.BinaryWrite(stream.ToArray()); i am not sure how to store the pdf file to use in another method |
Author: | TH-Soft [ Thu Jul 14, 2022 7:44 am ] |
Post subject: | Re: Need help to store my pdf file in variable |
"stream.ToArray()" is your PDF file. "var pdf = stream.ToArray();" gives you a variable with the PDF file. You can pass that to another method. |
Author: | noodlesincup [ Thu Jul 14, 2022 3:26 pm ] |
Post subject: | Re: Need help to store my pdf file in variable |
TH-Soft wrote: "stream.ToArray()" is your PDF file. "var pdf = stream.ToArray();" gives you a variable with the PDF file. You can pass that to another method. Thank you again for your reply and your support I have solved that issue but now i have come across another issue How should my code look if im converting a byte[] to pdf and not txt file to pdf? many things are breaking in my code now thank you |
Author: | TH-Soft [ Fri Jul 15, 2022 8:17 am ] |
Post subject: | Re: Need help to store my pdf file in variable |
noodlesincup wrote: How should my code look if im converting a byte[] to pdf Use the byte[] to initialize a MemoryStream and then use PDFsharp to read the PdfDocument from the stream.
and not txt file to pdf? |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |