We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML to word换页问题

你好, 我在使用html 转word后,发现换页的地方把同一div里面的不同span放在不同页面,没有一个div作为整体换页。
SeparatedSpansFromASameDiv.png (24.2 KB)

示例html:sampleHtml.zip (8.0 KB)
代码:

 var options = new Aspose.Html.Saving.DocSaveOptions();
            options.Css.MediaType = Aspose.Html.Rendering.MediaType.Screen;
            options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromMillimeters(210), Aspose.Html.Drawing.Length.FromMillimeters(265)));
            options.DocumentFormat = Aspose.Html.Rendering.Doc.DocumentFormat.DOCX;
            options.FontEmbeddingRule = Aspose.Html.Rendering.Doc.FontEmbeddingRule.Full;

            var streamProvider = new InspectionFormPDF.InstructionFormDoc.MemoryStreamProvider();
            Aspose.Html.Converters.Converter.ConvertHTML(html, ".", options, streamProvider);
            streamProvider.Streams.First().Seek(0, System.IO.SeekOrigin.Begin);

            var doc = new Aspose.Words.Document(streamProvider.Streams.First());
            var builder = new DocumentBuilder(doc)
            {
                PageSetup =
                {
                    Orientation = Orientation.Portrait,
                    PaperSize = PaperSize.A4,
                },

            };
            var nodes = builder.Document.GetChildNodes(NodeType.Shape, true);
            foreach(var node in nodes)
            {
                var textBox = ((Aspose.Words.Drawing.Shape)node).TextBox;
                if(textBox != null)
                { 
                    textBox.FitShapeToText = true;
                }
            }

            MemoryStream stream = new MemoryStream();
            builder.Document.Save(stream, Aspose.Words.SaveFormat.Docx);
            stream.Position = 0;
            return await Task.FromResult(($"Instruction Form_{DateTime.Now.ToString("yyyyMMdd")}.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", stream));

@X.Bourne,

我们测试了这个场景,并设法在我们这边重现了同样的问题。 为了在 Aspose.Words API 中进行任何更正,我们已将这个问题记录在我们的问题跟踪系统中。 本期ID为WORDSNET-22703。 我们将进一步调查此问题的详细信息,并会在此处为您提供有关更正状态的最新信息。 对于给您带来的不便,我们深表歉意。