Skip to main content
July 17, 2011
Question

how can i copy line with text and image to ms word

  • July 17, 2011
  • 1 reply
  • 820 views

When I insert an image in textflow using InlineGraphicElement it works, but when I copy the line with the image to MS Word it copies only the text (not the image).

How can i copy the image to MS Word?

This topic has been closed for replies.

1 reply

Adobe Employee
July 18, 2011

If you want copy formatted text and image to MS Word, you need to give MS Word rtf markup, because Word can recognize rtf markup but not TLF markup.

So you need to create a custom clipboard to paste a rtf markup. It's a large feature for you, because you need a tlf-rtf converter in your custom clipboard.

TLF Custom Clipboard Example:

package
{
    import flash.display.Sprite;
    import flash.desktop.ClipboardFormats;
   
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.conversion.ITextImporter;
    import flashx.textLayout.conversion.TextConverter;
    import flashx.textLayout.edit.EditManager;
    import flashx.textLayout.elements.*;
    import flashx.undo.UndoManager;
   
   
    // Example code to install a custom clipboard format. This one installs at the front of the list (overriding all later formats)
    // and adds a handler for plain text that strips out all consonants (everything except aeiou).
    public class CustomClipboardFormat extends Sprite
    {
        public function CustomClipboardFormat()
        {
            var textFlow:TextFlow = setup();
            TextConverter.addFormatAt(0, "vowelsOnly_extraList", VowelsOnlyImporter, AdditionalListExporter, "air:text" /* it's a converter for cliboard */);
        }
       
        private const markup:String = '<TextFlow whiteSpaceCollapse="preserve" version="2.0.0" xmlns="http://ns.adobe.com/textLayout/2008"><p><span color=\"0x00ff00\">Anything you paste will have all consonants removed.</span></p></TextFlow>';
        private function setup():TextFlow
        {
            var importer:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_LAYOUT_FORMAT);
            var textFlow:TextFlow = importer.importToFlow(markup);
            textFlow.flowComposer.addController(new ContainerController(this,500,200));
            textFlow.interactionManager = new EditManager(new UndoManager());
            textFlow.flowComposer.updateAllControllers();
            return textFlow;
        }
    }

import flashx.textLayout.conversion.ITextExporter;
import flashx.textLayout.conversion.ConverterBase;
import flashx.textLayout.conversion.ITextImporter;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.elements.IConfiguration;
import flashx.textLayout.elements.TextFlow;

class VowelsOnlyImporter extends ConverterBase implements ITextImporter
{
    protected var _config:IConfiguration = null;
   
    /** Constructor */
    public function VowelsOnlyImporter()
    {
        super();
    }
   
    public function importToFlow(source:Object):TextFlow
    {
        if (source is String)
        {
            var firstChar:String = (source as String).charAt(0);
            firstChar = firstChar.toLowerCase();
            // This filter only applies if the first character is a vowel
            if (firstChar == 'a' || firstChar == 'i' || firstChar == 'e' || firstChar == 'o' || firstChar == 'u')
            {
                var pattern:RegExp = /([b-df-hj-np-tv-z])*/g;
                source = source.replace(pattern, "");
                var importer:ITextImporter = TextConverter.getImporter(TextConverter.PLAIN_TEXT_FORMAT);
                importer.useClipboardAnnotations = this.useClipboardAnnotations;
                importer.configuration = _config;
                return importer.importToFlow(source);
            }
        }
        return null;
    }

    public function get configuration():IConfiguration
    {
        return _config;
    }
   
    public function set configuration(value:IConfiguration):void
    {
        _config = value;
    }
}

import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.ListElement;
import flashx.textLayout.elements.ListItemElement;

class AdditionalListExporter extends ConverterBase implements ITextExporter
{
    /** Constructor */
    public function AdditionalListExporter()   
    {
        super();
    }
   
    public function export(source:TextFlow, conversionType:String):Object
    {
        if (source is TextFlow)
        {
            source.getChildAt(source.numChildren - 1).setStyle(MERGE_TO_NEXT_ON_PASTE, false);
           
            var list:ListElement = new ListElement();
            var item1:ListItemElement = new ListItemElement();
            var item2:ListItemElement = new ListItemElement();
            var para1:ParagraphElement = new ParagraphElement();
            var para2:ParagraphElement = new ParagraphElement();
            var span1:SpanElement = new SpanElement();
            span1.text = "ab";
            var span2:SpanElement = new SpanElement();
            span2.text = "cd";
            list.addChild(item1);
            list.addChild(item2);
            item1.addChild(para1);
            para1.addChild(span1);
            item2.addChild(para2);
            para2.addChild(span2);
            source.addChild(list);
           
            var exporter:ITextExporter = TextConverter.getExporter(TextConverter.TEXT_LAYOUT_FORMAT);
            exporter.useClipboardAnnotations = this.useClipboardAnnotations;
            return exporter.export(source, conversionType);   
        }
        return null;
    }
}

July 18, 2011

this is my source code what i do to convert it

your sample is complicated to me

thanks

this is the part of graphics

// InlineGraphicElement has "auto" width/height so the size can't be calculated till the graphic is loaded
       
var inlineGraphic:InlineGraphicElement = new InlineGraphicElement();
        inlineGraphic
.source = drawRect();
        p
.addChild(inlineGraphic);
        mytextflow
.flowComposer.updateAllControllers();

        mytextflow
.addChild(bulletLayer);

       
}


function drawRect():Sprite
   
{
       
var redRect:Sprite = new Sprite();
        redRect
.graphics.beginFill(0xff0000);    // red
        redRect
.graphics.drawRect(0,0,30, 30);
        redRect
.graphics.endFill();
       
return redRect;
   
}