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

QR-Code in Word

8 Answers 405 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Андрей
Top achievements
Rank 1
Андрей asked on 22 Jul 2019, 08:56 PM
How can I add QR-code to the Word file in a specific place?

8 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 24 Jul 2019, 03:38 PM
Hello Андрей,

You can achieve this easily using our products.

Firstly you can check the Output Type help topic for RadBarcode (from Telerik UI for ASP.NET AJAX) to see how to create and export the image stream.

After that you will need the RadWordsProcessing library to create the document you would like to. If you want to import an existing document or export the generate one, you will need to use a DocxFormatProvider (or any other of the format provider classes, depending on the format you need). The ImageInline article shows more details on how to insert the image into the RadFlowDocument using RadFlowDocumentEditor.

I hope this helps. 

Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Андрей
Top achievements
Rank 1
answered on 25 Jul 2019, 04:04 PM

 

Hello Martin,

I am using RadWordsProcessing  and load Word`s file 

RadFlowDocument document;
DocxFormatProvider fileFormatProvider = new DocxFormatProvider();
string fileName = Server.MapPath("./Data/Document.docx");
using (FileStream input = new FileStream(fileName, FileMode.Open))
{
            document = fileFormatProvider.Import(input);
}
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);

 

And I create QR-code

RadBarcode QRCode = new RadBarcode
{
    Text = url,
    Type = BarcodeType.QRCode
};
 
QRCode.QRCodeSettings.Mode = Modes.CodeMode.Byte;
QRCode.QRCodeSettings.Version = 0;
QRCode.QRCodeSettings.ErrorCorrectionLevel = Modes.ErrorCorrectionLevel.L;
QRCode.QRCodeSettings.AutoIncreaseVersion = true;
 
Image imgBar = QRCode.GetImage();
 
using (MemoryStream mst = new MemoryStream())
{
    imgBar .Save(mst, System.Drawing.Imaging.ImageFormat.Png);
    editor.InsertImageInline(mst, "png", new Size(80, 80));
}

 

 

But the method InsertImageInline inserts a image at the beginning of the document.

How do I add QR-code in the middle of a document in a special place?

 

0
Андрей
Top achievements
Rank 1
answered on 26 Jul 2019, 10:40 AM
How can I find a specific paragraph in a document?
0
Accepted
Martin
Telerik team
answered on 26 Jul 2019, 11:18 AM
Hi Андрей,

The RadFlowDocument is a document designed to dynamically adjust its layout according to the available size. You can use its editor, the RadFlowDocumentEditor, which maintains an internal position inside the document. This position points either inside a paragraph (to an inline) or directly after the end of a table element. You can add an image inline to a specific position using two approaches.

The first one is positioning and inserting inline the image using the model.
Example 1:
Paragraph firstParagraph = document.EnumerateChildrenOfType<Paragraph>().First();
using (MemoryStream mst = new MemoryStream())
{
ImageInline imageInline = new ImageInline(document); imageInline.Image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(mst, "png"); imageInline.Image.Size = new Size(80, 80); firstParagraph.Inlines.Insert(0, imageInline);
}

The second one is using the editor to position and insert the image.
Example 2:

Paragraph firstParagraph = document.EnumerateChildrenOfType<Paragraph>().First();
using (MemoryStream mst = new MemoryStream())
{
// according Paragraph
editor.MoveToParagraphStart(firstParagraph);
editor.InsertImageInline(mst, "png", new Size(80, 80));

  // according InlineBase
editor.MoveToInlineEnd(firstParagraph.Inlines[1]);
editor.InsertImageInline(mst, "png", new Size(80, 80));
}
Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Андрей
Top achievements
Rank 1
answered on 26 Jul 2019, 02:01 PM
Can I also insert a picture in a table cell too?
0
Андрей
Top achievements
Rank 1
answered on 26 Jul 2019, 02:13 PM
How to find the necessary table or paragraph cell when calling document.EnumerateChildrenOfType<Paragraph>()? Is it possible to somehow mark it in the Word file?
0
Martin
Telerik team
answered on 29 Jul 2019, 02:33 PM
Hi Андрей,

In order to select the specific paragraph or table cell (again а paragraph within a table cell), you will need to iterate through the document elements. 

I am giving you an example using EnumerateChildrenOfType<T> method, which enumerates all child elements of given type and returns a collection of IEnumerable.

Check this examples:
// Selecting the Document`s Third Paragraph
Paragraph thirdParagraph = document.EnumerateChildrenOfType<
Paragraph>().ToList()[2];

// Selecting the First Cell of the First Table of the Document
Table selectFirstTable = document.EnumerateChildrenOfType<Table>().ToList()[0];
Paragraph firstCellParagraph = selectFirstTable.Rows[0].Cells[0].Blocks[0] as Paragraph;


Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Андрей
Top achievements
Rank 1
answered on 29 Jul 2019, 04:18 PM
Thank you very much, you helped me.
Tags
WordsProcessing
Asked by
Андрей
Top achievements
Rank 1
Answers by
Martin
Telerik team
Андрей
Top achievements
Rank 1
Share this question
or