Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jun 01, 2016 11:22 am

Hi,

I am trying to load word template that has keywords to replace.
I replace this keywords and after this I save this word doc to MemoryStream and return it with FileResult in Asp.net MVC.

Problem that I countered is that if word document is in portrate mode it has no problem bu in landscape mode it loses all margins

here is my code

Code: Select all
string path = "";
bool isLandscape = false;

if (lang == "rus")
{
    isLandscape = true;
    path = "~/ExcelTemplates/CustomerAgreementRus.docx";
}
else if (lang == "eng")
{
    isLandscape = true;
    path = "~/ExcelTemplates/CustomerAgreementEng.docx";
}
else
{
    path = "~/ExcelTemplates/CustomerAgreementGeo.docx";
}

Spire.Doc.Document doc = new Spire.Doc.Document(Server.MapPath(path));

var response = _contractorService.GetContractorGeneralInfo(new GetContractorGeneralInfoRequest { ContractorId = id });
doc.Replace("[CustomerName]", response.Name, false, true);
doc.Replace("[DateToday]", DateTime.Now.ToShortDateString(), false, true);
doc.Replace("[AgreementNumber]", "1", false, true);
doc.Replace("[DirectorName]", response.Director ?? "", false, true);
doc.Replace("[AgreementNumber]", "1", false, true);
doc.Replace("[IdentificationCode]", response.IdentificationCode ?? "", false, true);
doc.Replace("[CustomerAddress]", response.LegalAddress.Address1 ?? "", false, true);
doc.Replace("[PhoneNumber]", response.PhoneNumber ?? "", false, true);

if (isLandscape)
{
    //tried this too but still not working
    //doc.Sections[0].PageSetup.Orientation = Spire.Doc.Documents.PageOrientation.Landscape;
    //doc.Sections[0].PageSetup.Margins.Top = 40f;
    //doc.Sections[0].PageSetup.Margins.Left = 40f;
}

using (MemoryStream ms2 = new MemoryStream())
{
    doc.SaveToStream(ms2, Spire.Doc.FileFormat.Docx2010);
    //save to byte array
    byte[] toArray = ms2.ToArray();

    return File(toArray, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", response.Name + "_" + DateTime.Now.ToGeorgian().ToShortDateString() + ".docx");
}

xurca
 
Posts: 4
Joined: Wed Jun 01, 2016 9:23 am

Thu Jun 02, 2016 7:25 am

Hello,

Thank you for your kind feedback.
I have tested your files with the latest version Spire.Doc Pack Version:5.7 and they work fine without any issue. Please download and test the version.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri Jun 03, 2016 12:56 pm

Oh I am using FreeSpire.Doc and I guess thats the problem

xurca
 
Posts: 4
Joined: Wed Jun 01, 2016 9:23 am

Mon Jun 06, 2016 1:42 am

Hi,

Thank you for the reply.
Sorry that we don't plan to maintain the free version now.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Sat Sep 03, 2016 6:09 am

caroline.zhang wrote:Hi,

Thank you for the reply.
Sorry that we don't plan to maintain the free version now.

Sincerely,
Caroline
E-iceblue support team


Ah, so that's it. Time to upgrade I guess.

Fedor
 
Posts: 1
Joined: Fri Sep 02, 2016 7:32 am

Return to Spire.Doc