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?
Impossible d'afficher une image [ par arb ]
BonsoirJe suis en train de reprendre une appli en C#, et je voudrais mettre une image. J'ai donc ajouté une pictureBox et choisi un logo.jpg comme ima
Image cliquable dans un ListView [ par cybers7119 ]
Salut à tous,Je doit manipuler un ListView qui, pour l'instant, n'a qu'une seule colonne (avec des "string" dedans).J'aimerais pouvoir sélectionner un
[C#]treeview node image [ par medgha ]
bonjour tout le monde,je dévelope en C# sous visual studio 2005 , j'utilise dans mon application un treeview que je charge à partir d'une base de donn
[C#]TreeView ne pas associer à tt les nodes une image [ par medgha ]
bonjour tt le monde,peut etre que ma question vous paraitra bête, mais j'ai cherché dans le forum et j'ai pas trouvé la reponse,mon problème est le su
background image animée [ par zennoub ]
salut, j'aimerais savoir si c'ets possible de mettre dans mon form en backgroudimage une .gif, càd que je veux qu'en arriere plan il y ait une image a
[C#] progressBar et chargement de form en même temps [ par medgha ]
bonjour tout le monde,j'ai fait qlq recherches avant de poster, je développe une application en C# sous visual studio 2005et j'utilise un treview que
Exception GDI+ lors d'un passage d'une image dans un byte[] [ par nikochump ]
Bonjour à tous,J'ai un pti problème avec une partie d'un code et j'aimerais avoir votre avis sur la question.J'essaye de mettre dans un byte[] une ima
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|