Run time front and back Image to PDF Convert. For example button front click and back click image should be converted to show on pdf.
protected void DropFileName_SelectedIndexChanged(object sender, EventArgs e)
{
if (filePaths == null)
{
filePaths = Directory.GetFiles(BrowseUploadFile.FPaths, "*.*", SearchOption.AllDirectories);
}
if (filecount == 0)
{
filecount = System.IO.Directory.EnumerateFiles(BrowseUploadFile.FPaths).Count();
}
string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"900px\" height=\"600px\">";
embed += "If you are unable to view file, you can download from <a href = \"{0}\">here</a>";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
strJPPF = BrowseUploadFile.FPaths + DropFileName.Text + "";
string strJPGtoPDF = strJPPF;
if (strJPGtoPDF.EndsWith(".jpg") || strJPGtoPDF.EndsWith(".png"))
{
string fileName = strJPGtoPDF;
string stpath = strJPPF;
string phyiscalPath = stpath;
PdfDocument documents = new PdfDocument();
documents.Info.Title = DropFileName.Text;
PdfPage page = documents.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
DrawImage(gfx, stpath, 0, 0, (int)page.Width, (int)page.Height);
string strDemoFilePath = BrowseUploadFile.FPaths + strEmpCode + ".PDF";
if (File.Exists(strDemoFilePath))
{
File.Delete(strDemoFilePath);
}
if (documents.PageCount > 0) documents.Save(BrowseUploadFile.FPaths + strEmpCode + ".PDF");
string strFilePath = BrowseUploadFile.FPaths + strEmpCode + ".PDF";
ltEmbed.Text = string.Format(embed, ResolveUrl("~/pdfviewHandler.ashx?pdfFilePath=" + strFilePath));
}
else
{
string strFilePath = strJPGtoPDF;
ltEmbed.Text = string.Format(embed, ResolveUrl("~/pdfviewHandler.ashx?pdfFilePath=" + strFilePath));
}
}
void DrawImage(XGraphics gfx, string jpegsamplepath, int x, int y, int width, int height)
{
XImage image = XImage.FromFile(jpegsamplepath);
gfx.DrawImage(image, x, y, width, height);
}