Exemple #1
0
 public TextState GetFontState(Model.Font item)
 {
     Model.Font font = new Model.Font
     {
         Name  = GetValue(item?.Name, _defaultFont?.Name),
         Size  = GetValue(item?.Size, _defaultFont?.Size),
         Style = GetValue(item?.Style, _defaultFont?.Style)
     };
     return(new TextState(FontSize: font.Size, Font: font.Name, FontStyle: font.Style?.ToEnum(FontStyles.Regular) ?? FontStyles.Regular));
 }
Exemple #2
0
        public PdfReport(Dims dims, string filePath = null, string storageName         = null
                         , string templateFilePath  = null, string templateStorageName = null, bool debug = false)
        {
            _dims                   = dims;
            _defaultFont            = null;
            _debug                  = debug;
            _taskMeasurer           = new TaskMeasurer();
            _defaultDocumentOptions = new Model.DocumentOptions()
            {
                //GenerateQRCode = true
            };

            _templateFilePath    = templateFilePath;
            _templateStorageName = templateStorageName;

            _storageName = storageName;
            _filePath    = filePath;
            //
            if (!string.IsNullOrEmpty(_filePath))
            {
                var m = Regex.Match(_filePath, "^(.*)/([^/]*)$");
                if (m.Success)
                {
                    _folderName = m.Groups.Count > 1 ? m.Groups[1].Value : "";
                    _fileName   = m.Groups.Count > 2 ? m.Groups[2].Value : "";
                }
            }
            //_fileName = Path.GetFileName(_filePath);
            //_folderName = Path.GetDirectoryName(_filePath);

            if (string.IsNullOrEmpty(_folderName))
            {
                _folderName = null;
            }
            if (string.IsNullOrEmpty(_storageName))
            {
                _storageName = null;
            }

            _tmpFolderName = $"tmp_{FileName}";
            if (!string.IsNullOrEmpty(Folder))
            {
                _tmpFolderPath = $"{Folder}/{_tmpFolderName}";
            }
        }
Exemple #3
0
        /*
         * public async Task<bool> Configure(string apiKey, string appSid, string basePath = "")
         * {
         *  _pdfConfig = string.IsNullOrEmpty(basePath) ? new Configuration(apiKey, appSid) : new Configuration(apiKey, appSid, basePath);
         *  _pdfApi = new PdfApi(_pdfConfig);
         *
         *  _barcodeConfig = new Aspose.BarCode.Cloud.Sdk.Configuration();
         *  _barcodeConfig.DebugMode = _debug;
         *  _barcodeConfig.AppKey = apiKey;
         *  _barcodeConfig.AppSid = appSid;
         *  if (!string.IsNullOrEmpty(basePath))
         *      _barcodeConfig.ApiBaseUrl = basePath;
         *  _barcodeApi = new Aspose.BarCode.Cloud.Sdk.BarCodeApi(_barcodeConfig);
         *
         *  await _taskMeasurer.Run(async () =>
         *  {
         *      await CreateFolder("");
         *  }, "000_CreateClientFolder");
         *
         *  await _taskMeasurer.Run(async () =>
         *  {
         *      await CreateFolder(TmpFolderName);
         *  }, "000_CreateTemporaryFolder");
         *
         *  return true;
         * }
         */

        public async Task <bool> Report(Model.Document model)
        {
            _defaultFont     = model.DefaultFont;
            _documentOptions = model.Options;
            if (null == model?.Content || 0 == model?.Content?.Count)
            {
                throw new ArgumentException("No issues to export");
            }
            if (model?.Content?.Count == 1) // single issue
            {
                PdfReportPageProcessor processor = new PdfReportPageProcessor(this, FileName, Folder);
                await processor.PrepareDocument();

                await processor.Report(model.Content[0]);
            }
            else   // multiple issues
            {
                List <PdfReportPageProcessor> pageProcessors = model.Content.Select(i => new PdfReportPageProcessor(this, $"{Guid.NewGuid()}.pdf", TmpFolderPath)).ToList();
                await Task.WhenAll(pageProcessors.Select(async(p) =>
                {
                    await p.PrepareDocument();
                    await p.Report(model.Content[pageProcessors.IndexOf(p)]);
                }));

                await _taskMeasurer.Run(async() =>
                                        await _pdfApi.PutMergeDocumentsAsync(mergeDocuments: new MergeDocuments(pageProcessors.Select(p => $"{TmpFolderPath}/{p.FileName}").ToList())
                                                                             , name: FileName, storage: Storage, folder: Folder)
                                        , "990_MergeDocuments");
            }

            await _taskMeasurer.Run(async() =>
            {
                await RemoveFolder(TmpFolderName);
            }, "990_DeleteTemporaryFolder");

            return(true);
        }