Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation - Fix document assembler images and other tidy up #84

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/images/word/documentassembler/image1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/word/documentassembler/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/word/documentassembler/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/word/documentassembler/image4.png
Binary file not shown.
67 changes: 57 additions & 10 deletions docs/tutorials/word/DocumentAssembler_ImagesSupport.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,74 @@ uid: Tutorial.Word.DocumentAssembler.ImagesSupport

# Key highlights from [#31](https://github.com/sergey-tihon/Clippit/pull/31#issuecomment-874335292)

1. Image can be provided either by base64-encoded string or by specifying the filename. The Assembler will have to figure out the image type, based on either MIME or file extension. Here are both examples:
## Introduction

- `<Logo>../../md-logo.png</Logo>`
- `<Image>data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcetc…</Image>`
The Image content control works by being placed directly before an image placeholder in your Word document. The image placeholder must be inline.

2. The image content control will be surrounded by new type of select (in similar to repeat or conditional) – `Image Select` and `EndImage`. I found this approach easier than dealing just with the image content control. Here is the example:
Images content can be provided in your XML data using a path to a file on disk, or by using the [data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme). Example of both approaches are shown below:

```xml
<Logo>../../md-logo.png</Logo>
```
```xml
<Image>data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcetc…</Image>
```

Document Assembler will either infer the MIME type based on the extension of the filename, or take use the MIME type passed in when using the data URI scheme.

Examples below show the Image content control in action and are taken from the Document Assembler Test Files:

## Image Select

![image1](../../images/word/documentassembler/image1.jpg)

3. When used in repeated context, the image is used with relative XPath (in similar to other fields):
## Image Select within a Repeat

Note that when using a Repeat XPATH is aware of the Context it is in and should operate on the "current" Node.

![image2](../../images/word/documentassembler/image2.png)

4. Very similar situation with the Table:
## Image Select within a Table

Works in a very similar way to Repeat.

![image3](../../images/word/documentassembler/image3.png)

5. Here is example of data xml file:
## XML Data used in above Examples

```xml
<?xml version="1.0" encoding="utf-8"?>
<Customer>
<CustomerID>1</CustomerID>
<Name>Cheryl</Name>
<HighValueCustomer>True</HighValueCustomer>
<CustomerLogo>../../../../TestFiles/img.png</CustomerLogo>
<Header>../../../../TestFiles/T0936_files/image001.png</Header>
<Orders>
<Order>
<ProductDescription>Unicycle</ProductDescription>
<Quantity>3</Quantity>
<OrderDate>9/5/2001</OrderDate>
<Thumbnail>../../../../TestFiles/img2.png</Thumbnail>
</Order>
<Order>
<ProductDescription>Tricycle</ProductDescription>
<Quantity>3</Quantity>
<OrderDate>8/6/2000</OrderDate>
<Thumbnail>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMcAAACTCAYA...</Thumbnail>
</Order>
</Orders>
<TotalQuantity>6</TotalQuantity>
<Description><![CDATA[This
is a multiline
description that
contains details about
Cheryl.]]></Description>
</Customer>
```

![image4](../../images/word/documentassembler/image4.png)
## Further Reading

6. There is still a lot to be improved and some issues to be resolved, such as using templated image in header/footer, managing image size (preserve original/modify based on template/maintain aspect ratio etc.)
If you are interested in using the Image functionality in DocumentAssembler then your best bet is to look at `DocumentAssemblerTests.cs` and particularly the data files which can be found in the repository under `Test Files/DA`.

7. Samples can be found in `DocumentAssemblerTests.cs` merged in [#31](https://github.com/sergey-tihon/Clippit/pull/31)
Changes merged in: [#31](https://github.com/sergey-tihon/Clippit/pull/31)
Loading