0

I need to crop pdf and create word document of that cropped png image by pasting that in word document.

I am using Firemonkey Platform

this is code :

    procedure TForm2.Button1Click(Sender: TObject);
    begin
     ShellExecute(FormToHWND(Self),'open',PChar(GetCurrentDir+'\cairo.exe')
     ,PWideChar('-opw '+Edit1.Text+
     ' -cropbox -png -x 64 -y 215 -W 144 -H 375 -r 167 '+
     PdfFile+' tools/card'),'',SW_Hide);
     Sleep(500);
     Image1.Bitmap.LoadFromFile(Output);
    end;

    procedure TForm2.Button2Click(Sender: TObject);
    begin
         ClipBoard.Assign(Image1.Bitmap);
    end;

        procedure TForm2.FormCreate(Sender: TObject);
    begin
    Output:= GetCurrentDir+'\tools\card-1.png';
    end; 

Clicking on button2 pops the error Cannot assign TBitmapOfItem to TClipBoard.

How to copy the image to clipboard and create word document (don't know much about it) ?

Winsye
  • 35
  • 5
  • 1
    Don't destroy the clipboard object. Test the copying to the clipboard with a bitmap loaded from a file rather than that wacky ShellExecute. Once that works you need to fix the ShellExecute not to use Sleep. Question is also rather too vague. Can't see any word document here. – David Heffernan May 06 '19 at 17:50
  • @DavidHeffernan As you said i removed the destruction of Clipboard but the error is same. i am using the sleep as the pdftocairo.exe takes that time to create png file in drive and i am loading that into TImage but can't copy that confusing for me. – Winsye May 06 '19 at 17:55
  • 1
    My advice is to break the problem down. Forget about this Cairo stuff for now. Concentrate on learning how to copy a bitmap to the clipboard. Once you have a [mcve] we can tell you what is wrong. But this is confused and muddled and low quality. Please improve the question by making a clean [mcve]. – David Heffernan May 06 '19 at 18:00
  • I mean I can guess that the issue relates to you using VCL code in a Firemonkey app. But don't make us guess. This site is about enduring posts. Quality and clarity matter to us. – David Heffernan May 06 '19 at 18:02
  • @DavidHeffernan sorry for the late reply sir i faced system crash. I was just about to mention about firemonkey and you guessed it. – Winsye May 06 '19 at 18:57
  • 1
    Here is how you can use Clipboard in FMX: [Multi-Device Apps and Clipboard Support](https://community.idera.com/developer-tools/b/blog/posts/multi-device-apps-and-clipboard-support) – zed May 06 '19 at 19:05

1 Answers1

0

Simple example how you can copy some Image to Clipboard in FMX:

uses
  FMX.Platform;

...

procedure TForm1.Button1Click(Sender: TObject);
var
  VClipboard: IFMXClipboardService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, VClipboard) then begin
    Image1.Bitmap.LoadFromFile('c:\image_1.png');
    VClipboard.SetClipboard(Image1.Bitmap);
  end;
end;

More information about using Clipboard in FMX apps here: Multi-Device Apps and Clipboard Support

zed
  • 798
  • 7
  • 12
  • my uses clause was FMX.Platform.Win so it didn't found the IFMXClipboardService. Can please help me to create word document to paste the copied image into the doc ? – Winsye May 06 '19 at 19:24
  • 1
    @Winsye One question is one problem to solve. I helped you with Clipboard, ask another question and maybe someone will help you with Word. – zed May 06 '19 at 19:28