This is a migrated thread and some comments may be shown as answers.

Fill a Word Document from ASP.Net and export to it to PDF

10 Answers 554 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 02 May 2017, 01:58 AM

Hi,

My apologies in advance if this cannot be done using Telerik Document Processing and I'm wasting everyone's time. I'll try and explain my situation the best I can.

We have large number of word documents related to a process which need to be converted to online forms. That's the easy part. The business wants the reporting of these forms exactly in the same format as in the original word documents. So we are hoping to use the word documents as templates (not necessarily .DOTX). 

Since the format of word documents often change The idea is to

  • Have one base document of each format kept on the server.
  • This base doc will have place-holders for the data to be filled in by asp.net (C#) for e.g. Employee Name: <<NAME>>.
  • When a report is to be generated, the relevant data is pulled from the SQL database and filled in the placeholders of the document. So in the above example <<NAME>> will be replaced by real name of the employee from database.
  • There will be some Base64 Images which will come from database and to be placed in the document e.g. signatures, profile pictures.
  • Once the document is completely filled, it is converted to PDF and downloaded to user's browser.
  • Whenever the format of a word document changes, it is replaced on the server and the asp.net fills this new format.  

Since we are in design phase of this I'm open to adapt to any suggestions. Any pointers/demo/advice on approach is welcome.

 

Thanks in Advance.

10 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 04 May 2017, 02:45 PM
Hi Amit,

You can achieve the desired scenario using the WordsProcessing library. The Mail Merge feature will help you implement the placeholders in the template DOCX document. You can generate the template using the API of WordsProcessing and then export it via DocxFormatProvider. When you have the data from the customer, you will need to perform the mail merge, then export the document to PDF with the PdfFormatProvider class.

There are several from our online examples that will help you in getting a better understanding of the features and in implementing the scenario. You will find them at http://demos.telerik.com/aspnet-ajax/wordsprocessing/.

Hope this is helpful.

Regards,
Tanya
Telerik by Progress

0
Amit
Top achievements
Rank 1
answered on 05 May 2017, 01:48 AM

Hi Tanya,

Thank you for your reply. I was suspecting that Mail Merge should be the solution for this.

I actually have been previously to the WordsProcessing Mail Merge example here that you've mentioned here, however it is not working. When you click the Mail Merge button, I get page not found error. So got confused. Might be something for your guys to fix.

I will get the developers have a look at WordsProcessing and Mail Merge. Will get back to you in case they get stuck somewhere.

Thanks again for the pointers.

 

0
Tanya
Telerik team
answered on 05 May 2017, 04:20 PM
Hi Amit,

Thank you for bringing the issue with the examples to our attention. We managed to fix it and now you should be able to check the demos.

Regards,
Tanya
Telerik by Progress

0
Amit
Top achievements
Rank 1
answered on 06 May 2017, 12:09 AM

Thanks Tanya,

Works perfectly now

0
Amit
Top achievements
Rank 1
answered on 17 May 2017, 07:57 AM

Hi Tanya,

we have taken your suggestion and moved ahead with Mail Merge for for generating our reports. However have hit a roadblock. We need to insert images in some merge fields (user signatures etc.). The images are stored as Base64 in an SQL database. could you please provide some suggestions or point us to examples which demonstrate how to insert an image from database onto a merge field of a document.

Thanks in advance

0
Amit
Top achievements
Rank 1
answered on 19 May 2017, 04:38 AM

Hi Tanya / Any other admin,

Could you please provide some help on the issue that we are facing (add image from DB to Mail Merge) its proving to be a roadblock for us.

 

Thanks

Amit

 

 

0
Tanya
Telerik team
answered on 19 May 2017, 02:47 PM
Hi Amit,

You can find the placeholder and replace it with the image using code similar to the following one:
RadFlowDocument document = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
  
editor.InsertText("1");
editor.InsertText("EXAMPLE_IMAGE");
editor.InsertText("2");
  
foreach (var run in editor.Document.EnumerateChildrenOfType<Run>().ToArray())
{
    if(run.Text == "EXAMPLE_IMAGE")
    {
        Paragraph paragraph = run.Paragraph;
        int indexOfCurrentRun = paragraph.Inlines.IndexOf(run);
        paragraph.Inlines.RemoveAt(indexOfCurrentRun);
  
        ImageInline imageInline = new ImageInline(document);
        imageInline.Image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(imageData, "png");
        paragraph.Inlines.Insert(indexOfCurrentRun, imageInline);
    }
}

The ImageSource constructor overloads allow you pass a byte[] or a stream containing the image data, so you will need to convert the Base64 string.

We have also logged a feature request to implement similar functionality in RadWordsProcessing: INCLUDEPICTURE field. You can vote for its implementation and track its status through the public item in our feedback portal.

Regards,
Tanya
Telerik by Progress

0
Ruben
Top achievements
Rank 1
answered on 26 Jan 2018, 09:47 PM

Hi,

I am using WordsProcessing version WinForms 2018.1.116 and INCLUDEPICTURE seems doesn't work. Do you have any working example with image? Can you update you online example with INCLUDEPICTURE?

Thank you,

Ruben

0
Tanya
Telerik team
answered on 30 Jan 2018, 12:49 PM
Hi Ruben,

The INCLUDEPICTURE field is still not supported in RadWordsProcessing and you can vote for the implementation of the feature as well as subscribe to track its status using the related public item on our portal. In this item, you will find a description of how you could replace keywords with images using the API of WordsProcessing, similar to the one shown in my previous post.

Hope this helps.

Regards,
Tanya
Progress Telerik

0
Ruben
Top achievements
Rank 1
answered on 30 Jan 2018, 07:34 PM

Hi Tanya,

I had impression, that it is implemented. Anyway, your example is working fine.

Thank you,

Ruben

Tags
WordsProcessing
Asked by
Amit
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Amit
Top achievements
Rank 1
Ruben
Top achievements
Rank 1
Share this question
or