private void pdf_to_word(save_progress progress, System.Windows.Forms.Form dlg, string fileType) { Aspose.Pdf.Document document = null; int num = 0; if (fileType == ".pdf") { document = this.pdf_doc; num = 0; } else if ((fileType == ".ppt") || (fileType == ".pptx")) { document = this.ppt_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".xls") || (fileType == ".xlsx")) { document = this.xls_to_pdf(progress, dlg, 0); num = 50; } Aspose.Words.Document document2 = new Aspose.Words.Document(); Aspose.Pdf.Document document3 = new Aspose.Pdf.Document(); if (progress != null) { dlg.Invoke(progress, new object[] { num }); } document2.ChildNodes.Clear(); for (int i = 1; i <= document.Pages.Count; i++) { try { MemoryStream outputStream = new MemoryStream(); document3.Pages.Add(document.Pages[i]); document3.Save(outputStream, Aspose.Pdf.SaveFormat.Doc); document2.AppendDocument(new Aspose.Words.Document(outputStream), ImportFormatMode.KeepSourceFormatting); document3.Pages.Delete(); } catch (Exception) { break; } if (progress != null) { if (num == 50) { dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 }); } else { dlg.Invoke(progress, new object[] { (i * 100) / this.pdf_doc.Pages.Count }); } } } document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix()); if (progress != null) { dlg.Invoke(progress, new object[] { 100 }); } }
private void pdf_to_excel(save_progress progress, System.Windows.Forms.Form dlg, string fileType) { Aspose.Pdf.Document document = null; int num = 0; try { if (fileType == ".pdf") { document = this.pdf_doc; num = 0; } else if ((fileType == ".ppt") || (fileType == ".pptx")) { document = this.ppt_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".doc") || (fileType == ".docx")) { document = this.doc_to_pdf(progress, dlg, 0); num = 50; } Workbook workbook = new Workbook(); Aspose.Pdf.Document document2 = new Aspose.Pdf.Document(); if (progress != null) { dlg.Invoke(progress, new object[] { num }); } workbook.Worksheets.Clear(); for (int i = 1; i <= document.Pages.Count; i++) { MemoryStream outputStream = new MemoryStream(); document2.Pages.Add(document.Pages[i]); document2.Save(outputStream, Aspose.Pdf.SaveFormat.Excel); Workbook workbook2 = new Workbook(outputStream); workbook.Worksheets.Add(i.ToString()); workbook.Worksheets[i - 1].Copy(workbook2.Worksheets[0]); document2.Pages.Delete(); if (progress != null) { if (num == 50) { dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 }); } else { dlg.Invoke(progress, new object[] { (i * 100) / this.pdf_doc.Pages.Count }); } } } workbook.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".xls"); } catch (Exception) { } }
private Aspose.Pdf.Document xls_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select) { int num = 50; if (lst_select >= 7) { num = 100; } Aspose.Pdf.Document document = null; try { Workbook workbook = new Workbook(); if (progress != null) { dlg.Invoke(progress, new object[] { 0 }); } workbook.Worksheets.Clear(); if (this.excel_doc == null) { return(document); } document = new Aspose.Pdf.Document(); for (int i = 0; i < this.excel_doc.Worksheets.Count; i++) { MemoryStream stream = new MemoryStream(); workbook.Worksheets.Add(i.ToString()); workbook.Worksheets[0].Copy(this.excel_doc.Worksheets[i]); workbook.Save(stream, Aspose.Cells.SaveFormat.Pdf); document.Pages.Add(new Aspose.Pdf.Document(stream).Pages); workbook.Worksheets.RemoveAt(0); if (progress != null) { dlg.Invoke(progress, new object[] { (i * num) / this.excel_doc.Worksheets.Count }); } } if (lst_select >= 7) { document.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".pdf"); } if (progress != null) { dlg.Invoke(progress, new object[] { num }); } } catch (Exception) { return(null); } return(document); }
private Aspose.Pdf.Document ppt_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select) { int num = 50; if (lst_select >= 7) { num = 100; } Presentation presentation = new Presentation(); Aspose.Pdf.Document document = new Aspose.Pdf.Document(); try { presentation.Slides.RemoveAt(0); if (progress != null) { dlg.Invoke(progress, new object[] { 0 }); } if (this.ppt_doc == null) { return(null); } for (int i = 0; i < this.ppt_doc.Slides.Count; i++) { MemoryStream stream = new MemoryStream(); presentation.Slides.AddClone(this.ppt_doc.Slides[i]); presentation.Save(stream, Aspose.Slides.Export.SaveFormat.Pdf); presentation.Slides.RemoveAt(0); document.Pages.Add(new Aspose.Pdf.Document(stream).Pages); if (progress != null) { dlg.Invoke(progress, new object[] { (i * num) / this.ppt_doc.Slides.Count }); } } if (lst_select >= 7) { document.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".pdf"); } if (progress != null) { dlg.Invoke(progress, new object[] { num }); } } catch (Exception) { return(null); } return(document); }
private Aspose.Pdf.Document doc_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select) { int num = 50; if (lst_select == 7) { num = 100; } Aspose.Pdf.Document document2 = new Aspose.Pdf.Document(); try { document2.Pages.Delete(); if (progress != null) { dlg.Invoke(progress, new object[] { 0 }); } if (this.word_doc == null) { return(null); } for (int i = 0; i < this.word_doc.ChildNodes.Count; i++) { MemoryStream stream = new MemoryStream(); Aspose.Words.Document document = new Aspose.Words.Document(); document.ChildNodes.RemoveAt(0); document.AppendChild(document.ImportNode(this.word_doc.ChildNodes[i], true)); document.Save(stream, Aspose.Words.SaveFormat.Pdf); document2.Pages.Add(new Aspose.Pdf.Document(stream).Pages); if (progress != null) { dlg.Invoke(progress, new object[] { (i * num) / this.word_doc.ChildNodes.Count }); } } if (lst_select == 7) { document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix()); } if (progress != null) { dlg.Invoke(progress, new object[] { num }); } } catch (Exception) { return(null); } return(document2); }
public void save(save_progress progress, System.Windows.Forms.Form dlg, int c, string fileType, int lst_select) { if (this.file_can_work) { if (new reg().is_reg()) { if ((this.global_config.start_page > this.get_pages_count()) || (this.global_config.start_page <= 0)) { this.global_config.start_page = 1; } if ((this.global_config.end_page > this.get_pages_count()) || (this.global_config.end_page <= 0)) { this.global_config.end_page = this.get_pages_count(); } } else { if ((this.global_config.start_page > this.get_pages_count()) || (this.global_config.start_page <= 0)) { this.global_config.start_page = 1; } if ((this.global_config.end_page > this.get_pages_count()) || (this.global_config.end_page <= 0)) { this.global_config.end_page = this.get_pages_count(); } this.global_config.start_page = 1; if (this.global_config.end_page > 3) { this.global_config.end_page = 3; } } if ((this.global_config.start_page != 1) || (this.global_config.end_page != this.get_pages_count())) { int num2; int num = 1; int[] pages = new int[((this.global_config.start_page - 1) + this.get_pages_count()) - this.global_config.end_page]; for (num2 = 1; num2 <= (this.global_config.start_page - 1); num2++) { pages[num2 - 1] = num2; } num2 = this.global_config.start_page; while (num2 <= pages.Length) { pages[num2 - 1] = this.global_config.end_page + num; num2++; num++; } if (fileType == ".pdf") { this.pdf_doc.Pages.Delete(pages); } else if ((((fileType != ".ppt") && !(fileType == ".pptx")) && (ORIGIN_FORMAT.EXCEL != this.get_orgin_format())) && (ORIGIN_FORMAT.PPT == this.get_orgin_format())) { } } if (this.global_config.target_dic == "") { this.global_config.target_dic = this.get_path(this.file_path, false); } else if (this.global_config.target_dic.Substring(this.global_config.target_dic.Length - 1, 1) != @"\") { this.global_config.target_dic = this.global_config.target_dic + @"\"; } this.create_dic(); switch (this.target_format) { case FORMAT.PDF2WORD: this.pdf_to_word(progress, dlg, fileType); break; case FORMAT.PDF2EXCEL: this.pdf_to_excel(progress, dlg, fileType); break; case FORMAT.PDF2PPT: this.pdf_to_ppt(progress, dlg, fileType); break; case FORMAT.PDF2HTML: this.pdf_to_html(progress, dlg, fileType); break; case FORMAT.IMG2PDF: this.pdf_to_epub(progress, dlg, c); break; case FORMAT.PDF2IMG: this.pdf_to_img(progress, dlg, fileType); break; case FORMAT.PDF2TXT: this.pdf_to_txt(progress, dlg, fileType); break; case FORMAT.DOC2PDF: this.doc_to_pdf(progress, dlg, lst_select); break; case FORMAT.XLS2PDF: this.xls_to_pdf(progress, dlg, lst_select); break; case FORMAT.PPT2PDF: this.ppt_to_pdf(progress, dlg, lst_select); break; } } }
private void pdf_to_txt(save_progress progress, System.Windows.Forms.Form dlg, string fileType) { try { Aspose.Pdf.Document document = null; int num = 0; if (fileType == ".pdf") { document = this.pdf_doc; num = 0; } else if ((fileType == ".doc") || (fileType == ".docx")) { document = this.doc_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".xls") || (fileType == ".xlsx")) { document = this.xls_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".ppt") || (fileType == ".pptx")) { document = this.ppt_to_pdf(progress, dlg, 0); num = 50; } PdfExtractor extractor = new PdfExtractor(document); FileStream outputStream = new FileStream(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(), FileMode.Create); extractor.ExtractTextMode = 0; if (progress != null) { dlg.Invoke(progress, new object[] { num }); } for (int i = 1; i <= document.Pages.Count; i++) { extractor.StartPage = i; extractor.EndPage = i; extractor.ExtractText(Encoding.UTF8); extractor.GetText(outputStream); if (progress != null) { if (num == 50) { dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 }); } else { dlg.Invoke(progress, new object[] { (i * 100) / document.Pages.Count }); } } } outputStream.Close(); } catch (Exception) { return; } if (progress != null) { dlg.Invoke(progress, new object[] { 100 }); } }
private void pdf_to_ppt(save_progress progress, System.Windows.Forms.Form dlg, string fileType) { try { Aspose.Pdf.Document document = null; int num = 0; if (fileType == ".pdf") { document = this.pdf_doc; num = 0; } else if ((fileType == ".doc") || (fileType == ".docx")) { document = this.doc_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".xls") || (fileType == ".xlsx")) { document = this.xls_to_pdf(progress, dlg, 0); num = 50; } Presentation presentation = new Presentation(); JpegDevice device = new JpegDevice(new Resolution(300), 100); if (progress != null) { dlg.Invoke(progress, new object[] { num }); } int num3 = 0; for (int i = 1; num3 < document.Pages.Count; i++) { presentation.Slides.AddEmptySlide(presentation.LayoutSlides[0]); presentation.Slides[num3].Shapes.AddAutoShape(Aspose.Slides.ShapeType.Rectangle, 10f, 20f, (float)this.global_config.pic_width, (float)this.global_config.pic_height); int num2 = presentation.Slides[num3].Shapes.Count - 1; presentation.Slides[num3].Shapes[num2].FillFormat.FillType = FillType.Picture; presentation.Slides[num3].Shapes[num2].FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch; MemoryStream output = new MemoryStream(); device.Process(document.Pages[i], output); IPPImage image = presentation.Images.AddImage(new Bitmap(output)); presentation.Slides[num3].Shapes[num2].FillFormat.PictureFillFormat.Picture.Image = image; if (progress != null) { if (num == 50) { dlg.Invoke(progress, new object[] { ((num3 * 50) / document.Pages.Count) + 50 }); } else { dlg.Invoke(progress, new object[] { (num3 * 100) / document.Pages.Count }); } } num3++; } presentation.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(), Aspose.Slides.Export.SaveFormat.Ppt); } catch (Exception) { return; } if (progress != null) { dlg.Invoke(progress, new object[] { 100 }); } }
private void pdf_to_img(save_progress progress, System.Windows.Forms.Form dlg, string fileType) { try { Aspose.Pdf.Document document = null; int num = 0; if (fileType == ".pdf") { document = this.pdf_doc; num = 0; } else if ((fileType == ".doc") || (fileType == ".docx")) { document = this.doc_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".xls") || (fileType == ".xlsx")) { document = this.xls_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".ppt") || (fileType == ".pptx")) { document = this.ppt_to_pdf(progress, dlg, 0); num = 50; } if (document != null) { try { JpegDevice device = new JpegDevice(new Resolution(300), 100); if (progress != null) { dlg.Invoke(progress, new object[] { num }); } for (int i = 1; i <= document.Pages.Count; i++) { device.Process(document.Pages[i], this.global_config.target_dic + i.ToString() + this.get_suffix()); if (progress != null) { if (num == 50) { dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 }); } else { dlg.Invoke(progress, new object[] { (i * 100) / document.Pages.Count }); } } } } catch (Exception) { return; } if (progress != null) { dlg.Invoke(progress, new object[] { 100 }); } } } catch (Exception) { throw; } }
private void pdf_to_html(save_progress progress, System.Windows.Forms.Form dlg, string fileType) { int num = 0; if (fileType == ".pdf") { num = 0; } else if ((fileType == ".doc") || (fileType == ".docx")) { this.pdf_doc = this.doc_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".xls") || (fileType == ".xlsx")) { this.pdf_doc = this.xls_to_pdf(progress, dlg, 0); num = 50; } else if ((fileType == ".ppt") || (fileType == ".pptx")) { this.pdf_doc = this.ppt_to_pdf(progress, dlg, 0); num = 50; } new Thread(new ThreadStart(this.pdf_to_html_callback)).Start(); int num2 = 1; int num3 = num2; int count = this.pdf_doc.Pages.Count; if (progress != null) { dlg.Invoke(progress, new object[] { num }); } while (true) { bool flag2 = true; num3 = num2; try { if ((Directory.GetFiles(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + "_files").Length != 0) || (Directory.GetFiles(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + "_files", "img_" + num2.ToString().PadLeft(2, '0') + ".*").Length != 0)) { num2++; } } catch { } if (num2 == count) { if (progress != null) { try { bool flag = false; goto Label_028D; Label_0250: if (Directory.GetFiles(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + "_files", "style.css").Length != 0) { flag = true; goto Label_0292; } Label_028D: flag2 = true; goto Label_0250; Label_0292: if (flag) { dlg.Invoke(progress, new object[] { 100 }); } } catch (Exception) { } } return; } if (progress != null) { if (num == 50) { dlg.Invoke(progress, new object[] { ((num2 * 50) / count) + 50 }); } else { dlg.Invoke(progress, new object[] { (num2 * 100) / count }); } } Thread.Sleep(30); } }
private void pdf_to_epub(save_progress progress, System.Windows.Forms.Form dlg, int c) { try { Pdf pdf; ListViewItem item; string text; Aspose.Pdf.Generator.Section section; Aspose.Pdf.Generator.Image image; string str4; string extension; if (progress != null) { dlg.Invoke(progress, new object[] { 0 }); } string str = new ini_config("config.ini").read_ini("isMerger", "App"); ListView.ListViewItemCollection items = null; int num = 0; if (dlg.Name == "mainDlg") { items = ((mainDlg)dlg).lstFile.Items; num = 0; } else { items = ((mainDlg_A)dlg).lstFile.Items; num = 1; } if (str == "1") { if (c == (items.Count - 1)) { pdf = new Pdf(); for (int i = 0; i < items.Count; i++) { item = items[i]; text = item.SubItems[num].Text; section = pdf.Sections.Add(); image = new Aspose.Pdf.Generator.Image(section); section.Paragraphs.Add(image); image.ImageInfo.File = text; extension = Path.GetExtension(text); if (extension == null) { goto Label_01C8; } if (!(extension == ".jpg")) { if (extension == ".gif") { goto Label_0188; } if (extension == ".bmp") { goto Label_0198; } if (extension == ".png") { goto Label_01A8; } if (extension == ".tiff") { goto Label_01B8; } goto Label_01C8; } image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; continue; Label_0188: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Gif; continue; Label_0198: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; continue; Label_01A8: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png; continue; Label_01B8: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; continue; Label_01C8: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; } str4 = this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(); pdf.Save(str4); } goto Label_0366; } pdf = new Pdf(); item = items[c]; text = item.SubItems[num].Text; section = pdf.Sections.Add(); image = new Aspose.Pdf.Generator.Image(section); section.Paragraphs.Add(image); image.ImageInfo.File = text; extension = Path.GetExtension(text); if (extension == null) { goto Label_0329; } if (!(extension == ".jpg")) { if (extension == ".gif") { goto Label_02E9; } if (extension == ".bmp") { goto Label_02F9; } if (extension == ".png") { goto Label_0309; } if (extension == ".tiff") { goto Label_0319; } goto Label_0329; } image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; goto Label_0339; Label_02E9: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Gif; goto Label_0339; Label_02F9: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; goto Label_0339; Label_0309: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png; goto Label_0339; Label_0319: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; goto Label_0339; Label_0329: image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; Label_0339: str4 = this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(); pdf.Save(str4); Label_0366: if (progress != null) { dlg.Invoke(progress, new object[] { 100 }); } } catch (Exception) { } }