I have one very important thing to learn with this question. Is it possible to save images in pdf into database, so that when sending to users via email users can download it in pdf? For example, if an administrator creates an e-certificate by uploading a certificate background in .png, .jpg or .jpeg; and the admin inputs the names of the recipients on each certificate using a TextBox, and the name will be displayed in a label control. Then the admin saves each certificate as the names are added. After admin is finished, the admin goes to a GridView where the names and emails of each recipient is displayed in the GridView. Admin selects recipients by clicking on the checkboxes beside the names and emails of the recipients, and sends the certificate to the recipients. Then when the recipients opens their emails and downloads the certificate in pdf format. I will have 3 major issues with this design because.
1. How to save the image certificate in pdf in the database
2. I don't know how to attach each certificate (saved as pdf), and link it to each user in the GridView and send
This is my code to convert image file into PDF but how to save this pdf into Database
string base64 = Request.Form[ImageDatahf.UniqueID].Split(',')[1];
byte[] imageBytes = Convert.FromBase64String(base64);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageBytes);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
document.Add(image);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=Image.pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
}
This is the area where to send the saved certificate(PDF file) is sent to each recipient
<asp:TextBox ID="SubjectTxt" runat="server" CssClass="form-control" Font-Size="9pt" />
<asp:TextBox ID="txtBody" runat="server" CssClass="form-control" Width="100%" Font-Size="10pt" TextMode="MultiLine" Style="overflow: hidden; resize: none;" oninput="Resize(this)" />
<script type="text/javascript">
function Resize(textbox) {
textbox.style.height = "";
textbox.style.height = Math.min(textbox.scrollHeight, 300) + "px";
}
</script>
<asp:Button ID="BtnSubmit" Text="Send Certitifate" CssClass="btn btn-primary" runat="server" OnClick="BtnSubmit_Click" />
<!--GridView where the Name and email of recipient displays -->
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="OnPageIndexChanging" GridLines="None" AllowPaging="true" HeaderStyle-ForeColor="#224f6d" HeaderStyle-Font-Size="11pt" RowStyle-Font-Size="10pt"
AutoGenerateColumns="false" PageSize="7" CssClass="table" Width="100%" HeaderStyle-HorizontalAlign="left" RowStyle-HorizontalAlign="Left">
<EmptyDataTemplate>
<div style="text-align: center; font-weight: 500; font-size: medium;">
<asp:Label ID="labelTemp" runat="server" Text="No User"></asp:Label>
</div>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="Name" HeaderText="Recipient Name" ReadOnly="true" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="email" HeaderText="Recipient Email" ReadOnly="true" HeaderStyle-Font-Bold="false" />
</Columns>
</asp:GridView>