Hello there and thank you for your reply,
I was using version 8.3.15 of Spire.Doc.
After reading your reply, I downloaded latest version of Spire.Doc (Hot fix 9.4.1) and replaced it with the old one, and the problem was still there.
The target framework is
4, and programming language is
C#My PC configuration is:
OS: Win 10 x64 build number of 19041.928
CPU: Intel core-i7 7700k
Memory: 8 GB of DDR4 3200mh
and also need to mention that I'm saving the file on a Solid State Drive (which is faster than HDD).
The function I'm using to generate doc file is below:
- Code: Select all
private Document getEncodeFile()
{
if (txtLayerTo.Text == string.Empty)
{
txtLayerTo.Invoke((MethodInvoker)delegate
{
txtLayerTo.Text = ourMap.Height.ToString();
});
}
if (txtLayerFrom.Text == string.Empty)
{
txtLayerFrom.Invoke((MethodInvoker)delegate
{
txtLayerFrom.Text = "1";
});
}
string newLine = Environment.NewLine;
Document docNodes = new Document();
Section sec = docNodes.AddSection();
sec.PageSetup.PageSize = PageSize.A4;
sec.PageSetup.Orientation = PageOrientation.Portrait;
sec.PageSetup.Margins.Top = 36;
sec.PageSetup.Margins.Right = 36;
sec.PageSetup.Margins.Bottom = 36;
sec.PageSetup.Margins.Left = 36;
sec.PageSetup.HeaderDistance = sec.PageSetup.FooterDistance = 14f;
sec.PageSetup.ColumnsLineBetween = true;
if (radioEncodeCol2.Checked)
{
sec.AddColumn(100f, 20f);
sec.AddColumn(100f, 20f);
}
else if (radioEncodeCol3.Checked)
{
sec.AddColumn(100f, 20f);
sec.AddColumn(100f, 20f);
sec.AddColumn(100f, 20f);
}
if (chekbxEncodeFooter.Checked)
{
ParagraphStyle footerStyle = new ParagraphStyle(docNodes);
footerStyle.Name = "footerStyle";
footerStyle.CharacterFormat.Font = new Font("Times", 12, FontStyle.Bold);
footerStyle.CharacterFormat.FontSize = 12;
footerStyle.CharacterFormat.FontSizeBidi = 12;
footerStyle.CharacterFormat.Bidi = true;
footerStyle.ParagraphFormat.IsBidi = true;
docNodes.Styles.Add(footerStyle);
HeaderFooter footer = sec.HeadersFooters.Footer;
Table footerTbl = footer.AddTable();
footerTbl.ResetCells(1, 2);
footerTbl.TableFormat.CellSpacing = 0;
footerTbl.TableFormat.Paddings.All = 0;
footerTbl.TableFormat.HorizontalAlignment = RowAlignment.Center;
footerTbl.TableFormat.LayoutType = LayoutType.AutoFit;
footerTbl.AutoFit(AutoFitBehaviorType.AutoFitToWindow);
footerTbl.Rows[0].Cells[0].Width = 60f;
if (chekbxEncodePageNumber.Checked)
{
Paragraph pageNumber = footerTbl.Rows[0].Cells[0].AddParagraph();
pageNumber.AppendField("page number", FieldType.FieldPage);
pageNumber.AppendText("Page ");
pageNumber.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
pageNumber.ApplyStyle(footerStyle.Name);
}
if (chekbxEncodeDetails.Checked)
{
Paragraph modelDetails = footerTbl.Rows[0].Cells[1].AddParagraph();
if (txtMapName.Text.Replace(" ", "") != string.Empty)
{
modelDetails.AppendText("Map name: " + txtModelName.Text + " ");
}
modelDetails.ApplyStyle(footerStyle.Name);
}
}
ParagraphStyle nodesStyle = new ParagraphStyle(docNodes);
nodesStyle.Name = "nodesStyle";
nodesStyle.CharacterFormat.Font = new Font("Times", 12, FontStyle.Bold);
nodesStyle.CharacterFormat.FontSize = 12;
nodesStyle.CharacterFormat.FontSizeBidi = 12;
nodesStyle.ParagraphFormat.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Justify;
docNodes.Styles.Add(nodesStyle);
ParagraphStyle nodeCountStyle = new ParagraphStyle(docNodes);
nodeCountStyle.Name = "nodeCountStyle";
nodeCountStyle.CharacterFormat.Font = new Font("Times", 10, FontStyle.Regular);
nodeCountStyle.CharacterFormat.FontSize = 10;
nodeCountStyle.CharacterFormat.FontSizeBidi = 10;
nodeCountStyle.ParagraphFormat.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
docNodes.Styles.Add(nodeCountStyle);
ParagraphStyle gapStyle = new ParagraphStyle(docNodes);
gapStyle.Name = "gapStyle";
gapStyle.CharacterFormat.FontSize = 6;
gapStyle.CharacterFormat.FontSizeBidi = 6;
docNodes.Styles.Add(gapStyle);
for (int i = int.Parse(txtLayerFrom.Text) - 1; i < int.Parse(txtLayerTo.Text); i++)
{
Paragraph nodesParaghraph = sec.AddParagraph();
nodesParaghraph.AppendText("Layer " + (i + 1).ToString());
nodesParaghraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
nodesParaghraph.Format.BackColor = Color.FromArgb(192, 192, 192);
nodesParaghraph.Format.IsBidi = true;
nodesParaghraph.ApplyStyle(nodesStyle.Name);
Table tbl = sec.AddTable();
tbl.ResetCells(1, 3);
tbl.TableFormat.LayoutType = LayoutType.AutoFit;
tbl.AutoFit(AutoFitBehaviorType.AutoFitToContents);
tbl.TableFormat.Paddings.Left = 3;
tbl.TableFormat.Paddings.Right = 3;
tbl.LastRow.Cells[0].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.Single;
tbl.LastRow.Cells[1].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.Single;
tbl.LastRow.Cells[2].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.Single;
for (int j = 0; j < layerNodes[i].Count; j++)
{
if (layerNodes[i][j].Count > 0)
{
nodesParaghraph = tbl.LastRow.Cells[0].AddParagraph();
nodesParaghraph.AppendText((j + 1).ToString() + ":");
nodesParaghraph.ApplyStyle(nodesStyle.Name);
nodesParaghraph = tbl.LastRow.Cells[1].AddParagraph();
nodesParaghraph.AppendText(layerNodes[i][j].Count.ToString());
nodesParaghraph.Format.LineSpacingRule = LineSpacingRule.Exactly;
nodesParaghraph.Format.LineSpacing = 12;
nodesParaghraph.ApplyStyle(nodeCountStyle.Name);
nodesParaghraph = tbl.LastRow.Cells[1].AddParagraph();
nodesParaghraph.AppendText("nodes");
nodesParaghraph.Format.LineSpacing = 6f;
nodesParaghraph.ApplyStyle(nodeCountStyle.Name);
string nodes = (layerNodes[i][j][0] + 1).ToString();
string space = " ";
nodesParaghraph = tbl.LastRow.Cells[2].AddParagraph();
if (layerNodes[i][j].Count < 3)
{
for (int k = 1; k < layerNodes[i][j].Count; k++)
{
nodes += space + (layerNodes[i][j][k] + 1);
}
}
else
{
for (int k = 1; k < layerNodes[i][j].Count - 1; k++)
{
if (layerNodes[i][j][k] == (layerNodes[i][j][k - 1] + 1) && layerNodes[i][j][k] == (layerNodes[i][j][k + 1] - 1))
space = "-";
else
{
nodes += space + (layerNodes[i][j][k] + 1);
space = " ";
}
}
nodes += space + (layerNodes[i][j][layerNodes[i][j].Count - 1] + 1);
}
nodesParaghraph.AppendText(nodes);
nodesParaghraph.ApplyStyle(nodesStyle.Name);
tbl.AddRow();
}
}
tbl.Rows.Remove(tbl.LastRow);
tbl.LastRow.Cells[0].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None;
tbl.LastRow.Cells[1].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None;
tbl.LastRow.Cells[2].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None;
if (!chekbxEncodeContinuous.Checked)
{
nodesParaghraph.AppendBreak(BreakType.PageBreak);
}
else
{
nodesParaghraph = sec.AddParagraph();
nodesParaghraph.ApplyStyle(gapStyle.Name);
}
progressBar1.Invoke((MethodInvoker)delegate
{
progressBar1.Value++;
});
}
return docNodes;
}
Since your website doesn't allow attaching of files with more than 2MB of size, I've uploaded output file to my server and here is the download link:
» jalali.dev/spire_doc/map%20EA67-b.zip
Need to mention that for the file I'm sending to you I've tried to decrease font size and spacing between lines and etc, therefore page count
decreased to 1223,
but still it takes around
30 seconds to save the file.
And as I mentioned before, the
time required for saving increases dramatically when page count reaches around 2000.
Extra info:
It takes
24-25 seconds to calculate and prepare docNodes variable for saving (plus saving time, it takes 55-60 seconds in total),
and while saving, usage of RAM increases to a cap of
2.7GB for this specific image.
Again, thank you a lot for your attention and helping me on solving this problem.