Convert IMAGE TO PDF Software in C# Visual Studio 2010

6:09 AM


Hello Friends Today I Will Show You How to Create Image to PDF Converter Unique Design and Programming in C# Visual Studio 2010 only 5 Minutes

Convert IMAGE TO PDF Software in C# Visual Studio 2010




//Declare Variables and Object
  private string srcFile, destFile;
        bool success = false;
//Browse Select Image Button Codes
ofdSrcFile.ShowDialog() != DialogResult.OK)
            return;

            srcFile = ofdSrcFile.FileName;
            txt_sourcefile.Text = srcFile;

            txt_destinationfile.Text =
            Path.GetDirectoryName(srcFile) + "\\" +
            Path.GetFileNameWithoutExtension(srcFile) + ".pdf";
            destFile = txt_destinationfile.Text;  
       

//Browse Select Destination Folder Codes
            If (sfdDestFile.ShowDialog() != DialogResult.OK)
                return;
            destFile = sfdDestFile.FileName;
            txt_destinationfile.Text = destFile;
       
       



//Browse View File Button Codes

        errProv.Clear();

     if (rbSrc.Checked && txt_sourcefile.Text.Length == 0)
     {
errProv.SetError (txt_sourcefile, "Please point source file.");
                return;
     }
     else if (rbDest.Checked && txt_destinationfile.Text.Length == 0)
     {
errProv.SetError(txt_destinationfile, "Please point destination file.");
                return;
     }

    try
    {
    if (rbSrc.Checked)
    Process.Start(srcFile);
    else if (rbDest.Checked)
    Process.Start(destFile);
    }
    catch (Exception ex)
    {
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,     MessageBoxIcon.Error);
    }





   
   
//Browse Convert Files Codes

errProv.Clear();

if (txt_sourcefile.Text.Length == 0)
{
 errProv.SetError(txt_sourcefile, "Please point source file.");
 return;
 }
 else if (txt_destinationfile.Text.Length == 0)
 {
 errProv.SetError(txt_destinationfile, "Please point destination file.");
 return;
  }
  success = false;
 backgroundWorker2.RunWorkerAsync(new string[2] { srcFile, destFile });
 toolStripProgressBar1.Style = ProgressBarStyle.Marquee;





//Background2_DoWork Event
            try
            {
                string source = (e.Argument as string[])[0];
                string destinaton = (e.Argument as string[])[1];

                PdfDocument doc = new PdfDocument();
                doc.Pages.Add(new PdfPage());
                XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
                XImage img = XImage.FromFile(source);

                xgr.DrawImage(img, 0, 0);
                doc.Save(destinaton);
                doc.Close();
                success = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
       
       
//Background Worker 2_RunworkerCompleted Event
    toolStripProgressBar1.Style = ProgressBarStyle.Blocks;
            toolStripProgressBar1.Value = 0;

            if (success)
MessageBox.Show("The converion ended successfully.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);

       

      






Thanks For Visit My Blog if You want More Like that Programs then Subscribe My Youtube Channel.
contact me: (For Source Code And Designing Trick)
www.fb.com/AminSati786
www.plus.google.com/+aminsati
whatsapp number +918140005015
Comment me Your Mail ID I will Send You Source Code Thank You,

Next video we will upload soon.
Word to PDF Converter
Don’t Forget to Subscribe my Channel Now thank You





Share this

Related Posts

Previous
Next Post »