private void btn_Analiz_Click(object sender, EventArgs e) { if (durum == true) { if (tur == true) { //word dosyası olarak geliyor. Word2Pdf objWorPdf = new Word2Pdf(); string d_adi = dosya_yolu.Replace(dosya_adi, ""); string backfolder1 = @"" + d_adi.ToString() + ""; string strFileName = "" + dosya_adi.ToString() + ""; object FromLocation = backfolder1 + "\\" + strFileName; string FileExtension = Path.GetExtension(strFileName); string ChangeExtension = strFileName.Replace(FileExtension, ".pdf"); if (FileExtension == ".doc" || FileExtension == ".docx") { object ToLocation = backfolder1 + "\\" + ChangeExtension; objWorPdf.InputLocation = FromLocation; objWorPdf.OutputLocation = ToLocation; objWorPdf.Word2PdfCOnversion(); dosya_yolu = ToLocation.ToString(); } } else { //pdf dosyası olarak geliyor. } frmAnaliz analiz = new frmAnaliz(); this.Hide(); analiz.Show(); } }
/// <summary> /// Méthode qui permet de créer le PDF que nous enverons au client /// </summary> /// <param name="lc"></param> private void CreatePDF(LC lc) { Word2Pdf ObjetWord = new Word2Pdf(); string dossier = Program.FINACOOPFolder + Properties.Settings.Default.PathEnvoyer + modelManager.FindClient(lc.id_client).raison_sociale; if (!Directory.Exists(dossier)) { Directory.CreateDirectory(dossier); File.SetAttributes(dossier, FileAttributes.Normal); } string nomDuFichierAConvertir = lc.nom_lc; object CheminDuFichier = Program.FINACOOPFolder + lc.chemin_lc; string ExtensionDuFichier = Path.GetExtension(nomDuFichierAConvertir); string ExtensionCible = nomDuFichierAConvertir.Replace(ExtensionDuFichier, ".pdf"); if (ExtensionDuFichier == ".doc" || ExtensionDuFichier == ".docx") { object DossierCible = dossier + "\\" + ExtensionCible; ObjetWord.InputLocation = CheminDuFichier; ObjetWord.OutputLocation = DossierCible; ObjetWord.Word2PdfCOnversion(); } pathPDF = Properties.Settings.Default.PathEnvoyer + modelManager.FindClient(lc.id_client).raison_sociale + "\\" + ExtensionCible; // MessageBox.Show("Le PDF a était créer : " + pathPDF); }
private void ConfigureContract(ContractDetail detail) { detail.DateAcepted = DateTime.Now.Date; var valuesToFill = new Content( new FieldContent("contract_type", profileName), new FieldContent("contract_date", detail.DateAcepted.ToShortDateString()), new FieldContent("customer_name", detail.Customer.ToString()), new FieldContent("customer_dni", detail.Customer.Dni), new FieldContent("customer_address", detail.Customer.ComercialInfo.Address), new FieldContent("customer_city", detail.Customer.ComercialInfo.City.CityName), new FieldContent("customer_single_profile_name", singleProfileName), new FieldContent("customer_action", customerAction), new FieldContent("contract_percent", contract.ContractCommission.ToString("N2")), new FieldContent("additional_value", detail.AdditionalValue.ToString("N2")), new FieldContent("fine_value", detail.FineValue.ToString("N2")), new FieldContent("start_date", contract.StartDate.ToShortDateString()), new FieldContent("end_date", contract.EndDate.ToShortDateString()) ); using (var outputDocument = new TemplateProcessor(fileName).SetRemoveContentControls(true)){ outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); } var document = new Word2Pdf { InputLocation = fileName, OutputLocation = PdfFilePath }; document.Word2PdfCOnversion(); File.Delete(fileName); }
public async Task <string> ConvertAsync(Stream stream, string filename) { string destPath = fileLocation + "\\" + filename; using (var fileStream = new FileStream(destPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fileStream); } var word2Pdf = new Word2Pdf(); string extension = Path.GetExtension(filename); object file = fileLocation + "\\" + filename; string changeExtension = filename.Replace(extension, ".pdf"); if (File.Exists(fileLocation + "\\" + changeExtension)) { File.Delete(fileLocation + "\\" + changeExtension); } if (extension == ".doc" || extension == ".docx") { object saveLocation = fileLocation + "\\" + changeExtension; word2Pdf.InputLocation = file; word2Pdf.OutputLocation = saveLocation; word2Pdf.Word2PdfCOnversion(); } File.Delete(destPath); return(fileLocation + "\\" + changeExtension); }
public static void WordAPDF(string PathOrigen, string PathDestino, string strFileName) { var objWorPdf = new Word2Pdf(); object FromLocation = PathOrigen + strFileName; string FileExtension = Path.GetExtension(strFileName); string ChangeExtension = strFileName.Replace(FileExtension, ".pdf"); if (FileExtension == ".doc" || FileExtension == ".docx") { object ToLocation = PathDestino + ChangeExtension; objWorPdf.InputLocation = FromLocation; objWorPdf.OutputLocation = ToLocation; objWorPdf.Word2PdfCOnversion(); } }
private static void ConvertToPdfUsingWordToPdf(string source, string destination) { try { var word2Pdf = new Word2Pdf { InputLocation = source, OutputLocation = destination }; word2Pdf.Word2PdfCOnversion(); } catch (Exception ex) { FileLogger.SetLog(string.Format(ExceptionConstants.ConvertToPdf, source, ex.Message)); } }
static void Main(string[] args) { Word2Pdf ObjetWord = new Word2Pdf(); string dossier = "Z:\\projet tutore\\"; string nomDuFichierAConvertir = "cv.doc"; //ou docx object CheminDuFichier = dossier + "\\" + nomDuFichierAConvertir; string ExtensionDuFichier = Path.GetExtension(nomDuFichierAConvertir); string ExtensionCible = nomDuFichierAConvertir.Replace(ExtensionDuFichier, ".pdf"); if (ExtensionDuFichier == ".doc" || ExtensionDuFichier == ".docx") { object DossierCible = dossier + "\\" + ExtensionCible; ObjetWord.InputLocation = CheminDuFichier; ObjetWord.OutputLocation = DossierCible; ObjetWord.Word2PdfCOnversion(); } }
// POST: api/Convert_WordToPdf public string Post(WordToPdf value) { try { Dictionary <string, string> dicAppSet; general gn = new general(); dicAppSet = gn.ReadAppseting(); if (dicAppSet == null || dicAppSet.Count == 0) { return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}"); } var dicConfig = gn.ConfigConvertToDicConfig(value.config); if (dicConfig == null) { return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}"); } var pathFrom = dicConfig["fromfile"]; if (pathFrom.EndsWith(".doc") || pathFrom.EndsWith(".docx")) { var pathTo = pathFrom.Replace(".docx", ".pdf").Replace(".doc", ".pdf"); Word2Pdf objWorPdf = new Word2Pdf(); objWorPdf.InputLocation = pathFrom; objWorPdf.OutputLocation = pathTo; objWorPdf.Word2PdfCOnversion(); return("{\"result\":\"OK\",\"data\":\"" + pathTo + "\"}"); } else { return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}"); } } catch (Exception ex) { return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}"); } }
static void ConvertSingle(string source, string destination) { if (!string.IsNullOrWhiteSpace(source) && !string.IsNullOrWhiteSpace(destination)) { string pdfExtension = ".pdf"; var extension = Path.GetExtension(source); if (FileHelpers.IsValidWordFile(extension)) { var fileName = FileHelpers.GetFileName(source); var converter = new Word2Pdf() { InputLocation = source, OutputLocation = Path.Combine(destination, $"{fileName}{pdfExtension}") }; if (source == destination) { var sourceExtension = Path.GetExtension(source); converter.OutputLocation = source.Replace(sourceExtension, pdfExtension); } DisplayHelpers.Print("\nConverting File: " + fileName, Color.Yellow, ConsoleWriteMethod.WriteLine); try { var result = converter.Word2PdfCOnversion(); DisplayHelpers.Print("Done..", Color.DarkGreen, ConsoleWriteMethod.WriteLine); } catch (Exception ex) { DisplayHelpers.Print($"Something went wrong. Message: {ex.Message}.\n", Color.DarkRed, ConsoleWriteMethod.WriteLine); } } } }