Click here to Skip to main content
15,884,298 members
Home / Discussions / C#
   

C#

 
GeneralRe: Interface type or class type? Pin
N a v a n e e t h23-Sep-09 22:53
N a v a n e e t h23-Sep-09 22:53 
GeneralRe: Interface type or class type? Pin
shivapriyak24-Sep-09 0:36
shivapriyak24-Sep-09 0:36 
GeneralRe: Interface type or class type? Pin
PIEBALDconsult24-Sep-09 5:22
mvePIEBALDconsult24-Sep-09 5:22 
QuestionImport Excel to Database Pin
Member-495917623-Sep-09 18:53
Member-495917623-Sep-09 18:53 
AnswerRe: Import Excel to Database Pin
Richard MacCutchan23-Sep-09 22:39
mveRichard MacCutchan23-Sep-09 22:39 
Questionimage to PDF in C# 2008 Pin
vijaykumarp23-Sep-09 17:36
vijaykumarp23-Sep-09 17:36 
AnswerRe: image to PDF in C# 2008 Pin
Christian Graus23-Sep-09 18:16
protectorChristian Graus23-Sep-09 18:16 
GeneralRe: image to PDF in C# 2008 Pin
vijaykumarp23-Sep-09 21:39
vijaykumarp23-Sep-09 21:39 
Here is the code, im using PDFsharp lib for convert img to PDF.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Drawing;

namespace TreeListViewDragDrop
{
public partial class ImageToPDF : Form
{

private string srcFile, destFile;
bool success = false;

public ImageToPDF()
{
InitializeComponent();
}

private void btnSelectSrc_Click(object sender, EventArgs e)
{
if (ofdSrcFile.ShowDialog() != DialogResult.OK)
return;

srcFile = ofdSrcFile.FileName;
txbxSrcFile.Text = srcFile;

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

private void btnSelectDest_Click(object sender, EventArgs e)
{
if (sfdDestFile.ShowDialog() != DialogResult.OK)
return;

destFile = sfdDestFile.FileName;
txbxDestFile.Text = destFile;
}

private void btnConvert_Click(object sender, EventArgs e)
{
errProv.Clear();

if (txbxSrcFile.Text.Length == 0)
{
errProv.SetError(txbxSrcFile, "Please point source file.");
return;
}
else if (txbxDestFile.Text.Length == 0)
{
errProv.SetError(txbxDestFile, "Please point destination file.");
return;
}


success = false;
bw.RunWorkerAsync(new string[2] { srcFile, destFile });
toolStripProgressBar1.Style = ProgressBarStyle.Marquee;

ImageToPDF ImageToPDF = new ImageToPDF();
ImageToPDF.Close();

MainForm PDFForm = new MainForm();
PDFForm.Show();

this.Visible = false;


}

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
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);
}
}

private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
toolStripProgressBar1.Style = ProgressBarStyle.Blocks;
toolStripProgressBar1.Value = 0;

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

private void button1_Click(object sender, EventArgs e)
{
errProv.Clear();

if (rbSrc.Checked && txbxSrcFile.Text.Length == 0)
{
errProv.SetError(txbxSrcFile, "Please point source file.");
return;
}
else if (rbDest.Checked && txbxDestFile.Text.Length == 0)
{
errProv.SetError(txbxDestFile, "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);
}

}
}
}
QuestionConvertion image to PDF in C# 2008 Pin
vijaykumarp23-Sep-09 17:22
vijaykumarp23-Sep-09 17:22 
AnswerRe: Convertion image to PDF in C# 2008 Pin
Christian Graus23-Sep-09 18:17
protectorChristian Graus23-Sep-09 18:17 
QuestionProblems with getting UserDeletingRow event to work. Pin
gjx_junxian198923-Sep-09 17:06
gjx_junxian198923-Sep-09 17:06 
QuestionPOP3Temp folder ids not Found Pin
shobhit parasher23-Sep-09 13:05
shobhit parasher23-Sep-09 13:05 
QuestionHow to dynamically use C# 3.5 compiler Pin
pbalaga23-Sep-09 11:07
pbalaga23-Sep-09 11:07 
AnswerRe: How to dynamically use C# 3.5 compiler Pin
PIEBALDconsult23-Sep-09 12:07
mvePIEBALDconsult23-Sep-09 12:07 
GeneralRe: How to dynamically use C# 3.5 compiler Pin
pbalaga23-Sep-09 23:48
pbalaga23-Sep-09 23:48 
GeneralRe: How to dynamically use C# 3.5 compiler Pin
PIEBALDconsult24-Sep-09 4:35
mvePIEBALDconsult24-Sep-09 4:35 
GeneralRe: How to dynamically use C# 3.5 compiler Pin
pbalaga24-Sep-09 7:06
pbalaga24-Sep-09 7:06 
GeneralRe: How to dynamically use C# 3.5 compiler Pin
PIEBALDconsult24-Sep-09 7:08
mvePIEBALDconsult24-Sep-09 7:08 
QuestionHow to make a Custom Textbox Controll caputure the Parent's clickEvent [modified] Pin
Natural_Demon23-Sep-09 9:35
Natural_Demon23-Sep-09 9:35 
AnswerRe: How to make a Custom Textbox Controll caputure the Parent's clickEvent Pin
DaveyM6923-Sep-09 10:20
professionalDaveyM6923-Sep-09 10:20 
GeneralRe: How to make a Custom Textbox Controll caputure the Parent's clickEvent Pin
Natural_Demon23-Sep-09 10:47
Natural_Demon23-Sep-09 10:47 
GeneralRe: How to make a Custom Textbox Controll caputure the Parent's clickEvent Pin
Natural_Demon23-Sep-09 11:12
Natural_Demon23-Sep-09 11:12 
QuestionHow to display Multiple images in crystal report Pin
me_ariharan23-Sep-09 8:49
me_ariharan23-Sep-09 8:49 
AnswerRe: How to display Multiple images in crystal report Pin
Abhishek Sur23-Sep-09 10:35
professionalAbhishek Sur23-Sep-09 10:35 
QuestionError when opening demo projects Pin
Stieven23-Sep-09 8:26
Stieven23-Sep-09 8:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.