public static OperationsWorkflow CreatePDFReductionWorkflow(PDFReduceActionConfiguration reduceActionConfiguration)
        {
            List <Operation> actionsToBePerformed = new List <Operation>
            {
                new Operation(Operation.OperationType.LoadPDF, reduceActionConfiguration.OutputVersion),
                new Operation(Operation.OperationType.ReducePDF, reduceActionConfiguration)
            };

            return(new OperationsWorkflow(actionsToBePerformed, OperationsWorkflow.SaveOperationType.SavePDF));
        }
Exemplo n.º 2
0
        private PdfReduceResponse HandleReducePDF(PDFApi pdfApiInstance, PDFReduceActionConfiguration actionConfiguration, FileToProcess fileToProcess, string fileID, int workerNumber, List <string> warnings)
        {
            PdfReduceParameters reduceParameters = PassportPDFParametersUtilities.GetReduceParameters(actionConfiguration, fileID);
            PdfReduceResponse   reduceResponse   = PassportPDFRequestsUtilities.SendReduceRequest(pdfApiInstance, reduceParameters, workerNumber, fileToProcess.FileAbsolutePath, FileOperationStartEventHandler);

            if (reduceResponse.WarningsInfo != null)
            {
                foreach (ReduceWarningInfo warning in reduceResponse.WarningsInfo)
                {
                    warnings.Add(LogMessagesUtils.GetWarningStatustext(warning, fileToProcess.FileAbsolutePath));
                }
            }

            return(reduceResponse);
        }
Exemplo n.º 3
0
 public static void ParseCommandLineArgs(string[] args, ApplicationConfiguration applicationConfiguration, PDFReduceActionConfiguration reduceActionConfiguration = null, PDFOCRActionConfiguration ocrActionConfiguration = null, ImageSaveAsPDFMRCActionConfiguration imageSaveAsPdfMrcActionConfiguration = null, DocumentLoadAsPDFActionConfiguration loadAsPdfActionConfiguration = null)
 {
     for (int index = 0; index < args.Length; index++)
     {
         if (!ParseApplicationConfigurationArgument(args, index, applicationConfiguration))
         {
             if (reduceActionConfiguration != null)
             {
                 ParseReduceActionConfigurationArgument(args, index, reduceActionConfiguration);
             }
             if (ocrActionConfiguration != null)
             {
                 ParseOCRActionConfigurationArgument(args, index, ocrActionConfiguration);
             }
             if (imageSaveAsPdfMrcActionConfiguration != null)
             {
                 ParseSaveImageAsPdfMrcConfigurationArgument(args, index, imageSaveAsPdfMrcActionConfiguration);
             }
             if (loadAsPdfActionConfiguration != null)
             {
                 ParseDocumentLoadAsPdfConfigurationArgument(args, index, loadAsPdfActionConfiguration);
             }
         }
     }
 }
Exemplo n.º 4
0
        private WorkflowProcessingResult ProcessWorkflow(PDFApi pdfApiInstance, ImageApi imageApiInstance, OperationsWorkflow workflow, FileToProcess fileToProcess, int workerNumber)
        {
            List <string> warningMessages = new List <string>();
            bool          contentRemoved  = false;
            bool          versionChanged  = false;
            bool          linearized      = false;
            string        fileID          = null;

            foreach (Operation operation in workflow.OperationsToBePerformed)
            {
                Error           actionError     = null;
                ReduceErrorInfo reduceErrorInfo = null;
                long            remainingTokens = 0;

                if (_cancellationPending)
                {
                    return(null);
                }

                switch (operation.Type)
                {
                case Operation.OperationType.LoadPDF:
                    PdfVersion outputVersion = (PdfVersion)operation.Parameters;
                    PdfLoadDocumentResponse loadDocumentResponse = HandleLoadPDF(pdfApiInstance, outputVersion, fileToProcess, workerNumber);
                    if (loadDocumentResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "Load"));
                        return(null);
                    }
                    remainingTokens = loadDocumentResponse.RemainingTokens;
                    actionError     = loadDocumentResponse.Error;
                    fileID          = loadDocumentResponse.FileId;
                    break;

                case Operation.OperationType.LoadImage:
                    ImageLoadResponse imageLoadResponse = HandleLoadImage(imageApiInstance, fileToProcess, workerNumber);
                    if (imageLoadResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "Load"));
                        return(null);
                    }
                    remainingTokens = imageLoadResponse.RemainingTokens;
                    actionError     = imageLoadResponse.Error;
                    fileID          = imageLoadResponse.FileId;
                    break;

                case Operation.OperationType.ReducePDF:
                    PDFReduceActionConfiguration reduceActionConfiguration = (PDFReduceActionConfiguration)operation.Parameters;
                    PdfReduceResponse            reduceResponse            = HandleReducePDF(pdfApiInstance, reduceActionConfiguration, fileToProcess, fileID, workerNumber, warningMessages);
                    if (reduceResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "Reduce"));
                        return(null);
                    }
                    remainingTokens = reduceResponse.RemainingTokens;
                    contentRemoved  = reduceResponse.ContentRemoved;
                    versionChanged  = reduceResponse.VersionChanged;
                    actionError     = reduceResponse.Error;
                    reduceErrorInfo = reduceResponse.ErrorInfo;
                    linearized      = reduceActionConfiguration.FastWebView;
                    break;

                case Operation.OperationType.OCRPDF:
                    PDFOCRActionConfiguration ocrActionConfiguration = (PDFOCRActionConfiguration)operation.Parameters;
                    PdfOCRResponse            ocrResponse            = HandleOCRPDF(pdfApiInstance, ocrActionConfiguration, fileToProcess, fileID, workerNumber);
                    if (ocrResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "OCR"));
                        return(null);
                    }
                    remainingTokens = ocrResponse.RemainingTokens;
                    actionError     = ocrResponse.Error;
                    break;
                }

                if (actionError != null)
                {
                    string errorMessage = reduceErrorInfo != null && reduceErrorInfo.ErrorCode != ReduceErrorCode.OK ? ErrorManager.GetMessageFromReduceActionError(reduceErrorInfo, fileToProcess.FileAbsolutePath) : ErrorManager.GetMessageFromPassportPDFError(actionError, operation.Type, fileToProcess.FileAbsolutePath);
                    OnError(errorMessage);
                    return(null);
                }
                else
                {
                    RemainingTokensUpdateEventHandler.Invoke(remainingTokens);
                }
            }


            return(new WorkflowProcessingResult(contentRemoved, versionChanged, linearized, fileID, warningMessages));
        }
Exemplo n.º 5
0
        private static void ParseReduceActionConfigurationArgument(string[] args, int index, PDFReduceActionConfiguration reduceActionConfiguration)
        {
            switch (args[index].ToString())
            {
            case "/DC":     //disable the "color detection" option
                reduceActionConfiguration.EnableColorDetection = false;
                break;

            case "/CR":     //enable the "automatic char repair" option
                reduceActionConfiguration.EnableCharRepair = true;
                break;

            case "/DR":     //disable the "recompress images" option
                reduceActionConfiguration.RecompressImages = false;
                break;

            case "/DU":     //disable the "discard unused objects" option
                reduceActionConfiguration.PackDocument = false;
                break;

            case "/DD":     //disable the "downscale images" option
                reduceActionConfiguration.DownscaleImages = false;
                break;

            case "/Q":     //image quality
                if (args.Length > index + 1)
                {
                    int quality;
                    if (int.TryParse(args[index + 1], out quality))
                    {
                        if (quality >= (int)ImageQuality.ImageQualityLow && quality <= (int)ImageQuality.ImageQualityVeryHigh)
                        {
                            reduceActionConfiguration.ImageQuality = (ImageQuality)quality;
                        }
                    }
                }
                break;

            case "/R":     //downscale resolution
                if (args.Length > index + 1)
                {
                    int resolution;
                    if (int.TryParse(args[index + 1], out resolution))
                    {
                        if (resolution > 0)
                        {
                            reduceActionConfiguration.DownscaleResolution = resolution;
                        }
                    }
                }
                break;

            case "/DJ2K":     //disable the "JPEG 2000 compression" option
                reduceActionConfiguration.EnableJPEG2000 = false;
                break;

            case "/DJ2":     //disable the "JBIG2 compression" option:
                reduceActionConfiguration.EnableJBIG2 = false;
                break;

            case "/RF":     //remove formfields
                reduceActionConfiguration.RemoveFormFields = true;
                break;

            case "/RA":     //remove annotations
                reduceActionConfiguration.RemoveAnnotations = true;
                break;

            case "/RH":     //remove hyperlinks
                reduceActionConfiguration.RemoveHyperlinks = true;
                break;

            case "/RB":     //remove bookmarks
                reduceActionConfiguration.RemoveBookmarks = true;
                break;

            case "/RBP":     //remove blank pages
                reduceActionConfiguration.RemoveBlankPages = true;
                break;

            case "/RE":     //remove embedded files
                reduceActionConfiguration.RemoveEmbeddedFiles = true;
                break;

            case "/RJ":     // remove JavaScript
                reduceActionConfiguration.RemoveJavaScript = true;
                break;

            case "/LINEARIZED":     //enable fast web view
                reduceActionConfiguration.FastWebView = true;
                break;

            case "/MRC":     //enable MRC
                reduceActionConfiguration.EnableMRC = true;
                break;
            }
        }