public ActionResult getData(string category, string name, string equation, HttpPostedFileBase file) { string fileName = category + name; string path = ""; string pathOfFolder = ""; p = new Picture(category, name, equation, file); Vuforia v; if (file.ContentLength > 0) { path = Path.Combine(Server.MapPath("~/Content/images"), fileName); pathOfFolder = Server.MapPath("~/Content/images") + "\\"; file.SaveAs(path); } SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(path); if (f.PageCount > 0) { f.ImageOptions.Dpi = 300; f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; for (int page = 1; page <= f.PageCount; page++) { f.ToImage(pathOfFolder + "MyPDFImage.jpg", page); } } return View("TargetSelection"); //v = new Vuforia(fileName, path); //v.postTarget(); }
public static string getImageFromPDF(string pdfData, int[] pages) { List <CroppedImage> list = new List <CroppedImage>(); // var data = JsonConvert.DeserializeObject<List<int>>(pages); SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); byte[] sPDFDecoded = Convert.FromBase64String(pdfData); f.OpenPdf(sPDFDecoded); if (f.PageCount > 0) { //save 1st page to png file, 120 dpi f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; f.ImageOptions.Dpi = 100; foreach (int i in pages) { Bitmap source_image = (Bitmap)f.ToDrawingImage(i); int x = 0; int y = 92; int w = source_image.Width; int h = source_image.Height; // 상단 라이센스 부분 처리 using (Bitmap target_image = new Bitmap(w, h)) { using (Graphics g = Graphics.FromImage(target_image)) { g.DrawImage(source_image, 0, 0, new Rectangle(x, y, w, h), GraphicsUnit.Pixel); // g.Flush(); } // Bitmap bImage = newImage; //Your Bitmap Image System.IO.MemoryStream ms = new System.IO.MemoryStream(); target_image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] byteImage = ms.ToArray(); var SigBase64 = Convert.ToBase64String(byteImage); //Get Base64 list.Add(new CroppedImage() { no = i, image = SigBase64 }); } } } return(JsonConvert.SerializeObject(list)); }
public static void ExtractXml(string pdfPath) { SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); string xmlPath = System.IO.Path.ChangeExtension(pdfPath, ".xml"); //f.XmlOptions.ConvertNonTabularDataToSpreadsheet = true; f.OpenPdf(pdfPath); if (f.PageCount > 0) { int result = f.ToXml(xmlPath); } }
private void next_Click(object sender, EventArgs e) { currentPage++; PageCountLbl.Text = $"{currentPage} of {pageCount}"; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(paths[0]); if (f.PageCount > 0) { f.ImageOptions.Dpi = 50; page.Image = f.ToDrawingImage(currentPage); } }
private static void ConvertPdfStreamToHtml() { string pathToPdf = @"..\..\..\..\..\simple text.pdf"; string pathToHtml = Path.ChangeExtension(pathToPdf, ".htm"); // This list will be filled by images after the PDF to HTML conversion. List <Image> imgCollection = new List <Image>(); // Convert PDF to HTML in memory SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // Let's force the component to store images inside HTML document // using base-64 encoding. // Thus the component will not use HDD. f.HtmlOptions.IncludeImageInHtml = true; f.HtmlOptions.Title = "Simple text"; f.HtmlOptions.InlineCSS = true; // This property is necessary only for registered version //f.Serial = "XXXXXXXXXXX"; // Read a PDF document to byte array // Assume that we have a PDF document as Stream. using (FileStream fs = File.OpenRead(pathToPdf)) { f.OpenPdf(fs); if (f.PageCount > 0) { // Convert PDF to HTML string. string html = f.ToHtml(1, f.PageCount, imgCollection); // Show info about images. Console.WriteLine("After converting we've got {0} image(s):", imgCollection.Count); foreach (Image img in imgCollection) { Console.WriteLine("\t {0,4} x {1,4} px", img.Width, img.Height); } Console.WriteLine("Press any key ..."); Console.ReadLine(); // Save HTML to a file only for demonstration purposes. if (html != null) { File.WriteAllText(pathToHtml, html); System.Diagnostics.Process.Start(pathToHtml); } } } }
public static List <Image> pdfToImages(String pdfPath, int idProjet) { List <Image> images = new List <Image>(); // Convert PDF to JPG with high Quality SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for registered version // f.Serial = "XXXXXXXXXXX"; string pdfName = Path.GetFileNameWithoutExtension(pdfPath); string pdfDir = Path.GetDirectoryName(pdfPath); String jpegDir = ConfigurationManager.AppSettings["MainFolder"].ToString(); f.OpenPdf(pdfPath); if (f.PageCount > 0) { // Set image properties: Jpeg, 200 dpi f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; f.ImageOptions.Dpi = 200; // Set 95 as JPEG quality f.ImageOptions.JpegQuality = 95; //Save all PDF pages to image folder, each file will have name Page 1.jpg, Page 2.jpg, Page N.jpg for (int page = 1; page <= f.PageCount; page++) { string jpegFile = Path.Combine(jpegDir, String.Format(pdfName + " page {0}.jpg", page)); Image image = new Image(jpegFile, mainForm.utilisateur.idUtilisateur, idProjet); // 0 - converted successfully // 2 - can't create output file, check the output path // 3 - conversion failed int result = f.ToImage(jpegFile, page); if (result.Equals(0)) { images.Add(image); } else { Console.WriteLine("error"); } } return(images); } return(null); }
static void Main(string[] args) { // Convert PDF to separate HTMLs. // Each PDF page will be converted to a single HTML document. string pdfFile = @"..\..\simple text.pdf"; DirectoryInfo htmlDir = new DirectoryInfo("htmls"); if (!htmlDir.Exists) { htmlDir.Create(); } SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for licensed version. //f.Serial = "XXXXXXXXXXX"; f.HtmlOptions.IncludeImageInHtml = false; // Path (must exist) to a directory to store images after converting. f.HtmlOptions.ImageFolder = htmlDir.FullName; f.OpenPdf(pdfFile); if (f.PageCount > 0) { // Convert each PDF page to separate HTML document. // simple text.html, simple text.html ... simple text.html. for (int page = 1; page <= f.PageCount; page++) { f.HtmlOptions.Title = $"Page {page}"; f.HtmlOptions.ImageSubFolder = String.Format("page{0}_images", page); string htmlString = f.ToHtml(page, page); // Save htmlString to file string htmlFile = Path.Combine(htmlDir.FullName, $"Page{page}.html"); File.WriteAllText(htmlFile, htmlString); // Let's open only 1st and last pages. if (page == 1 || page == f.PageCount) { // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile) { UseShellExecute = true }); } } } }
public ActionResult Checkout(int?id) { if (id != null) { SautinSoft.PdfFocus pdfFocus = new SautinSoft.PdfFocus(); pdfFocus.OpenPdf(UploadFile(id).FileContent); TextFileFormat textFormat = new TextFileFormat(); textFormat.PDFtext = pdfFocus.ToText(); return(View(textFormat)); } else { return(RedirectToAction("Index")); } }
private String convertPDFtoJPG(string filePDFFullName) { int len = filePDFFullName.LastIndexOf("."); string fileLocation = filePDFFullName.Substring(0, len) + ".jpg"; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(@filePDFFullName); if (f.PageCount > 0) { f.ImageOptions.Dpi = 300; f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; f.ToImage(fileLocation, 1); } f.ClosePdf(); return(fileLocation); }
private static XmlNodeList OpenAndConvertPDFToXML(string filepath) { string output = filepath.Remove(filepath.LastIndexOf('.')) + ".xml"; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.XmlOptions.ConvertNonTabularDataToSpreadsheet = false; f.OpenPdf(filepath); f.ToXml(output); f.ClosePdf(); var xmlDoc = new XmlDocument(); xmlDoc.Load(output); return(xmlDoc.SelectNodes("document/page/table/row")); }
private void btnConvertirWord_Click(object sender, EventArgs e) { this.progressBar1.Increment(1); if (Convertir) { // this.progressBar1.Increment(20); SautinSoft.PdfFocus ArchivoPDF = new SautinSoft.PdfFocus(); // this.progressBar1.Increment(30); ArchivoPDF.OpenPdf(@RutaArchivoOrigen); // this.progressBar1.Increment(25); ArchivoPDF.ToWord(@RutaArchivoDestino + "\\" + NombreArchivoOrigen + ".docx"); // this.progressBar1.Increment(25); System.Diagnostics.Process.Start(@RutaArchivoDestino); //Proceso Terminado MessageBox.Show("Archivo Convertido x Sebithaxx"); } }
static void Main(string[] args) { SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(@"D:\Integra training\fileConversion\scansmpl.pdf"); if (f.PageCount > 0) { f.ImageOptions.Dpi = 200; f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; for (int page = 1; page <= f.PageCount; page++) { f.ToImage(@"D:\Integra training\fileConversion\images\" + "page" + page + ".jpg", page); } Console.ReadKey(); } }
private static void ConvertPdfStreamToHtml() { // We need files only for demonstration purposes. // The whole conversion process will be done in memory. string templateFile = "/Users/user/Downloads/1022out.pdf"; string outFile = "/Users/user/Downloads/1022out.html"; // Convert PDF to HTML in memory SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for licensed version. //f.Serial = "XXXXXXXXXXX"; // Let's force the component to store images inside HTML document // using base-64 encoding. // Thus the component will not use HDD. f.HtmlOptions.IncludeImageInHtml = true; f.HtmlOptions.Title = "Simple text"; // Assume that we have a PDF document as Stream. using (FileStream fs = File.OpenRead(templateFile)) { f.OpenPdf(fs); if (f.PageCount > 0) { // Convert PDF to HTML to a MemoryStream. using (MemoryStream msHtml = new MemoryStream()) { int res = f.ToHtml(msHtml); // Open the result for demonstation purposes. if (res == 0) { File.WriteAllBytes(outFile, msHtml.ToArray()); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true }); } } } } }
private void btnBaslat_Click(object sender, EventArgs e) { if (txtFaturaYolu.Text.Equals("")) { System.Windows.Forms.MessageBox.Show("Fatura Yolu Seçilmeli", "Message"); return; } else if (txtExcellYolu.Text.Equals("")) { System.Windows.Forms.MessageBox.Show("Excell Yolu Seçilmeli", "Message"); return; } faturalar = new List <FaturaOrnegi>(); string pathToExcel; Directory.CreateDirectory(selectedPath + @"\\Fatura_Excell"); SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for registered version //f.Serial = "XXXXXXXXXXX"; // 'true' = Convert all data to spreadsheet (tabular and even textual). // 'false' = Skip textual data and convert only tabular (tables) data. f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true; // 'true' = Preserve original page layout. // 'false' = Place tables before text. f.ExcelOptions.PreservePageLayout = true; foreach (String file in pdfFiles) { pathToExcel = ReplaceLastOccurence(file, @"\", @"\Fatura_Excell\"); pathToExcel = Path.ChangeExtension(pathToExcel, ".xls"); f.OpenPdf(file); if (f.PageCount > 0) { int result = f.ToExcel(pathToExcel); } f.ClosePdf(); } readExcelFiles(Directory.GetFiles(selectedPath + @"\Fatura_Excell", "*.xls")); }
private void btnConvPdf_Click(object sender, EventArgs e) { if (!Directory.Exists("new_pdf")) { Directory.CreateDirectory("new_Pdf"); } SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); foreach (var i in lbxFile.Items) { f.OpenPdf(i + ""); f.ToWord(@"new_pdf\\" + Path.GetFileName(i + "") + ".doc"); } MessageBox.Show("Ok converted"); lbxFile.Items.Clear(); btnConvPdf.Enabled = false; Process.Start("new_Pdf"); // FileStream stream = File.Open("new_Pdf", FileMode.Open); }
private void listView2_SelectedIndexChanged(object sender, EventArgs e) { if (listView2.SelectedItems.Count > 0) { using (PdfReader reader = new PdfReader(paths.Find(x => x.Contains(listView2.SelectedItems[0].Text)))) { pageCount = reader.NumberOfPages; PageCountLbl.Text = $"{currentPage} of {pageCount}"; } } SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(paths.Find(x => x.Contains(listView2.SelectedItems[0].Text))); if (f.PageCount > 0) { f.ImageOptions.Dpi = 50; page.Image = f.ToDrawingImage(currentPage); } }
static void Main(string[] args) { // Convert whole PDF document to separate Word documents. // Each PDF page will be converted to a single Word document. // Path to a PDF file. // string pdfPath = Path.GetFullPath(@"d:\Tempos\Text.pdf"); string pdfPath = Path.GetFullPath(@"Text.pdf"); string textFile = Path.ChangeExtension(pdfPath, ".txt"); // Directory to store Word documents. string docxDir = Path.GetDirectoryName(pdfPath); SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(pdfPath); // Convert each PDF page to separate Word document. // simple text - page 1.docx, simple text- page 2.docx ... simple text - page N.doc. // for (int page = 1; page <= f.PageCount; page++) // { // wrzuca caly plik do txt - okraja bo to eval int result = f.ToText(textFile); /* * // You may select between Docx and Rtf formats. * f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx; * * byte [] docxBytes = f.ToWord(page, page); * * string tempName = Path.GetFileNameWithoutExtension(pdfPath) + String.Format(" - page {0}.docx", page); * string docxPath = Path.Combine(docxDir, tempName); * File.WriteAllBytes(docxPath, docxBytes); * * // Let's show first and last Word pages. * if (page == 1 || page==f.PageCount) * System.Diagnostics.Process.Start(docxPath); */ // } }
private void btnConverte_Click(object sender, EventArgs e) { SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); string pdfFile = txtCaminhoArquivoPDF.Text; string wordFile = Path.ChangeExtension(pdfFile, ".docx"); f.OpenPdf(pdfFile); if (f.PageCount > 0) { int result = f.ToWord(wordFile); if (result == 0) { System.Diagnostics.Process.Start(wordFile); } } }
public static String GetTextFromPDF(string filePath) { string texto = string.Empty; try { SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.XmlOptions.ConvertNonTabularDataToSpreadsheet = true; f.OpenPdf(filePath); texto = f.ToText(); //f.ToHtml(@"c:\Table.xml"); //SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); //f.OpenPdf(filePath); //if (f.PageCount > 0) //{ // texto = f.ToText(); // texto = f.ToXml(); //} //using (PdfReader reader = new PdfReader(filePath)) //{ // string prevPage = ""; // for (int page = 1; page <= reader.NumberOfPages; page++) // { // ITextExtractionStrategy its = new SimpleTextExtractionStrategy(); // var s = PdfTextExtractor.GetTextFromPage(reader, page, its); // if (prevPage != s) sb.Append(s); // prevPage = s; // } // reader.Close(); //} } catch (Exception ex) { _ = ex.Message; } return(texto); }
private void Pdf_Merge(FileInfo[] all, string path, string batch) { try { PdfSharp.Pdf.PdfDocument output = new PdfSharp.Pdf.PdfDocument(); foreach (var a in all) { PdfSharp.Pdf.PdfDocument input = PdfSharp.Pdf.IO.PdfReader.Open(a.FullName, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import); int cnt = input.PageCount; for (int i = 0; i < cnt; i++) { output.AddPage(input.Pages[i]); } } if (Directory.Exists(path) != true) { Directory.CreateDirectory(path); } string fin = path + "\\" + batch + ".pdf"; output.Save(fin); SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(fin); if (f.PageCount > 0) { string fins = path + "\\" + batch + ".rtf"; f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf; f.ToWord(fins); } //stat.Text = "PDF combined succesfully into RTF"; //stat.Update(); return; } catch (Exception asd) { MessageBox.Show(asd.Message); return; } }
static void Main(string[] args) { string pathToPdf = @"..\..\Table.pdf"; string pathToExcel = "Result.xls"; // Convert PDF file to Excel file SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for registered version //f.Serial = "XXXXXXXXXXX"; // 'true' = Convert all data to spreadsheet (tabular and even textual). // 'false' = Skip textual data and convert only tabular (tables) data. f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true; // 'true' = Preserve original page layout. // 'false' = Place tables before text. f.ExcelOptions.PreservePageLayout = true; // The information includes the names for the culture, the writing system, // the calendar used, the sort order of strings, and formatting for dates and numbers. System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US"); ci.NumberFormat.NumberDecimalSeparator = ","; ci.NumberFormat.NumberGroupSeparator = "."; f.ExcelOptions.CultureInfo = ci; f.OpenPdf(pathToPdf); if (f.PageCount > 0) { int result = f.ToExcel(pathToExcel); //Open a produced Excel workbook if (result == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pathToExcel) { UseShellExecute = true }); } } }
private static void ConvertPdfBytesToHtml() { // We need files only for demonstration purposes. // The whole conversion process will be done in memory. string pdfFile = @"..\..\simple text.pdf"; string htmlFile = "Result.html"; // Convert PDF to HTML in memory SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for licensed version. //f.Serial = "XXXXXXXXXXX"; // Let's force the component to store images inside HTML document // using base-64 encoding. // Thus the component will not use HDD. f.HtmlOptions.IncludeImageInHtml = true; f.HtmlOptions.Title = "Simple text"; // Read a PDF document to byte array // Assume that we already have the PDF as array of bytes. byte[] pdf = File.ReadAllBytes(pdfFile); f.OpenPdf(pdf); if (f.PageCount > 0) { // Convert PDF to HTML in memory string html = f.ToHtml(); // Save HTML to the file only for demonstration purpose. if (html != null) { File.WriteAllText(htmlFile, html); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile) { UseShellExecute = true }); } } }
private String convertPDFtoJPG(string fileNameInp, string str) { string fileLocation = ""; string fileNameOut = str; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(@fileNameInp); if (f.PageCount > 0) { f.ImageOptions.Dpi = 300; f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; int len = openFileDialog1.SafeFileName.LastIndexOf("."); string fileName = openFileDialog1.SafeFileName.Substring(0, len); fileLocation = @fileNameOut + fileName + ".jpg"; f.ToImage(fileLocation, 1); } f.ClosePdf(); return(fileLocation); }
public void SaveFile() { saveFileDialog1.Filter = "docx files (*.docx)|*.docx"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { SavePath = saveFileDialog1.FileName; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(Path); if (f.PageCount > 0) { f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx; int result = f.ToWord(SavePath); if (result == 0) { System.Diagnostics.Process.Start(SavePath); } } MessageBox.Show("Conversion completed"); } }
private static void test4() { // Open document SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(System.IO.File.ReadAllBytes("template.pdf")); //this property is necessary only for registered version //f.Serial = "XXXXXXXXXXX"; if (f.PageCount > 0) { //set image properties f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; f.ImageOptions.Dpi = 300; //Let's convert 1st page from PDF document byte[] image = f.ToImage(1); f.ToImage("image2_out.jpg", 1); } }
static void Main(string[] args) { string[] files = GetFiles(args); foreach (var file in files) { if (Path.GetExtension(file).ToLower() == ".pdf") { string pdfFile = file; string wordFile = Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file) + ".docx"; SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(pdfFile); if (f.PageCount > 0) { f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx; int result = f.ToWord(wordFile); } } } }
static void Main(string[] args) { //Convert PDF file to Multipage TIFF file SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); //this property is necessary only for registered version //f.Serial = "XXXXXXXXXXX"; string pdfPath = @"..\..\..\..\..\simple text.pdf"; string tiffPath = Path.ChangeExtension(pdfPath, ".tiff"); f.OpenPdf(pdfPath); if (f.PageCount > 0) { f.ImageOptions.Dpi = 120; if (f.ToMultipageTiff(tiffPath) == 0) { System.Diagnostics.Process.Start(tiffPath); } } }
static void Main(string[] args) { string pathToPdf = @"..\..\Table.pdf"; string pathToExcel = "Result.xls"; // Here we have our PDF and Excel docs as byte arrays byte[] pdf = File.ReadAllBytes(pathToPdf); byte[] xls = null; // Convert PDF document to Excel workbook in memory SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for registered version //f.Serial = "XXXXXXXXXXX"; // The information includes the names for the culture, the writing system, // the calendar used, the sort order of strings, and formatting for dates and numbers. System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US"); ci.NumberFormat.NumberDecimalSeparator = ","; ci.NumberFormat.NumberGroupSeparator = "."; f.ExcelOptions.CultureInfo = ci; f.OpenPdf(pdf); if (f.PageCount > 0) { xls = f.ToExcel(); //Save Excel workbook to a file in order to show it if (xls != null) { File.WriteAllBytes(pathToExcel, xls); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pathToExcel) { UseShellExecute = true }); } } }
static void Main(string[] args) { // Convert PDF to JPG with high Quality SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for registered version // f.Serial = "XXXXXXXXXXX"; string pdfFile = @"..\..\..\..\..\simple text.pdf"; string jpegDir = Path.GetDirectoryName(pdfFile); f.OpenPdf(pdfFile); if (f.PageCount > 0) { // Set image properties: Jpeg, 200 dpi f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; f.ImageOptions.Dpi = 200; // Set 95 as JPEG quality f.ImageOptions.JpegQuality = 95; //Save all PDF pages to image folder, each file will have name Page 1.jpg, Page 2.jpg, Page N.jpg for (int page = 1; page <= f.PageCount; page++) { string jpegFile = Path.Combine(jpegDir, String.Format("Page {0}.jpg", page)); // 0 - converted successfully // 2 - can't create output file, check the output path // 3 - conversion failed int result = f.ToImage(jpegFile, page); // Show only 1st page if (page == 1 && result == 0) { System.Diagnostics.Process.Start(jpegFile); } } } }
static void Main(string[] args) { // Convert whole PDF document to separate Word documents. // Each PDF page will be converted to a single Word document. // Path to a PDF file. string pdfPath = Path.GetFullPath(@"..\..\simple text.pdf"); // Directory to store Word documents. string docxDir = Directory.GetCurrentDirectory(); SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.OpenPdf(pdfPath); // Convert each PDF page to separate Word document. // simple text - page 1.docx, simple text- page 2.docx ... simple text - page N.doc. for (int page = 1; page <= f.PageCount; page++) { // You may select between Docx and Rtf formats. f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx; byte [] docxBytes = f.ToWord(page, page); string tempName = Path.GetFileNameWithoutExtension(pdfPath) + String.Format(" - page {0}.docx", page); string docxPath = Path.Combine(docxDir, tempName); File.WriteAllBytes(docxPath, docxBytes); // Let's show first and last Word pages. if (page == 1 || page == f.PageCount) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxPath) { UseShellExecute = true }); } } }
static void Main(string[] args) { // Convert PDF to separate HTMLs. // Each PDF page will be converted to a single HTML document. // Path to PDF file. string pdfPath = Path.GetFullPath(@"..\..\..\..\..\simple text.pdf"); // Directory to store HTML documents. string htmlDir = Path.GetDirectoryName(pdfPath); SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); f.HtmlOptions.IncludeImageInHtml = false; // Path (must exist) to a directory to store images after converting. Notice also to the property "ImageSubFolder". f.HtmlOptions.ImageFolder = htmlDir; f.OpenPdf(pdfPath); // Convert each PDF page to separate HTML document. // simple text.html, simple text.html ... simple text.html. for (int page = 1; page <= f.PageCount; page++) { f.HtmlOptions.Title = String.Format("Simple Text - Page {0}", page); f.HtmlOptions.ImageSubFolder = String.Format("images-page{0}", page); string htmlString = f.ToHtml(page, page); // Save htmlString to file string htmlPath = Path.Combine(htmlDir, String.Format("Page{0}.html", page)); File.WriteAllText(htmlPath, htmlString); // Let's show first and last HTML pages. if (page == 1 || page == f.PageCount) { System.Diagnostics.Process.Start(htmlPath); } } }
public void ExtractXml(string sourcePdfPath , bool considerNonTabular) { //string pathToPdf = @"..\..\..\..\..\Page58.pdf"; string pathToXml = System.IO.Path.ChangeExtension(sourcePdfPath, ".xml"); // Convert PDF file to XML file. SautinSoft.PdfFocus f = new SautinSoft.PdfFocus(); // This property is necessary only for registered version. //f.Serial = "XXXXXXXXXXX"; // Let's convert only tables to XML and skip all textual data. f.XmlOptions.ConvertNonTabularDataToSpreadsheet = considerNonTabular; f.OpenPdf(sourcePdfPath); if (f.PageCount > 0) { int result = f.ToXml(pathToXml); //Show HTML document in browser //if (result == 0) //{ // System.Diagnostics.Process.Start(pathToXml); //} } }