Esempio n. 1
0
        /// <inheritdoc/>
        public async Task <IPDFtkResult <byte[]> > FillFormAsync(string pdfFilePath,
                                                                 IReadOnlyDictionary <string, string> fieldData,
                                                                 bool flatten,
                                                                 bool dropXfa)
        {
            using var outputFile = TempPDFtkFile.Create();
            using var xfdfFile   = await _xfdfGenerator.CreateXfdfFile(fieldData);

            var args = new List <string>(new[]
            {
                pdfFilePath,
                "fill_form",
                xfdfFile.TempFileName,
                "output",
                outputFile.TempFileName
            });

            if (flatten)
            {
                args.Add("flatten");
            }

            if (dropXfa)
            {
                args.Add("drop_xfa");
            }

            var executeProcessResult = await _pdftkProcess.ExecuteAsync(args.ToArray());

            return(await ResolveSingleFileExecutionResultAsync(executeProcessResult, outputFile));
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public async Task <IPDFtkResult <byte[]> > ConcatAsync(IEnumerable <string> filePaths)
        {
            using var outputFile = TempPDFtkFile.Create();

            var inputFileNames = string.Join(" ", filePaths);

            var executeProcessResult =
                await _pdftkProcess.ExecuteAsync(inputFileNames, "cat", "output", outputFile.TempFileName);

            return(await ResolveSingleFileExecutionResultAsync(executeProcessResult, outputFile));
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public async Task <IPDFtkResult <byte[]> > StampAsync(string pdfFilePath, string stampPdfFilePath)
        {
            using var outputFile = TempPDFtkFile.Create();


            var executeProcessResult = await _pdftkProcess.ExecuteAsync(pdfFilePath,
                                                                        "multistamp", stampPdfFilePath,
                                                                        "output", outputFile.TempFileName);

            return(await ResolveSingleFileExecutionResultAsync(executeProcessResult, outputFile));
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public async Task <IPDFtkResult <byte[]> > GetPagesAsync(string inputFile, params int[] pages)
        {
            using var outputFile = TempPDFtkFile.Create();

            var pageRanges = GetPageRangeArgs(pages);

            var executeProcessResult = await _pdftkProcess.ExecuteAsync(inputFile, "cat",
                                                                        string.Join(" ", pageRanges),
                                                                        "output", outputFile.TempFileName);

            return(await ResolveSingleFileExecutionResultAsync(executeProcessResult, outputFile));
        }
Esempio n. 5
0
        internal async Task <TempPDFtkFile> CreateXfdfFile(IReadOnlyDictionary <string, string> fieldData)
        {
            var inputFile = TempPDFtkFile.Create();

            var xmlWriterSettings = new XmlWriterSettings()
            {
                Async = true
            };

#if NETSTANDARD2_1 || NETSTANDARD2_0
            using var xmlWriter =
                      XmlWriter.Create(inputFile.TempFileName, xmlWriterSettings);
#else
            await using var xmlWriter =
                            XmlWriter.Create(inputFile.TempFileName, xmlWriterSettings);
#endif

            await WriteXmlDocument(xmlWriter, fieldData);

            await xmlWriter.FlushAsync();

            return(inputFile);
        }