Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vderyushev committed Jul 22, 2024
1 parent d91f9ac commit 3ef1127
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 29 deletions.
4 changes: 0 additions & 4 deletions Examples/ApiExamples/ApiExamples/ExBuildingBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public void CreateAndInsert()
BuildingBlockVisitor visitor = new BuildingBlockVisitor(glossaryDoc);
// Visit start/end of the BuildingBlock.
block.Accept(visitor);
// Visit only start of the BuildingBlock.
block.AcceptStart(visitor);
// Visit only end of the BuildingBlock.
block.AcceptEnd(visitor);

// We can access the block that we just made from the glossary document.
BuildingBlock customBlock = glossaryDoc.GetBuildingBlock(BuildingBlockGallery.QuickParts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void InsertImageFromByteArray()
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

byte[] imageByteArray = File.ReadAllBytes(ImageDir + "Logo.jpg");
byte[] imageByteArray = TestUtil.ImageToByteArray(ImageDir + "Logo.jpg");

// Below are three ways of inserting an image from a byte array.
// 1 - Inline shape with a default size based on the image's original dimensions:
Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public void DeleteHeaderFooterShapes()

// Create a primary footer with an image.
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.InsertImage(ImageDir + "Logo Icon.ico");
builder.InsertImage(ImageDir + "Logo icon.ico");

Assert.AreEqual(1, doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetChildNodes(NodeType.Shape, true).Count);
Assert.AreEqual(1, doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetChildNodes(NodeType.Shape, true).Count);
Expand Down
23 changes: 2 additions & 21 deletions Examples/ApiExamples/ApiExamples/ExSignDocumentCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,6 @@ private static void SignDocument(string srcDocumentPath, string dstDocumentPath,
DigitalSignatureUtil.Sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}

/// <summary>
/// Converts an image to a byte array.
/// </summary>
private static byte[] ImageToByteArray(string imagePath)
{
#if NET461_OR_GREATER || JAVA
Image image = Image.FromFile(imagePath);
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Png);
return ms.ToArray();
}
#elif NET5_0_OR_GREATER || __MOBILE__
return SkiaSharp.SKBitmap.Decode(imagePath).Bytes;
#endif
}

public class Signee
{
public Guid PersonId { get; set; }
Expand All @@ -124,10 +107,8 @@ private static void CreateSignees()

mSignees = new List<Signee>
{
new Signee(Guid.NewGuid(), "Ron Williams", "Chief Executive Officer",
ImageToByteArray(signImagePath)),
new Signee(Guid.NewGuid(), "Stephen Morse", "Head of Compliance",
ImageToByteArray(signImagePath))
new Signee(Guid.NewGuid(), "Ron Williams", "Chief Executive Officer", TestUtil.ImageToByteArray(signImagePath)),
new Signee(Guid.NewGuid(), "Stephen Morse", "Head of Compliance", TestUtil.ImageToByteArray(signImagePath))
};
}

Expand Down
7 changes: 5 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ private void ConvertWith(string separator, Table table)
[Test]
public void GetColSpanRowSpan()
{
Document doc = new Document(MyDir + "merged.docx");
Document doc = new Document(MyDir + "Table with merged cells.docx");

var table = (Table)doc.GetChild(NodeType.Table, 0, true);
// Convert cells with merged columns into a format that can be easily manipulated.
Expand Down Expand Up @@ -1865,8 +1865,11 @@ private int CalculateRowSpan(Table table, int rowIndex, int cellIndex)
for (int i = rowIndex; i < table.Rows.Count; i++)
{
var currentRow = table.Rows[i + 1];
if (currentRow == null)
break;

var currentCell = currentRow.Cells[cellIndex];
if (currentRow == null || currentCell.CellFormat.VerticalMerge != CellMerge.Previous)
if (currentCell.CellFormat.VerticalMerge != CellMerge.Previous)
break;

rowSpan++;
Expand Down
8 changes: 8 additions & 0 deletions Examples/ApiExamples/ApiExamples/TestUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,13 @@ internal static Encoding GetEncoding(string filename)
return streamReader.CurrentEncoding;
}
}

/// <summary>
/// Converts an image to a byte array.
/// </summary>
internal static byte[] ImageToByteArray(string imagePath)
{
return File.ReadAllBytes(imagePath);
}
}
}

0 comments on commit 3ef1127

Please sign in to comment.