create pdf from predefined word template RRS feed

  • Question

  • User97258757 posted


     I am writing a program to generate PDF using word Template .  Word Template have some  keys which will be dynamically replaced and saved as PDF  

     My code is failing and not creating PDF, if you have source code and any idea, please suggest. 

    Here is Code:-

    string Body = string.Empty;
    using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailHTML/certifcate.docx")))
    Body = reader.ReadToEnd();
    Body = Body.Replace("[PackageCost]", model.TotalAmmount);
    Body = Body.Replace("[Name]", model.FName);
    Body = Body.Replace("[Address]", model.Address);
    Body = Body.Replace("[Phoneno]", model.PhoneNumber);
    Body = Body.Replace("[Email]", model.Email);
    Body = Body.Replace("[HoursOfWork]", " ");
    Body = Body.Replace("[CategoryOfWork]", model.categoryname);
    Body = Body.Replace("[ScopeOfWork]", model.expertisename);
    Body = Body.Replace("[IssueDate]", model.Email1);
    Body = Body.Replace("[Time]", Time);


    using (MemoryStream stream = new System.IO.MemoryStream())
    StringReader sr = new StringReader(Body);
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
    PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
    XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
    return File(stream.ToArray(), "application/pdf", "Certificate.pdf");


     Thanks in advance, 

    Wednesday, November 28, 2018 6:12 AM

All replies

  • User1520731567 posted

    Hi Nilasish,

    What is your error report?

    Do you use itextsharp?

    Could you please post more details,such as: your word Template...

    Best Regards.

    Yuki Tao

    Thursday, November 29, 2018 7:03 AM