Jump to content

Clipboard: detect and separate text from image


Recommended Posts

Hello,

at work we receive tons of Office documents (word, excel) with an image and description.

Operators must open single file, extract photo, text and put in an internal tool.

There is any way to :

- select all document (photo+text) and copy (put to clipboard)

- let an AI script detect change in clipboard

- separe image from text in 2 different files.

Then with hot folder i can send automatically to my Production program.

Now i'm reading post about _ClipBoard_GetDataEx from forum users, anyone can help with some hints ?

thank you,

m.

 

Link to comment
Share on other sites

I know you can copy/paste plain text. I used this in a script so it would strip any color/font/format from what I copied. This would also strip away your images.

Not sure about the rest of what you want to do though, sounds like something that could be done but I am not sure where to start with it.

You may even look into Waters Excel & Word UDF if those are your only file types lots of backend ways to access files that could be even faster and more automated than copy/paste, possibly it can get the images right out for you.

Link to comment
Share on other sites

thank you for reply,

reading forum find some working examples. This read clipboard and save image to desktop:

#include <Clipboard.au3>
#Include <GDIPlus.au3>

_SaveClip(@ScriptDir & "\XXX.jpg")

Func _SaveClip($sFile)
    If _ClipBoard_IsFormatAvailable($CF_BITMAP) <> 1 Then Return SetError(1, 0, 0)
    If _ClipBoard_Open(0) <> 1 Then Return SetError(2, 0, 0)
    If @error Then SetError(3, 0, 0)
    $hBitmap = _ClipBoard_GetDataEx($CF_BITMAP)
    If IsPtr($hBitmap) = 0 Then Return SetError(4, 0, 0)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    If @error Or IsPtr($hImage) = 0 Then
        _ClipBoard_Close()
        _WinAPI_DeleteObject($hBitmap)
        _GDIPlus_Shutdown()
        Return SetError(5, 0, 0)
    EndIf
    _ClipBoard_Close()
    _WinAPI_DeleteObject($hBitmap)
    If _GDIPlus_ImageSaveToFile($hImage, $sFile) = False Then
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        Return SetError(6, 0, 0)
    Else
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_SaveClip

i'm searching to separe image from text with single copy.

m,

Link to comment
Share on other sites

Create primitive script,

that detect changes in clipboard, and try to understand if TXT or IMAGE:

#include <Clipboard.au3>
#Include <GDIPlus.au3>



$ClipGet_now = ClipGet()
$ClipGet_old = $ClipGet_now

while 1


    $ClipGet_now = ClipGet()
    $ClipGet_status = @error

    ;something change in clipboard
    if $ClipGet_now <> $ClipGet_old Then


        if $ClipGet_status = 2 Then                ;it s not text
            msgbox(0,$ClipGet_status & " CLIP change! and it's not TEXT ", $ClipGet_now)
            _SaveClip(@ScriptDir & "\XXX.jpg")
        EndIf

    EndIf

    $ClipGet_old = $ClipGet_now
    Sleep(10)
WEnd




Func _SaveClip($sFile)
    If _ClipBoard_IsFormatAvailable($CF_BITMAP) <> 1 Then Return SetError(1, 0, 0)
    If _ClipBoard_Open(0) <> 1 Then Return SetError(2, 0, 0)
    If @error Then SetError(3, 0, 0)
    $hBitmap = _ClipBoard_GetDataEx($CF_BITMAP)
    If IsPtr($hBitmap) = 0 Then Return SetError(4, 0, 0)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    If @error Or IsPtr($hImage) = 0 Then
        _ClipBoard_Close()
        _WinAPI_DeleteObject($hBitmap)
        _GDIPlus_Shutdown()
        Return SetError(5, 0, 0)
    EndIf
    _ClipBoard_Close()
    _WinAPI_DeleteObject($hBitmap)
    If _GDIPlus_ImageSaveToFile($hImage, $sFile) = False Then
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        Return SetError(6, 0, 0)
    Else
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_SaveClip

Using _ClipBoard_GetDataEx function can open more options in clipboard detection and output;

eg: detect and manain Rich Text Formats (Wordpad RTF)

thank you for any information,

m.

Link to comment
Share on other sites

Hello,
search and read old post about identify a registered clipboard format and then use them.
 
Find some usefull info using _ClipBoard_EnumFormats function, capable to detect also Clipboard format : Rich Text Format
So Autoit can detect other format than simple text. This may allow format preservation (eg: bold)
 
Try also a nice UDF that preserve HTML format _ClipgetHTML

So think my request, distinguish between text/image and preserve text formatting, is not impossible.

This can automate really a lot and simplify all flows where copy and paste is heavy needed.

Find functions but any example about their advanced use. Anyone can help a bit ? :sweating:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...