Exemple #1
0
        public async Task <bool> SavePDF(List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Any())
            {
                string savePath;

                var pdfSettings = pdfSettingsContainer.PdfSettings;
                if (pdfSettings.SkipSavePrompt && Path.IsPathRooted(pdfSettings.DefaultFileName))
                {
                    savePath = pdfSettings.DefaultFileName;
                }
                else
                {
                    if (!dialogHelper.PromptToSavePdf(pdfSettings.DefaultFileName, out savePath))
                    {
                        return(false);
                    }
                }

                var subSavePath = fileNamePlaceholders.SubstitutePlaceholders(savePath, DateTime.Now);
                var changeToken = changeTracker.State;
                if (await ExportPDF(subSavePath, images, false, null))
                {
                    changeTracker.Saved(changeToken);
                    notify?.PdfSaved(subSavePath);
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        private bool SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify, ref string firstFileSaved)
        {
            if (images.Count == 0)
            {
                return(true);
            }
            var    form    = formFactory.Create <FProgress>();
            string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);

            if (settings.PromptForFilePath)
            {
                if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i);
                }
            }
            var extension = Path.GetExtension(subPath);

            if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(subPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
                }
                var op = operationFactory.Create <SavePdfOperation>();
                form.Operation = op;
                var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null;
                if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, false))
                {
                    form.ShowDialog();
                }
                if (op.Status.Success && firstFileSaved == null)
                {
                    firstFileSaved = subPath;
                }
                if (op.Status.Success)
                {
                    notify?.PdfSaved(subPath);
                }
                return(op.Status.Success);
            }
            else
            {
                var op = operationFactory.Create <SaveImagesOperation>();
                form.Operation = op;
                if (op.Start(subPath, now, images))
                {
                    form.ShowDialog();
                }
                if (op.Status.Success && firstFileSaved == null)
                {
                    firstFileSaved = op.FirstFileSaved;
                }
                if (op.Status.Success)
                {
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                }
                return(op.Status.Success);
            }
        }
        public async Task <bool> SavePdf(List <ScannedImage> images, ISaveNotify notify)
        {
            if (!images.Any())
            {
                return(false);
            }
            string savePath;

            var pdfSettings = pdfSettingsContainer.PdfSettings;

            if (pdfSettings.SkipSavePrompt && Path.IsPathRooted(pdfSettings.DefaultFileName))
            {
                savePath = pdfSettings.DefaultFileName;
            }
            else
            {
                if (!dialogHelper.PromptToSavePdf(pdfSettings.DefaultFileName, out savePath))
                {
                    return(false);
                }
            }

            var changeToken    = changeTracker.State;
            var firstFileSaved = await ExportPdf(savePath, images, false, null);

            if (firstFileSaved == null)
            {
                return(false);
            }
            changeTracker.Saved(changeToken);
            notify?.PdfSaved(firstFileSaved);
            return(true);
        }
Exemple #4
0
        private async Task <(bool, string)> SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Count == 0)
            {
                return(true, null);
            }
            string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);

            if (settings.PromptForFilePath)
            {
                if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i);
                }
                else
                {
                    return(false, null);
                }
            }
            var extension = Path.GetExtension(subPath);

            if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(subPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
                }
                var op = operationFactory.Create <SavePdfOperation>();
                if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrManager.DefaultParams, false, null))
                {
                    operationProgress.ShowProgress(op);
                }
                bool success = await op.Success;
                if (success)
                {
                    notify?.PdfSaved(subPath);
                }
                return(success, subPath);
            }
            else
            {
                var op = operationFactory.Create <SaveImagesOperation>();
                if (op.Start(subPath, now, images))
                {
                    operationProgress.ShowProgress(op);
                }
                bool success = await op.Success;
                if (success)
                {
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                }
                return(success, subPath);
            }
        }
        //TODO
        public bool AlfSavePDF(List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Any())
            {
                var savePath = NAPS2_Alfresco.utils.FileUtils.GetTempPath() + "\\" + DateTime.Now.ToFileTime() + ".pdf";
                if (ExportPDF(savePath, images, false))
                {
                    changeTracker.HasUnsavedChanges = false;

                    NAPS2_Alfresco.AlfResult alfResult = SessionUtils.UploadFile(savePath);
                    if (alfResult.status == NAPS2_Alfresco.AlfResult.STATUS_OK)
                    {
                        notify?.PdfSaved(savePath);
                        return(true);
                    }
                    else
                    {
                        MessageBox.Show(alfResult.message, "Error " + alfResult.status, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            return(false);
        }
Exemple #6
0
 private bool SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List<ScannedImage> images, ISaveNotify notify, ref string firstFileSaved)
 {
     if (images.Count == 0)
     {
         return true;
     }
     var form = formFactory.Create<FProgress>();
     var subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);
     var extension = Path.GetExtension(subPath);
     if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
     {
         if (File.Exists(subPath))
         {
             subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
         }
         var op = operationFactory.Create<SavePdfOperation>();
         form.Operation = op;
         var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null;
         if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, false))
         {
             form.ShowDialog();
         }
         if (op.Status.Success && firstFileSaved == null)
         {
             firstFileSaved = subPath;
         }
         if (op.Status.Success && notify != null)
         {
             notify.PdfSaved(subPath);
         }
         return op.Status.Success;
     }
     else
     {
         var op = operationFactory.Create<SaveImagesOperation>();
         form.Operation = op;
         if (op.Start(subPath, now, images))
         {
             form.ShowDialog();
         }
         if (op.Status.Success && firstFileSaved == null)
         {
             firstFileSaved = op.FirstFileSaved;
         }
         if (op.Status.Success && notify != null)
         {
             notify.ImagesSaved(images.Count, op.FirstFileSaved);
         }
         return op.Status.Success;
     }
 }