Click here to Skip to main content
14,364,290 members
Rate this:
Please Sign up or sign in to vote.
I create pdf dynamically. now I want to save that pdf into the database. I do not want to download it. i just want to save dynamically created pdf into the database. below I am attaching code for pdf created what I want to do next to save doc into the database?

What I have tried:

string attachment = "attachment; filename=" + "abc" + ".pdf";
                Response.ClearContent();
                Response.AddHeader("content-disposition", attachment);
                Response.ContentType = "application/pdf";
                StringWriter s_tw = new StringWriter();
                HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
                h_textw.AddStyleAttribute("font-size", "7pt");
                h_textw.AddStyleAttribute("color", "Black");
                Panel1.RenderControl(h_textw);//Name of the Panel
                Document doc = new Document();
                doc = new Document(PageSize.A4, 5, 5, 15, 5);
                FontFactory.GetFont("Times New Roman", 14);
                PdfWriter.GetInstance(doc, Response.OutputStream);
                doc.Open();
                StringReader s_tr = new StringReader(s_tw.ToString());
                HTMLWorker html_worker = new HTMLWorker(doc);
                html_worker.Parse(s_tr);
                doc.Close();
                Response.Write(doc);
Posted
Updated 4-Nov-19 4:23am
Comments
Richard Deeming 5-Nov-19 15:33pm
   
REPOST
This is the same question you posted last week:
Create a pdf in ASP.NET and save that file into databse[^]
Rate this:
Please Sign up or sign in to vote.

Solution 1

See the answer here: How I Store Pdf File In Mysql_Database And Retrive Using Vb.Net[^]
The example is in VB.NET but you can convert the code online here: Convert VB.NET to/from C# online - Roslyn Code Converter[^]

To convert to byte array:
byte[] bytes = System.IO.File.ReadAllBytes(docFileName);
   
v4
Comments
Member 14192879 3-Nov-19 16:43pm
   
actually, I know how to upload pdf with file uploader or with an open dialog box. but I want to save that pdf to the database which is dynamically created.
Member 14192879 3-Nov-19 16:46pm
   
i am not getting right code for changing below doc file into byte. i have code for saving pdf but i am still looking for converting dyanmic pdf into bytes.
doc.Open();
StringReader s_tr = new StringReader(s_tw.ToString());
HTMLWorker html_worker = new HTMLWorker(doc);
html_worker.Parse(s_tr);
doc.Close();

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100