Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

C++
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 3: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[^]

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);
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900