Accueil > > > CONVERTISSEUR PDF
CONVERTISSEUR PDF
Information sur la source
Description
Ce code se sert de la librairie ItextSharp pour creer, des docuemnts PDF. Dans ce code, je creé des document PDF des images présente dans un répertoir. Apres vous pouvez faire tout ce que vous voulez !!! (Insertion des textes, modification de la police etc...)
Source
- using System;
- using System.Windows.Forms;
- using System.IO;
-
- using iTextSharp.text;
- using iTextSharp.text.pdf;
-
-
- namespace PDFConvertor
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
- private System.Windows.Forms.TextBox browseTxt;
- private System.Windows.Forms.Button browseBtn;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- private System.Windows.Forms.Button convertBtn;
- public string folderName = string.Empty;
-
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
-
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.convertBtn = new System.Windows.Forms.Button();
- this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
- this.browseTxt = new System.Windows.Forms.TextBox();
- this.browseBtn = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // convertBtn
- //
- this.convertBtn.Enabled = false;
- this.convertBtn.Location = new System.Drawing.Point(256, 40);
- this.convertBtn.Name = "convertBtn";
- this.convertBtn.Size = new System.Drawing.Size(80, 24);
- this.convertBtn.TabIndex = 0;
- this.convertBtn.Text = "Convert";
- this.convertBtn.Click += new System.EventHandler(this.convertBtn_Click);
- //
- // browseTxt
- //
- this.browseTxt.Location = new System.Drawing.Point(8, 8);
- this.browseTxt.Name = "browseTxt";
- this.browseTxt.Size = new System.Drawing.Size(264, 20);
- this.browseTxt.TabIndex = 1;
- this.browseTxt.Text = "";
- //
- // browseBtn
- //
- this.browseBtn.Location = new System.Drawing.Point(280, 8);
- this.browseBtn.Name = "browseBtn";
- this.browseBtn.Size = new System.Drawing.Size(56, 24);
- this.browseBtn.TabIndex = 2;
- this.browseBtn.Text = "Browse";
- this.browseBtn.Click += new System.EventHandler(this.browseBtn_Click);
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(344, 72);
- this.Controls.Add(this.browseBtn);
- this.Controls.Add(this.browseTxt);
- this.Controls.Add(this.convertBtn);
- this.Name = "Form1";
- this.Text = "PDF Convertor";
- this.ResumeLayout(false);
-
- }
- #endregion
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
-
- private void browseBtn_Click(object sender, System.EventArgs e)
- {
- if(this.folderBrowserDialog.ShowDialog()== DialogResult.OK){
- folderName = folderBrowserDialog.SelectedPath;
- browseTxt.Text = folderName;
- convertBtn.Enabled = true;
- }
- }
-
- private void convertBtn_Click(object sender, System.EventArgs e)
- {
- string filename = "image2pdf.pdf";
- Image imageFile = null;
- Document pdfDoc = new Document();
- PdfWriter.GetInstance(pdfDoc, new System.IO.FileStream(filename, System.IO.FileMode.Create));
- pdfDoc.AddTitle("PDF Convertor");
- pdfDoc.Open();
- try
- {
- foreach(string imgFile in Directory.GetFiles(folderName, "*.*"))
- {
- imageFile = Image.GetInstance(imgFile);
- imageFile.Alignment = Image.MIDDLE_ALIGN;
- imageFile.ScalePercent(80);
- pdfDoc.Add(imageFile);
- pdfDoc.NewPage();
- imageFile = null;
- }
- MessageBox.Show("Process terminated. ","PDF Convertor",MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch(Exception ex)
- {
- MessageBox.Show("Image File is not supported !! \n"+ex.ToString(),"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally{
- pdfDoc.Close();
- System.GC.Collect();
- }
- }
- }
- }
using System;
using System.Windows.Forms;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace PDFConvertor
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
private System.Windows.Forms.TextBox browseTxt;
private System.Windows.Forms.Button browseBtn;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button convertBtn;
public string folderName = string.Empty;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.convertBtn = new System.Windows.Forms.Button();
this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
this.browseTxt = new System.Windows.Forms.TextBox();
this.browseBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// convertBtn
//
this.convertBtn.Enabled = false;
this.convertBtn.Location = new System.Drawing.Point(256, 40);
this.convertBtn.Name = "convertBtn";
this.convertBtn.Size = new System.Drawing.Size(80, 24);
this.convertBtn.TabIndex = 0;
this.convertBtn.Text = "Convert";
this.convertBtn.Click += new System.EventHandler(this.convertBtn_Click);
//
// browseTxt
//
this.browseTxt.Location = new System.Drawing.Point(8, 8);
this.browseTxt.Name = "browseTxt";
this.browseTxt.Size = new System.Drawing.Size(264, 20);
this.browseTxt.TabIndex = 1;
this.browseTxt.Text = "";
//
// browseBtn
//
this.browseBtn.Location = new System.Drawing.Point(280, 8);
this.browseBtn.Name = "browseBtn";
this.browseBtn.Size = new System.Drawing.Size(56, 24);
this.browseBtn.TabIndex = 2;
this.browseBtn.Text = "Browse";
this.browseBtn.Click += new System.EventHandler(this.browseBtn_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(344, 72);
this.Controls.Add(this.browseBtn);
this.Controls.Add(this.browseTxt);
this.Controls.Add(this.convertBtn);
this.Name = "Form1";
this.Text = "PDF Convertor";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void browseBtn_Click(object sender, System.EventArgs e)
{
if(this.folderBrowserDialog.ShowDialog()== DialogResult.OK){
folderName = folderBrowserDialog.SelectedPath;
browseTxt.Text = folderName;
convertBtn.Enabled = true;
}
}
private void convertBtn_Click(object sender, System.EventArgs e)
{
string filename = "image2pdf.pdf";
Image imageFile = null;
Document pdfDoc = new Document();
PdfWriter.GetInstance(pdfDoc, new System.IO.FileStream(filename, System.IO.FileMode.Create));
pdfDoc.AddTitle("PDF Convertor");
pdfDoc.Open();
try
{
foreach(string imgFile in Directory.GetFiles(folderName, "*.*"))
{
imageFile = Image.GetInstance(imgFile);
imageFile.Alignment = Image.MIDDLE_ALIGN;
imageFile.ScalePercent(80);
pdfDoc.Add(imageFile);
pdfDoc.NewPage();
imageFile = null;
}
MessageBox.Show("Process terminated. ","PDF Convertor",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show("Image File is not supported !! \n"+ex.ToString(),"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally{
pdfDoc.Close();
System.GC.Collect();
}
}
}
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
PDF+c# [ par meth6278 ]
salut a tous je travail avec PDF et c#j'ai un document PDF contient une image ,j'aimerai lorsque je selectionne une partie de cette image ,mon program
Image dans une transformation XML->RTF ou XML->PDF [ par DeadEye0112 ]
Bonjour,J'ai un problème avec les images et la transformation XSLT.Lors de la création d'un fichier (RTF ou PDF) à l'aide d'un XSLT, je réussis à mett
Convertir un pdf en image [ par Tolliap ]
Bonjour,Je cherche à convertir un fichier PDF en fichier IMAGE (jpg de préférence), 1 image par page du PDF.Quelqu'un aurai une solution à m'apporter?
Afficher document office ou pdf ou image dans un Form C# [ par houba80 ]
Salut, je veux récupérer mes documents office PDF et image (jpg, bmp...) qui sont enregistrer dans une base SQLServer 2008 et les afficher dans un for
Extraction d'images et de pages - PDF [ par mbeditions ]
Bonjour à tous, Je développe actuellement un logiciel dont l'une des fonctionnalités est l'extraction des photos contenues dans un fichier PDF. Parti
Reconnaitre texte et image dans Richtextbox [ par shirtboy ]
Bonjour à tous, J'ai un petit problème avec ma richtextbox, et j'aurais besoin de votre aide, si vous voulez bien me l'accorder. Voilà, j'ai une sor
Générer un fichier PDF en C# [ par PolOw94 ]
Bonjour, Je suis débutant en programmation, j'utilise Visual Studio 2010 (C#) J'aimerais savoir comment peut on générer un fichier PDF en C# avec WP
|
Derniers Blogs
TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0 par odewit
Je viens de publier la version 3.0 de Perspective pour Silverlight, qui regroupe un portage sous Silverlight 5.0 des fonctionnalités de Perspective 2.0, le framework 3D de haut-niveau introduit récemment et de nouveaux exemples de code. En voici la li...
Cliquez pour lire la suite de l'article par odewit TECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVERTECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVER par ROMELARD Fabrice
Speaker : Nadia Ben El Kadi Configuration machine La session commence par la toute première question à se poser lors de la mise en place d'environnement SQL Server, la configuration des machines : Type de mac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SITECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SI par ROMELARD Fabrice
Speakers : Fabrice Barbin, Samuel Blanchard, Julien Lo Presti Titre Prometteur et attractif invitant à voir comment lier le composant ludique Kinect dans le cadre d'une structure IT classique, notamment au travers de la plat...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOURTECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOUR par ROMELARD Fabrice
KeyNotes du premier jour pour les développeurs. La session est principalement axée sur une des principales directions prise par Microsoft à travers tous ses nouveaux produits : Cloud privé ou public (Solution Azure) ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|