public async Task <byte[]> GenerateDocumentAsync(Guid idTemplate, IDocumentGeneratorModel parameters) { return(await DocumentGeneratorHelper.TryCatchWithLogger(async() => { _logger.WriteDebug(new LogMessage($"Request PDF generation with idTemplate {idTemplate}"), LogCategories); if (idTemplate.Equals(Guid.Empty)) { throw new ArgumentException("Parameter idTemplate is empty", nameof(idTemplate)); } Guid?IdArchiveChain = _unitOfWork.Repository <TemplateDocumentRepository>().GetDocumentIdArchiveChainById(idTemplate); if (!IdArchiveChain.HasValue) { throw new DSWException($"Template '{idTemplate}' not found", null, DSWExceptionCode.Invalid); } ModelDocument.Document document = (await _documentService.GetDocumentLatestVersionFromChainAsync(IdArchiveChain.Value)).FirstOrDefault(); if (document == null) { throw new DSWException($"Document '{IdArchiveChain.Value}' not found", null, DSWExceptionCode.Invalid); } BuilderParameter builderParameter = new BuilderParameter(parameters.DocumentGeneratorParameters); byte[] content = await _documentService.GetDocumentContentAsync(document.IdDocument); return (await _pdfGeneratorClient.BuildPDFAsync(content, builderParameter.MappedParameters.ToArray(), string.Empty)).Body.BuildPDFResult; }, _logger, LogCategories)); }
public async Task <byte[]> GenerateDocumentAsync(Guid idTemplate, IDocumentGeneratorModel parameters, byte[] content = null) { return(await DocumentGeneratorHelper.TryCatchWithLogger(async() => { if (content == null) { content = await GetLatestVersionAsync(idTemplate); } WordGeneratorBuilder builder = new WordGeneratorBuilder(); return builder.GenerateWordDocument(content, parameters.DocumentGeneratorParameters); }, _logger, LogCategories)); }
public byte[] AppendTable(IDocumentGeneratorModel parameters, byte[] content) { using (MemoryStream stream = new MemoryStream()) { stream.Write(content, 0, content.Length); using (WordprocessingDocument doc = WordprocessingDocument.Open(stream, true)) { WordGeneratorBuilder builder = new WordGeneratorBuilder(); Table wordTable = builder.BuildWordTable(parameters.DocumentGeneratorParameters); if (wordTable != null) { doc.MainDocumentPart.Document.Body.Append(new Paragraph()); doc.MainDocumentPart.Document.Body.Append(wordTable); } } return(stream.ToArray()); } }
public byte[] AppendTable(IDocumentGeneratorModel source, byte[] content) { throw new NotImplementedException(); }
public Task <byte[]> GenerateDocumentAsync(Guid idTemplate, IDocumentGeneratorModel source, byte[] content = null) { throw new NotImplementedException(); }