private void btnConvertJPG_Click(object sender, EventArgs e) // PDF convert to Image Function { SautinSoft.PdfFocus JPG = new SautinSoft.PdfFocus(); // 呼叫SautinSoft中的Image Convert Function JPG.OpenPdf(textBox1.Text); if (JPG.PageCount > 0) { JPG.ImageOptions.Dpi = 200; JPG.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; for (int page = 1; page <= JPG.PageCount; page++) { JPG.ToImage(textBox1.Text + "page" + page + ".jpg", page); } } }
public static void ConvertToPng(object targ) { TArgument targum = (TArgument)targ; string pdfFile = targum.PdfFile; int page = targum.PageNumber; string pngFile = Path.GetFileNameWithoutExtension(pdfFile) + ".png"; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png; f.ImageOptions.Dpi = 300; f.OpenPdf(pdfFile); bool done = false; if (f.PageCount > 0) { if (page >= f.PageCount) { page = 1; } if (f.ToImage(pngFile, page) == 0) { done = true; } f.ClosePdf(); } if (done) { Console.WriteLine("{0}\t - Done!", Path.GetFileName(pdfFile)); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pngFile) { UseShellExecute = true }); } else { Console.WriteLine("{0}\t - Error!", Path.GetFileName(pdfFile)); } }
/// <summary> /// Converts PDF to DOCX, RTF, HTML, XML, Excel (XLS), PNG, Multipage TIFF, Text. /// </summary> public static void ConvertPdfToAll() { SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); string pdfFile = @"..\..\..\..\simple text.pdf"; string outFile = String.Empty; f.OpenPdf(pdfFile); if (f.PageCount > 0) { // To Docx. outFile = Path.ChangeExtension(pdfFile, ".docx"); f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Docx; if (f.ToWord(outFile) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To Rtf. outFile = Path.ChangeExtension(pdfFile, ".rtf"); f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Rtf; if (f.ToWord(outFile) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To Excel. outFile = Path.ChangeExtension(pdfFile, ".xls"); f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true; if (f.ToExcel(outFile) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To HTML. outFile = Path.ChangeExtension(pdfFile, ".html"); f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true; if (f.ToHtml(outFile) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To XML. outFile = Path.ChangeExtension(pdfFile, ".xml"); f.XmlOptions.ConvertNonTabularDataToSpreadsheet = true; if (f.ToXml(outFile) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To Image. outFile = Path.ChangeExtension(pdfFile, ".png"); f.ImageOptions.Dpi = 300; f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png; if (f.ToImage(outFile, 1) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To Multipage Tiff (Black & White). outFile = Path.ChangeExtension(pdfFile, ".tiff"); f.ImageOptions.ColorDepth = PdfFocus.CImageOptions.eColorDepth.BlackWhite1bpp; if (f.ToMultipageTiff(outFile, System.Drawing.Imaging.EncoderValue.CompressionCCITT4) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } // To Text. outFile = Path.ChangeExtension(pdfFile, ".txt"); if (f.ToText(outFile) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } } else { Console.WriteLine("Error: {0}!", f.Exception.Message); Console.ReadLine(); } }