RECHERCHER :
COMMUNAUTE MP
Identifiez vous ...
Devenir Membre
J'ai oublié mon MDP
DOMAINE MP
Bavardages
Langages Généraux
Langages Web
Langages DotNet
Autres langages
Dev. Jeux Video
Sécurité
Sys. Exploitation
Graphismes
Logiciels
Réseaux
Bases de données
Méthodologies
Emplois High-tech
Aide juridique
Articles juridiques
FORUM
Index des forums
Ajouter un sujet
Rechercher sujet
Contact Responsable
Devenir modérateur
CHAT MP IRC
Votre pseudo ...
Srv: irc.moteurprog.com
Chan: #MoteurProg
PARTICIPER
Plus de 3500 emplois.
Rechercher un job
Déposez votre CV
Emplois High-tech

Visiteur MP

 Manipulation d'un pdf en c#

Forum : CSHARP (C#)
Sous Catégorie : Aucune
Type du sujet : Sujet Normal
FAQ : FAQ CSHARP (C#)

SUIVI DES SUJETS PAR MAIL

SUIVI PAR MAIL INACTIF

RESOLUTION DU SUJET SUJET RESOLU
BLOQUAGE DU SUJET SUJET ACTIF
APPARTENANCE A LA FAQ N'APPARTIENT PAS A LA FAQ


PAGES : [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [>>]

POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

FORUM CSHARP (C#)

PREMIERE PAGE

PAGE PRECEDENTE

Page précedente

Page suivante

PAGE SUIVANTE

DERNIERE PAGE
Nej
Membre actif
Inscrit : 28/01/2008
Messages : 107
Message
#149785
Posté le 27/02/08 à 09:45
Bonne vacance Pistache!

Sinon si quelqu'un passe par là!

après avoir appelé la fonction monConv.FindOut();

je ne sais comment utiliser les méthodes taskend et taskstart!

je pensait n'utiliser que taskend pour detecter la fin du traitement le problème est
que je ne sais comment l'utiliser en vérité!

j'essayes de l'utiliser de la façon suivante:

monConv.FindOut();

monConv.TaskEnd += new ConvertPDFImagestoJPG.TaskEndEventHandler(monConv_TaskEnd);


}

static void monConv_TaskEnd()
{
throw new Exception("The method or operation is not implemented.");
}

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Publicité
Inscrit : X
Messages : X
Message
#Aucun

HAUT DE PAGE

  

Nej
Membre actif
Inscrit : 28/01/2008
Messages : 107
Message
#149786
Posté le 27/02/08 à 09:57
Bon bah voilou j'ai réussi à l'utiliser:


monConv.FindOutImages(nompdf, chemincreation + nom + "\\Images_zoom\\n", repertoireApplication + "\\xpdf\\"); monConv.TaskEnd += new ConvertPDFImagestoJPG.TaskEndEventHandler(monConv_TaskEnd); while (!convFaite) { } convertPpmToJpeg(); } static void monConv_TaskEnd() { //throw new Exception("The method or operation is not implemented."); convFaite = true; } private static void convertPpmToJpeg() { monAttente.Hide(); maFormCatalogue.Enabled = true; direction_sommaire(); }



plus qu'à réussir ma conversion ppmtojpeg et hop "Résolu"!

^^ (Nej est content)

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Nej
Membre actif
Inscrit : 28/01/2008
Messages : 107
Message
#149789
Posté le 27/02/08 à 11:31
Allez hop résolu!

Un grand merci à l'ami Pistache! ^^

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Czayfaboo
Superviseur :
- Langages Dot.
Modérateur :
- CSharp (C#)
Chef de projet(s) :
- ID3.NET Library
- MoteurProg Work.

Avatar de Czayfaboo
Inscrit : 05/01/2005
Messages : 3130
Message
#149815
Posté le 27/02/08 à 19:07
Arf, résolu...

Bon tant pis, voici le boulot que j'avais fait dessus.


using System; using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Diagnostics; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-----------------------------------------"); Console.WriteLine("--- Conversion des fichiers PDF en PPM --"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; PDFToPPM ptp = new PDFToPPM(@"C:\01.pdf", @"C:\mm"); ptp.FileCreated += delegate(string s) { Console.Write("- Création du fichier : " + s); }; ptp.FileWrited += delegate(string s) { Console.ForegroundColor = ConsoleColor.White; Console.Write(" ["); Console.ForegroundColor ]"); }; ptp.Run(); /*Console.WriteLine("- Command line > " + ptp.CommandLine); while (!ptp.StandardError.EndOfStream) { Console.WriteLine("--> " + ptp.StandardError.ReadLine()); }*/ ptp.WaitForExit(); //Console.WriteLine("--> Exit code : " + ptp.Error); ptp.Dispose(); // Le temps que tous les évènements précédents soient bien pris en compte. System.Threading.Thread.Sleep(50); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("--- Conversion des images PPM en JPEG ---"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; string[] files = ptp.OutputFiles; for (int i = 0; i < files.Length; i++) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("- Traitement du fichier : {0}", files[i]); MagickNet.Image mimg = new MagickNet.Image(files[i]); // Attention pas de using MagickNet sinon Image sera défini deux fois... // On peut redimensionner l'image pour gagner du temps... mimg.Resize(new Size((int)(mimg.Size.Width / 5), (int)(mimg.Size.Height / 5))); Bitmap bmp = new Bitmap(mimg.Size.Width, mimg.Size.Height); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("- Format : {0}", mimg.Format); Console.WriteLine("- Nombre de pixels : {0}x{1}", bmp.Width, bmp.Height); Console.Write("- Ligne traitée : "); int cursorLeft = Console.CursorLeft; int cursorTop = Console.CursorTop; Console.ForegroundColor = ConsoleColor.Red; for (int x = 0; x < bmp.Width; x++) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write(x.ToString()); for (int y = 0; y < bmp.Height; y++) bmp.SetPixel(x, y, mimg.get_PixelColor((uint)x, (uint)y).ToSystemColor()); } string output = String.Format("{0}-{1:00}.jpg", ptp.OutputFileBaseName, i); bmp.Save(output, ImageFormat.Jpeg); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(0, cursorTop); Console.WriteLine("- Enregistré sous : {0}", output); Console.ForegroundColor = ConsoleColor.White; } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("------ Suppression des fichiers PPM -----"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; foreach (string f in files) { Console.Write("- Suppression de : {0}", f); File.Delete(f); Console.Write(" ["); Console.ForegroundColor ]"); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("----------- Programme terminé -----------"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Console.Write("Appuyez sur une touche pour quitter l'application."); Console.ReadKey(); } } public class PDFToPPM : IDisposable { public event EventHandler Exited; public event StringEventHandler FileCreated; public event StringEventHandler FileWrited; public delegate void StringEventHandler(string s); bool closed = false; string commandLine; string pdfFile; string outputDirectory; string outputFileBaseName; List<string> outputFiles; int firstPageToPrint; int lastPageToPrint; int resolution; bool mono; bool gray; bool freetype; bool aa; bool aaVector; string ownerPassword = String.Empty; string userPassword = String.Empty; string path; private string error; private string lastFile = String.Empty; Process process; FileSystemWatcher watcher; /// <summary> /// Constructor /// </summary> /// <param name="pdfFile">The full path of the pdf file</param> /// <param name="outputFileBaseName">The full path of the created file. Exemple : C:\\monFichier</param> public PDFToPPM(string pdfFile, string outputFileBaseName) { this.pdfFile = pdfFile; this.outputFileBaseName = outputFileBaseName; if (outputFileBaseName[outputFileBaseName.Length - 1] == '\\') this.outputFileBaseName += "file"; outputDirectory = outputFileBaseName; while (outputDirectory[outputDirectory.Length - 1] != '\\') outputDirectory = outputDirectory.Remove(outputDirectory.Length - 1); watcher = new FileSystemWatcher(outputDirectory); watcher.EnableRaisingEvents = true; watcher.Created += new FileSystemEventHandler(watcherCreated); watcher.Changed += new FileSystemEventHandler(watcherCreated); path = Path.Combine(Environment.CurrentDirectory, "xpdf\\pdftoppm.exe"); } public void Run() { outputFiles = new List<string>(); closed = false; process = new Process(); StringBuilder sb = new StringBuilder(); if (firstPageToPrint > 0) sb.Append("-f " + firstPageToPrint.ToString() + " "); if (lastPageToPrint > 0) sb.Append("-l " + lastPageToPrint.ToString() + " "); if (resolution > 0) sb.Append("-r " + lastPageToPrint.ToString() + " "); if (mono) sb.Append("-mono "); if (gray) sb.Append("-gray "); if (freetype) sb.Append("-freetype yes "); if (aa) sb.Append("-aa yes "); if (aaVector) sb.Append("-aaVector yes "); if (ownerPassword != String.Empty) sb.Append("-opw " + ownerPassword + " "); if (userPassword != String.Empty) sb.Append("-upw " + userPassword + " "); sb.Append("\""); sb.Append(pdfFile); sb.Append("\" \""); sb.Append(outputFileBaseName); sb.Append("\""); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = path; startInfo.Arguments = sb.ToString(); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; commandLine = startInfo.FileName + " " + startInfo.Arguments; process.StartInfo = startInfo; process.EnableRaisingEvents = true; process.Exited += new EventHandler(processExited); process.Start(); } public void Dispose() { watcher.Dispose(); } private void watcherCreated(object sender, FileSystemEventArgs e) { if (!outputFiles.Contains(e.FullPath)) { outputFiles.Add(e.FullPath); if (lastFile != String.Empty && FileWrited != null) FileWrited(lastFile); lastFile = e.FullPath; if (FileCreated != null) FileCreated(e.FullPath); } } public void WaitForExit() { if (!closed) process.WaitForExit(); } private void processExited(object sender, EventArgs e) { if (!closed) { if (lastFile != String.Empty && FileWrited != null) FileWrited(lastFile); if (Exited != null) Exited(sender, e); switch (process.ExitCode) { case 0: error = "No error."; break; case 1: error = "Error opening a PDF file."; break; case 2: error = "Error opening an output file."; break; case 3: error = "Error related to PDF permissions."; break; case 99: default: error = "Other error"; break; } process.Close(); closed = true; } } #region Properties public StreamReader StandardOutput { get { return process.StandardOutput; } } public StreamReader StandardError { get { return process.StandardError; } } /// <summary> /// Get the exit code of the process /// </summary> public string Error { get { return error; } } /// <summary> /// Get the command line used by the process /// </summary> public string CommandLine { get { return commandLine; } } /// <summary> /// File's names of the generated ppm files /// </summary> public string[] OutputFiles { get { return outputFiles.ToArray(); } } /// <summary> /// The file to convert /// </summary> public string PdfFile { get { return pdfFile; } set { pdfFile = value; } } /// <summary> /// The output directory /// </summary> public string OutputDirectory { get { return outputDirectory; } } /// <summary> /// The output file base name /// </summary> public string OutputFileBaseName { get { return outputFileBaseName; } } /// <summary> /// First page to print /// </summary> public int FirstPageToPrint { get { return firstPageToPrint; } set { firstPageToPrint = value; } } /// <summary> /// Last page to print /// </summary> public int LastPageToPrint { get { return lastPageToPrint; } set { lastPageToPrint = value; } } /// <summary> /// Resolution in DPI (default is 150) /// </summary> public int Resolution { get { return resolution; } set { resolution = value; } } /// <summary> /// Generate a monochrome PBM file /// </summary> public bool Mono { get { return mono; } set { mono = value; } } /// <summary> /// Generate a grayscale PGM file /// </summary> public bool Gray { get { return gray; } set { gray = value; } } /// <summary> /// Enable or disable FreeType font rasterrizer /// </summary> public bool FreeType { get { return freetype; } set { freetype = value; } } /// <summary> /// Enable or disable font anti-aliasing /// </summary> public bool Aa { get { return aa; } set { aa = value; } } /// <summary> /// Enable or disable vector anti-aliasing /// </summary> public bool AaVector { get { return aaVector; } set { aaVector = value; } } /// <summary> /// Owner password (for encrypted files) /// </summary> public string OwnerPassword { get { return ownerPassword; } set { ownerPassword = value; } } /// <summary> /// User password (for encrypted files) /// </summary> public string UserPassword { get { return userPassword; } set { userPassword = value; } } #endregion } }


Ca convertit automatiquement les fichiers pdf en jpeg (en passant par du ppm obligé) et supprime les fichiers temporaires.
Avec çà, t'as juste besoin de MagickNet.dll et du programme pdftoppm.exe se trouvant dans le dossier xpdf situé lui même dans le dossier où l'exécutable de ton application est lancé.

Ca marche nikel, j'ai eu aucun souci à convertir ton pdf.

Remarque : J'arrivais pas à me servir de ton fichier pistache alors j'ai recodé une classe qui exploite totalement l'exe pdftoppm... Toutes les options sont intégrées dedans.

La conversion ppm to jpeg est assez chiante... Vu que la méthode statique ToBitmap de MagickNet.Image crashait tout le temps, j'ai du y aller pixel par pixel pour obtenir quelque chose qui marche. Ca marche super mais çà peut prendre un peu de temps pour les très grosses images... C'est le seul point à améliorer.

Jettes-y un oeil Nej et dis moi ce que t'en penses.

@/+ et bonnes vacances pistache.

PS : le programme pdftoppm se comporte assez bizarrement sur son deuxième argument (le root dir)... Je l'ai implémenté dans ma classe pour que çà marche sans nous démonter le cerveau à chaque fois.

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Nej
Membre actif
Inscrit : 28/01/2008
Messages : 107
Message
#149831
Posté le 28/02/08 à 08:54
ok Czayfaboo je regarderais ça à tête reposée ce week-end!

pour la conversion des ppm , j'ai utilisé une dll:

http://www.codeproject.com/KB/cs/Managed_PGM.aspx

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Nej
Membre actif
Inscrit : 28/01/2008
Messages : 107
Message
#149867
Posté le 29/02/08 à 10:00
Bon je repost s'il est nécessaire d'ouvrir un autre topic dites le moi!

J'arrive bine à convertir les ppm en jpeg, le petit souci c'est que j'ai essayé avec un pdf très haute résolution de 2 pages cela à mis 15minutes, et donc 5 heures pour un catalogue de 40 pages cela fait beaucoup!

J'ai trouvé un site :
http://fr.imageconverterplus.com/purchase/

Mais ils donnent seulement le programme sans dll (j'ai regardé dans visual après install mais pas de dll en vu)

Donc voila je voudrais savoir si vous aviez des pistes pour ce genre de dll, car en utilisant leur prog cela m'a prit 1 minutes au maximum, on gagne donc 4 heures et 59 minutes ce qui est plutot pas mal^^

Je précise que le fait que la dll soit payante n'est pas un souci!

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Czayfaboo
Superviseur :
- Langages Dot.
Modérateur :
- CSharp (C#)
Chef de projet(s) :
- ID3.NET Library
- MoteurProg Work.

Avatar de Czayfaboo
Inscrit : 05/01/2005
Messages : 3130
Message
#149892
Posté le 29/02/08 à 16:07
salut !

Tu convertis comment finalement tes ppm en jpeg ?

Je vais aller voir tes liens...

€dit : A oki, c'est le lien que tu m'avais filé au dessus... Et le morceau de code que je t'ai filé çà va plus vite ou plus lentement ? Perso, pour un format A4, çà me prenait quelque chose comme 30 secondes par page... Essaie de voir ce que çà donne chez toi.

€dit 2 : on pourrait avoir le pdf de très haute résolution pour tester ?

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Nej
Membre actif
Inscrit : 28/01/2008
Messages : 107
Message
#149897
Posté le 29/02/08 à 16:42
J'ai pas encore essayé ton bon de code!

Déjà j'ai debuggé mon programme qui pourrissait de partout ^^

ensuite là je rajoute quelques petites fonctions nécessaires, et quand tout sera bien propre d'ici la fin du week end je m'affaire à gagner du temps pour la transformation!

et sinon voila le pdf, plus de 16mb pour deux pages:

http://www.megaupload.com/fr/?d=3CQKWQUT

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

pistache
Superviseur :
- CSharp (C#)
Modérateur :
- VB .NET
- XAML
Chef de projet(s) :
- Image Data base
- Titan

Avatar de pistache
Inscrit : 22/02/2005
Messages : 1305
Message
#149951
Posté le 02/03/08 à 14:11
Hop là, fini le ski Smiley

Czayfaboo > Oui j'ai vu ça pour ToBitmap.

Chez moi ça marche sur le .NET 2.0 mais pas sur le .NET 3.0 ...

Peut etre que l'implementation n'est pas bonne...

Nej > Là ton problème c'est en utilisant http://www.codeproject.com/KB/cs/Managed_PGM.aspx ?

Peut etre qu'il y a une option qui gère la qualité dans leur DLL ?
__________________________
Image
La quadrature du net

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Czayfaboo
Superviseur :
- Langages Dot.
Modérateur :
- CSharp (C#)
Chef de projet(s) :
- ID3.NET Library
- MoteurProg Work.

Avatar de Czayfaboo
Inscrit : 05/01/2005
Messages : 3130
Message
#149968
Posté le 02/03/08 à 22:17
Salut !

Bon, ben j'ai retouché un peu mon code et voila :
- l'original mettait 3 minutes pour convertir ton fichier (méthode 1)
- la deuxième méthode met entre 70 et 75 s pour faire la conversion
- la troisième met 65 s à peu près.

Voici la maj :

using System; using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Diagnostics; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { static void Main() { Stopwatch chrono = new Stopwatch(); chrono.Start(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-----------------------------------------"); Console.WriteLine("--- Conversion des fichiers PDF en PPM --"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; PDFToPPM ptp = new PDFToPPM(@"C:\Binder1.pdf", @"C:\mm"); ptp.FileCreated += delegate(string s) { Console.Write("- Création du fichier : " + s); }; ptp.FileWrited += delegate(string s) { Console.ForegroundColor = ConsoleColor.White; Console.Write(" ["); Console.ForegroundColor ]"); }; ptp.Run(); /*Console.WriteLine("- Command line > " + ptp.CommandLine); while (!ptp.StandardError.EndOfStream) { Console.WriteLine("--> " + ptp.StandardError.ReadLine()); }*/ ptp.WaitForExit(); //Console.WriteLine("--> Exit code : " + ptp.Error); ptp.Dispose(); // Le temps que tous les évènements précédents soient bien pris en compte. System.Threading.Thread.Sleep(50); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("--- Conversion des images PPM en JPEG ---"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; string[] files = ptp.OutputFiles; for (int i = 0; i < files.Length; i++) { string output = String.Format("{0}-{1:00}.jpg", ptp.OutputFileBaseName, i); ConvertImageTo_3(files[i], output, ImageFormat.Jpeg); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("------ Suppression des fichiers PPM -----"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; foreach (string f in files) { Console.Write("- Suppression de : {0}", f); File.Delete(f); Console.Write(" ["); Console.ForegroundColor ]"); } chrono.Stop(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("----------- Programme terminé -----------"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Temps total de l'opération : {0} ms", chrono.ElapsedMilliseconds); Console.Write("Appuyez sur une touche pour quitter l'application."); Console.ReadKey(); } public static void ConvertImageTo_1(string fileSource, string fileDestination, ImageFormat format) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("- Traitement du fichier : {0}", fileSource); MagickNet.Image mimg = new MagickNet.Image(fileSource); // Attention pas de using MagickNet sinon Image sera défini deux fois... // On peut redimensionner l'image pour gagner du temps... //mimg.Resize(new Size((int)(mimg.Size.Width / 5), (int)(mimg.Size.Height / 5))); Bitmap bmp = new Bitmap(mimg.Size.Width, mimg.Size.Height); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("- Format : {0}", mimg.Format); Console.WriteLine("- Nombre de pixels : {0}x{1}", bmp.Width, bmp.Height); Console.Write("- Ligne traitée : "); int cursorLeft = Console.CursorLeft; int cursorTop = Console.CursorTop; Console.ForegroundColor = ConsoleColor.Red; for (int x = 0; x < bmp.Width; x++) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write(x.ToString()); for (int y = 0; y < bmp.Height; y++) bmp.SetPixel(x, y, mimg.get_PixelColor((uint)x, (uint)y).ToSystemColor()); } bmp.Save(fileDestination, format); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(0, cursorTop); Console.WriteLine("- Enregistré sous : {0}", fileDestination); Console.ForegroundColor = ConsoleColor.White; } // Code optimisé pour traiter les fichiers issus du programme pdftoppm.exe, inspiré du projet ShaniSoftDrawing public static void ConvertImageTo_2(string fileSource, string fileDestination, ImageFormat format) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("- Traitement du fichier : {0}", fileSource); FileStream fs = new FileStream(fileSource, FileMode.Open); StreamReader sr = new StreamReader(fs); string line1 = sr.ReadLine(); string line2 = sr.ReadLine(); string line3 = sr.ReadLine(); fs.Seek(line1.Length + line2.Length + line3.Length + 3, SeekOrigin.Begin); BinaryReader br = new BinaryReader(fs); string[] split = line2.Split(' '); int width = Int32.Parse(split[0]); int height = Int32.Parse(split[1]); int R, G, B; Bitmap bmp = new Bitmap(width, height); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("- Nombre de pixels : {0}x{1}",width, height); Console.Write("- Ligne traitée : "); int cursorLeft = Console.CursorLeft; int cursorTop = Console.CursorTop; Console.ForegroundColor = ConsoleColor.Red; for (int y = 0; y < height; y++) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write(y.ToString()); for (int x = 0; x < width; x++) { R = br.ReadByte(); G = br.ReadByte(); B = br.ReadByte(); bmp.SetPixel(x, y, Color.FromArgb(R, G, B)); } } bmp.Save(fileDestination, format); br.Close(); sr.Close(); fs.Close(); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(0, cursorTop); Console.WriteLine("- Enregistré sous : {0}", fileDestination); Console.ForegroundColor = ConsoleColor.White; } // Pareil que la 2 mais encore plus rapide ;) public static void ConvertImageTo_3(string fileSource, string fileDestination, ImageFormat format) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("- Traitement du fichier : {0}", fileSource); FileStream fs = new FileStream(fileSource, FileMode.Open); StreamReader sr = new StreamReader(fs); string line1 = sr.ReadLine(); string line2 = sr.ReadLine(); string line3 = sr.ReadLine(); sr.Close(); fs.Close(); string[] split = line2.Split(' '); int width = Int32.Parse(split[0]); int height = Int32.Parse(split[1]); Bitmap bmp = new Bitmap(width, height); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("- Nombre de pixels : {0}x{1}", width, height); Console.Write("- Ligne traitée : "); int cursorLeft = Console.CursorLeft; int cursorTop = Console.CursorTop; int counter = line1.Length + line2.Length + line3.Length + 2; Console.ForegroundColor = ConsoleColor.Red; byte[] file = File.ReadAllBytes(fileSource); for (int y = 0; y < height; y++) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write(y.ToString()); for (int x = 0; x < width; x++) { bmp.SetPixel(x, y, Color.FromArgb(file[++counter], file[++counter], file[++counter])); } } bmp.Save(fileDestination, format); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(0, cursorTop); Console.WriteLine("- Enregistré sous : {0}", fileDestination); Console.ForegroundColor = ConsoleColor.White; } } public class PDFToPPM : IDisposable { public event EventHandler Exited; public event StringEventHandler FileCreated; public event StringEventHandler FileWrited; public delegate void StringEventHandler(string s); bool closed = false; string commandLine; string pdfFile; string outputDirectory; string outputFileBaseName; List<string> outputFiles; int firstPageToPrint; int lastPageToPrint; int resolution; bool mono; bool gray; bool freetype; bool aa; bool aaVector; string ownerPassword = String.Empty; string userPassword = String.Empty; string path; private string error; private string lastFile = String.Empty; Process process; FileSystemWatcher watcher; /// <summary> /// Constructor /// </summary> /// <param name="pdfFile">The full path of the pdf file</param> /// <param name="outputFileBaseName">The full path of the created file. Exemple : C:\\monFichier</param> public PDFToPPM(string pdfFile, string outputFileBaseName) { this.pdfFile = pdfFile; this.outputFileBaseName = outputFileBaseName; if (outputFileBaseName[outputFileBaseName.Length - 1] == '\\') this.outputFileBaseName += "file"; outputDirectory = outputFileBaseName; while (outputDirectory[outputDirectory.Length - 1] != '\\') outputDirectory = outputDirectory.Remove(outputDirectory.Length - 1); watcher = new FileSystemWatcher(outputDirectory); watcher.EnableRaisingEvents = true; watcher.Created += new FileSystemEventHandler(watcherCreated); watcher.Changed += new FileSystemEventHandler(watcherCreated); path = Path.Combine(Environment.CurrentDirectory, "xpdf\\pdftoppm.exe"); } public void Run() { outputFiles = new List<string>(); closed = false; process = new Process(); StringBuilder sb = new StringBuilder(); if (firstPageToPrint > 0) sb.Append("-f " + firstPageToPrint.ToString() + " "); if (lastPageToPrint > 0) sb.Append("-l " + resolution.ToString() + " "); if (resolution > 0) sb.Append("-r " + lastPageToPrint.ToString() + " "); if (mono) sb.Append("-mono "); if (gray) sb.Append("-gray "); if (freetype) sb.Append("-freetype yes "); if (aa) sb.Append("-aa yes "); if (aaVector) sb.Append("-aaVector yes "); if (ownerPassword != String.Empty) sb.Append("-opw " + ownerPassword + " "); if (userPassword != String.Empty) sb.Append("-upw " + userPassword + " "); sb.Append("\""); sb.Append(pdfFile); sb.Append("\" \""); sb.Append(outputFileBaseName); sb.Append("\""); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = path; startInfo.Arguments = sb.ToString(); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; commandLine = startInfo.FileName + " " + startInfo.Arguments; process.StartInfo = startInfo; process.EnableRaisingEvents = true; process.Exited += new EventHandler(processExited); process.Start(); } public void Dispose() { watcher.Dispose(); } private void watcherCreated(object sender, FileSystemEventArgs e) { if (!outputFiles.Contains(e.FullPath)) { outputFiles.Add(e.FullPath); if (lastFile != String.Empty && FileWrited != null) FileWrited(lastFile); lastFile = e.FullPath; if (FileCreated != null) FileCreated(e.FullPath); } } public void WaitForExit() { if (!closed) process.WaitForExit(); } private void processExited(object sender, EventArgs e) { if (!closed) { if (lastFile != String.Empty && FileWrited != null) FileWrited(lastFile); if (Exited != null) Exited(sender, e); switch (process.ExitCode) { case 0: error = "No error."; break; case 1: error = "Error opening a PDF file."; break; case 2: error = "Error opening an output file."; break; case 3: error = "Error related to PDF permissions."; break; case 99: default: error = "Other error"; break; } process.Close(); closed = true; } } #region Properties public StreamReader StandardOutput { get { return process.StandardOutput; } } public StreamReader StandardError { get { return process.StandardError; } } /// <summary> /// Get the exit code of the process /// </summary> public string Error { get { return error; } } /// <summary> /// Get the command line used by the process /// </summary> public string CommandLine { get { return commandLine; } } /// <summary> /// File's names of the generated ppm files /// </summary> public string[] OutputFiles { get { return outputFiles.ToArray(); } } /// <summary> /// The file to convert /// </summary> public string PdfFile { get { return pdfFile; } set { pdfFile = value; } } /// <summary> /// The output directory /// </summary> public string OutputDirectory { get { return outputDirectory; } } /// <summary> /// The output file base name /// </summary> public string OutputFileBaseName { get { return outputFileBaseName; } } /// <summary> /// First page to print /// </summary> public int FirstPageToPrint { get { return firstPageToPrint; } set { firstPageToPrint = value; } } /// <summary> /// Last page to print /// </summary> public int LastPageToPrint { get { return lastPageToPrint; } set { lastPageToPrint = value; } } /// <summary> /// Resolution in DPI (default is 150) /// </summary> public int Resolution { get { return resolution; } set { resolution = value; } } /// <summary> /// Generate a monochrome PBM file /// </summary> public bool Mono { get { return mono; } set { mono = value; } } /// <summary> /// Generate a grayscale PGM file /// </summary> public bool Gray { get { return gray; } set { gray = value; } } /// <summary> /// Enable or disable FreeType font rasterrizer /// </summary> public bool FreeType { get { return freetype; } set { freetype = value; } } /// <summary> /// Enable or disable font anti-aliasing /// </summary> public bool Aa { get { return aa; } set { aa = value; } } /// <summary> /// Enable or disable vector anti-aliasing /// </summary> public bool AaVector { get { return aaVector; } set { aaVector = value; } } /// <summary> /// Owner password (for encrypted files) /// </summary> public string OwnerPassword { get { return ownerPassword; } set { ownerPassword = value; } } /// <summary> /// User password (for encrypted files) /// </summary> public string UserPassword { get { return userPassword; } set { userPassword = value; } } #endregion } }


Dis moi ce que çà donne chez toi.

€dit par pistache : correction bug reporté par Nej

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 
POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

PREMIERE PAGE

PAGE PRECEDENTE Page précédente

Page suivante

PAGE SUIVANTE DERNIERE PAGE

FORUM CSHARP (C#)



    PAGES : [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [>>]



.: Site Web développé par Yann Pingot et l'équipe MPWG avec www.evolvia-web.com :.