QR-Code in Word

9 posts, 1 answers
  1. Андрей
    Андрей avatar
    14 posts
    Member since:
    Dec 2014

    Posted 22 Jul 2019 Link to this post

    How can I add QR-code to the Word file in a specific place?
  2. Martin
    Admin
    Martin avatar
    39 posts

    Posted 24 Jul 2019 Link to this post

    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.
  3. Андрей
    Андрей avatar
    14 posts
    Member since:
    Dec 2014

    Posted 25 Jul 2019 in reply to Martin Link to this post

     

    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?

     

  4. Андрей
    Андрей avatar
    14 posts
    Member since:
    Dec 2014

    Posted 26 Jul 2019 in reply to Андрей Link to this post

    How can I find a specific paragraph in a document?
  5. Answer
    Martin
    Admin
    Martin avatar
    39 posts

    Posted 26 Jul 2019 Link to this post

    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.
  6. Андрей
    Андрей avatar
    14 posts
    Member since:
    Dec 2014

    Posted 26 Jul 2019 in reply to Martin Link to this post

    Can I also insert a picture in a table cell too?
  7. Андрей
    Андрей avatar
    14 posts
    Member since:
    Dec 2014

    Posted 26 Jul 2019 in reply to Андрей Link to this post

    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?
  8. Martin
    Admin
    Martin avatar
    39 posts

    Posted 29 Jul 2019 Link to this post

    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.
  9. Андрей
    Андрей avatar
    14 posts
    Member since:
    Dec 2014

    Posted 29 Jul 2019 in reply to Martin Link to this post

    Thank you very much, you helped me.
Back to Top