public void CanConvertTemplateWithImages() { using var ms = new MemoryStream(Resources.convert_template_with_images_docx); var conversion = OpenXmlWordConverter.ConvertToHtml(ms, "T01_12345678"); Assert.NotNull(conversion); Assert.NotNull(conversion.Html); Assert.Equal(2, conversion.Images.Count); }
public void CanConvertSimpleReceiptContent() { using var ms = new MemoryStream(); ms.Write(Resources.simple_receipt_template_docx, 0, Resources.simple_receipt_template_docx.Length); var conversion = OpenXmlWordConverter.ConvertToHtml(ms, "DOC1"); Assert.NotNull(conversion); Assert.NotNull(conversion.Html); Assert.Contains("description1", conversion.Html); File.WriteAllText("./CanConvertSimpleReceiptContent.html", conversion.Html); }
public async Task <DocumentDetails> CreateDocument(string templateName, string mappingName, DocumentPayload payload) { var template = repository.GetLatestTemplate(templateName); Stream mappingBytes = null; if (mappingName != null) { var mapping = repository.GetLatestMapping(templateName, null, mappingName); mappingBytes = mapping.Buffer; } var documentBytes = CreateDocument(template.Buffer, mappingBytes, payload); var document = await repository.CreateDocument(templateName, mappingName, documentBytes); if (htmlRepository != null) { var pageTitle = template.Name; var conversion = OpenXmlWordConverter.ConvertToHtml(document.Buffer, pageTitle, document.Name); htmlRepository.SaveHtml(document.Name, conversion.Html, conversion.Images); } return(TransformFull(document)); }
public async Task <TemplateDetails> CreateTemplate(TemplateData templateData, Stream bytes) { templateData = templateData ?? throw new ArgumentNullException(nameof(templateData)); var templateName = templateData.TemplateName ?? throw new ArgumentNullException(nameof(templateData.TemplateName)); IEnumerable <TemplateField> fields; try { fields = OpenXmlWordProcessing.FindTemplateFields(bytes); } catch (FileFormatException) { throw new ArgumentException(nameof(bytes)); } var content = await repository.CreateTemplate(templateName, bytes); if (htmlRepository != null) { var conversion = OpenXmlWordConverter.ConvertToHtml(bytes, content.Name); htmlRepository.SaveHtml(content.Name, null, conversion.Images); } return(TransformFull(content, fields)); }