Could you please check this code ??? I am calling the overlapIssue() method in my main method (Convert()). I think my method calling is wrong. because when I call the method (OverlapIssue(document);), I think I should pass the saved word document. Could you please help me to do that? How can I pass the saved word document to the method (OverlapIssue(document);??? I am not allowed to get the document from the machine. Do you have another way to get saved document???
///Main Method
public List<byte[]> Convert(ContentsDto content, IDictionary<string,string> options, System.Func<DependentContent, Task<ContentsDto>> GetDependency=null)
{
License htmlLicense1 = new License();
htmlLicense1.SetLicense("Aspose.Words.NET.lic");
HtmlDocument htmlDocument = new HtmlDocument();
using (var htmlStream = new MemoryStream(content.Data))
{
htmlDocument.Load(htmlStream);
}
var byteArray = new List<byte[]>();
using (var dataStream = new MemoryStream(content.Data))
{
HtmlLoadOptions docOptions = new HtmlLoadOptions();
docOptions.ResourceLoadingCallback = new AsposeWordsAuthHandler(_settingsProvider, _authSettings, _logger);
var document = new Aspose.Words.Document(dataStream, docOptions);
using (var outputStream = new MemoryStream())
{
document.Save(outputStream, SaveFormat.Docx);
//in here i am calling your method.
OverlapIssue(document);
byteArray.Add(outputStream.ToArray());
}
}
return byteArray;
}
//Method , which adjust the overlap issue
private static void OverlapIssue(Document doc)
{
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape s in shapes)
{
// LayoutCollector and LayoutEnumerator do not work with nodes in header and footer.
// Skip them.
if (s.GetAncestor(NodeType.HeaderFooter) != null)
continue;
PageSetup ps = ((Section)s.GetAncestor(NodeType.Section)).PageSetup;
// Rectangle inside page margin.
double top = ps.TopMargin + ps.HeaderDistance;
double bottom = ps.BottomMargin + ps.FooterDistance;
float width = (float)(ps.PageWidth - ps.LeftMargin - ps.RightMargin);
float height = (float)(ps.PageHeight - top - bottom);
RectangleF rect = new RectangleF((float)ps.LeftMargin, (float)top, width, height);
// Get shape rectangle on the page.
enumerator.Current = collector.GetEntity(s);
RectangleF shapeRect = enumerator.Rectangle;
// Update shape position to place it inside page margins.
if (shapeRect.Left < rect.Left)
s.Left += (rect.Left - shapeRect.Left);
if (shapeRect.Right > rect.Right)
s.Left -= (shapeRect.Right - rect.Right);
if (shapeRect.Top < rect.Top)
s.Top += (rect.Top - shapeRect.Top);
if (shapeRect.Bottom > rect.Bottom)
s.Top -= (shapeRect.Bottom - rect.Bottom);
}
}