I'm using E-iceblue control (Spire.Doc for NET3.5) to develop a SharePoint webpart which has 2 main functions: Import a Word file to HTML then show its content into a Wiki page (*.aspx), export a Wiki page to PDF. There are some problems happened in my process.
1. For importing Word to HTML
1.1. Don't show the shapes in Word file (see Shapeslosing.rar)
1.2. If the Word file has page numbers, the HTML file also contains page numbers after importing. How can I remove that page numbers out of the HTML?.
2. For exporting HTML to PDF
2.1. An error occurred after exporting: "A generic error occurred in GDI+.". This is happened with some Wiki page which has lots of tables and bullets format (attached file GDI_Error.png)
2.2. Losing pages after exporting Wiki page to PDF (see Pageslosing.rar). Steps of the conversion: save a wiki page (imported from Word) to HTML then convert that HTML to PDF.
2.3. Losing the link after exporting HTML to PDF (see LosingLink.png)
- Code: Select all
private void btnSave_Click(object sender, EventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
string tempPath = string.Format("{0}\\SPWiki\\Export", Path.GetTempPath());
WikiUtility.CreateFolderStoreHtmlContent(tempPath);
WikiUtility.SaveHtmlToLocalFile(itemUrl, tempPath, this.item.Name.Replace(".aspx", ".html"), currenSiteUrl);
string htmlFilePath = tempPath + "\\" + this.item.Name.Replace(".aspx", ".html");
this.document = new Document();
this.document.LoadFromFile(htmlFilePath, Spire.Doc.FileFormat.Html, XHTMLValidationType.None);
if (this.document != null)
{
GetConfigurationDoc();
using (Stream stream = new System.IO.MemoryStream())
{
document.SaveToStream(stream, Spire.Doc.FileFormat.PDF);
this.doc = new PdfDocument();
Thread thread1 = new Thread(() =>
{ this.doc.LoadFromStream(stream); });
thread1.SetApartmentState(ApartmentState.STA);
thread1.Start();
thread1.Join();
if (this.chkInsertCurrentDate.Checked || this.chkInsertPageNumber.Checked)
{
DrawPageNumber(this.doc.Pages, this.doc.PageSettings.Margins, 1, doc.Pages.Count);
}
doc.SaveToHttpResponse(this.item.Name.Replace(".aspx", ".pdf"), HttpContext.Current.Response, HttpReadType.Save);
}
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
}
});
}
catch (Exception ex)
{
this.DisplayErrors("btnSave_Click", ex);
}
}
Thank you in advance,
Lee K