Exemplo n.º 1
0
        public IActionResult ProcessAllExcels()
        {
            var excels = dropBox.ListFolder(excelIn, false, true, ".xls");

            excelRepo.ClearAll();
            excels.ToList().ForEach(x => dropBox.Download(excelIn, x, excelRepo.DirPath, x));

            var orderedExcels = OrderUploadedExcelFiles(excels);

            return(Ok());
        }
Exemplo n.º 2
0
        public static void AggregateAndExport(DropBoxBase dropBoxClient, string outputLocalFile, string dropBoxOutputFolder, params string[] inputFilePaths)
        {
            Document document = new Document();
            //var stream = new FileStream(outputLocalFile, FileMode.Create);
            var writer = PdfWriter.GetInstance(document, new FileStream(outputLocalFile, FileMode.Create));

            var nrCadGeneral = "";// Path.GetFileNameWithoutExtension(outputLocalFile);

            //PdfCopy pdfCopy = new PdfCopy(document, new FileStream(outputLocalFile, FileMode.Create));
            document.Open();
            PdfContentByte pcb = writer.DirectContentUnder;

            for (var i = 0; i < inputFilePaths.Count(); i++)
            {
                CreateSourceDir(nrCadGeneral);

                var copied = dropBoxClient.Download(inputFilePaths[i], $"{sourceLocalDir}{nrCadGeneral}");

                if (!copied)
                {
                    continue;
                }

                var sourceFile = $"{sourceLocalDir}{nrCadGeneral}/{Path.GetFileName(inputFilePaths[i])}";

                var ext = Path.GetExtension(inputFilePaths[i]);

                switch (ext.ToLower())
                {
                case ".jpg":
                case ".jpeg":


                    var image = Image.GetInstance(sourceFile);

                    image.ScaleToFit(PageSize.A4);
                    image.SetAbsolutePosition(0, 0);

                    //pdfCopy.AddPage(PageSize.A4,0);
                    //pdfCopy.AddDirectImageSimple(image);

                    //pdfCopy.DirectContent.AddImage(image);

                    document.SetPageSize(PageSize.A4);
                    document.NewPage();
                    document.Add(image);



                    break;

                case ".pdf":

                    var reader = new PdfReader(sourceFile);
                    for (var p = 1; p <= reader.NumberOfPages; p++)
                    {
                        document.SetPageSize(reader.GetPageSizeWithRotation(p));
                        document.NewPage();
                        PdfImportedPage page = writer.GetImportedPage(reader, p);
                        pcb.AddTemplate(page, 0, 0);
                    }
                    ////pdfCopy.AddDocument(new PdfReader(sourceFile));
                    //reader.Close();

                    break;
                }

                DeleteSourceDir(nrCadGeneral);
            }

            document.Close();
            writer.Close();


            Task.Factory.StartNew(() => dropBoxClient.Upload(dropBoxOutputFolder, Path.GetFileName(inputFilePaths[0]), outputLocalFile));
        }