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.
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!
€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 ?
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:
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