Solved

'''>>- Print JPG Files -<<'''

Posted on 1998-10-15
22
251 Views
Last Modified: 2010-08-05
why doesn't this work ?

ShellExecute(0,'print','c:\a.jpg','','',0);   ?

How should I do it ?

k, thanx ya.
0
Comment
Question by:menorcanet
  • 7
  • 6
  • 6
  • +2
22 Comments
 
LVL 4

Expert Comment

by:binkzz
ID: 1342959
One way to do it is loading it into a component and then execute the component.print
method.

Binkzz
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1342960
menorcanet

Have you included the JPEG unit in you uses clause..

uses
 Forms...., JPEG;

Also your Shellexecute's handle should be

Handle not 0

ShellExecute(Handle, 'print', 'c:\a.jpg', '', '', 0);

have you tried loading the jpg into a image component and then printing it..

Later
BoRiS
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1342961
as explained in my previous comment
0
 

Author Comment

by:menorcanet
ID: 1342962
ok, I tried with "Handle" and I still get the Error 31 ( a:= Shellexecute(handle,'pri...)

and... I have no idea on how to load the jpg file into an image component, and then
 print it.

and yeah, I included the ShellApi and JPEG in the USES clause.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342963
This one works with a DOC file extension

      ShellExecute(0, 'print', 'c:\windows\desktop\test.doc', nil, nil, 0);

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1342964
menorcanet

drop  a button on your form and on the onclick event copy this, also add printers to your uses clause...

procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      JPG : TJpegImage;

    begin
      if Printer.Printing then
        Application.MessageBox('Printer is busy', 'Print Error', 0)
      else
        begin
          Printer.Title := 'Printing JPEG'S';
          Printer.BeginDoc;
          with Printer.Canvas do
            begin
              Font.Name := 'Arial';
              Font.Pitch := fpDefault;
              Font.Style := [fsItalic, fsBold];
              Font.Size := 30;
              Font.Color := clBlack;
              TextOut(100, 100, 'Getting the JPEG Printed');
              JPG := TJpegImage.Create;
              JPG.LoadFromFile('c:\a.jpg');
              Draw(100, 300, JPG);
              JPG.Free;
            end;
          Printer.EndDoc;
        end;
    end;

Later
BoRiS
0
 
LVL 2

Expert Comment

by:Thaddy
ID: 1342965
Or use the example in D4's help\example\Jpeg directory!:

procedure TForm1.Print1Click(Sender: TObject);
var
  AspectRatio: Single;
  OutputWidth, OutputHeight: Single;
begin
  if not PrintDialog1.Execute then Exit;
  Printer.BeginDoc;
  try
    OutputWidth := Image1.Picture.Width;
    OutputHeight := Image1.Picture.Height;
    AspectRatio := OutputWidth / OutputHeight;
    if (OutputWidth < Printer.PageWidth) and
      (OutputHeight < Printer.PageHeight) then
    begin
      if OutputWidth < OutputHeight then
      begin
        OutputHeight := Printer.PageHeight;
        OutputWidth := OutputHeight * AspectRatio;
      end
      else
      begin
        OutputWidth := Printer.PageWidth;
        OutputHeight := OutputWidth / AspectRatio;
      end
    end;
    if OutputWidth > Printer.PageWidth then
    begin
      OutputWidth := Printer.PageWidth;
      OutputHeight := OutputWidth / AspectRatio;
    end;
    if OutputHeight > Printer.PageHeight then
    begin
      OutputHeight := Printer.PageHeight;
      OutputWidth := OutputHeight * AspectRatio;
    end;
    Printer.Canvas.StretchDraw(Rect(0,0,
      Trunc(OutputWidth), Trunc(OutputHeight)),
      Image1.Picture.Graphic);
  finally
    Printer.EndDoc;
  end;
end;

0
 

Author Comment

by:menorcanet
ID: 1342966
Thaddy:::

How do I assign Image1.Picture with a jpg file ?
Boris' answer works, but the image is printed very small.


0
 

Author Comment

by:menorcanet
ID: 1342967
hey Boris, take a look at my question about Using JPEG,

I left a message for you

0
 

Author Comment

by:menorcanet
ID: 1342968
Look at the comment
0
 

Author Comment

by:menorcanet
ID: 1342969
I don't have D4, I have Delphi 1 to 3.

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:viktornet
ID: 1342970
Hello menorcanet.////

When you draw the JPG image onto the Printer's canvas use StretchDraw() If you need help with that just tell me :-)

Cheers,
Viktor
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1342971
menorcanet

Yip send me your component and I'll put it up, like I said the page is for you guys here at the EX-EX my email is phillip@vwv.com
remember to send a brief discription of the component etc.

also I see you say the jpeg prints to small just increase the draw size

Draw(100, 300, JPG);
to
Draw(500, 480, JPG);

Later
BoRiS
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342972
Hello guys.

Draw(500, 480) will just print it in a x=500 and y=480...it won't increase the size of the printed image....

As I said before you need to use StretchDraw() even thought it's not the only one to use...however it's the easiest one to be used ;->

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1342973
menocanet

Yip viktornet is totally correct, sorry wasn't thinking I meant to say
 
StrechDraw();

Viktornet

check out my home page it's for all the experts here at Ex-Ex to put up there components etc...

http://www.geocities.com/SiliconValley/Garage/3862/

follow the delphi section...

That goes for the rest of you here at Ex-Ex (delphi)

Later
BoRiS
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1342974
menorcanet

forgot to mention how to use strechDraw

StrechDraw(Rect, JPG);

rect been the defined rectangle for the printer canvas

Later
BoRiS
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342975
Hello again!

Here is how to use StrecthDraw()

This is Boris' procedure but I've added the needed function



     procedure TForm1.BitBtn1Click(Sender: TObject);
         var
           JPG : TJpegImage;
           R : TRect;
         begin
           if Printer.Printing then
             Application.MessageBox('Printer is busy', 'Print Error', 0)
           else
             begin
               Printer.Title := 'Printing JPEG''S';
               Printer.BeginDoc;
               with Printer.Canvas do
                 begin
                   Font.Name := 'Arial';
                   Font.Pitch := fpDefault;
                   Font.Style := [fsItalic, fsBold];
                   Font.Size := 30;
                   Font.Color := clBlack;
                   TextOut(100, 100, 'Getting the JPEG Printed');
                   JPG := TJpegImage.Create;
                   JPG.LoadFromFile('C:\something\test.jpg');
                   R := Rect(0, 0, JPG.Width * 2, JPG.Height * 2);//make it twice as big as it was b4
                   StretchDraw(R, JPG);
                   JPG.Free;
                 end;
               Printer.EndDoc;
             end;
         end;

Hope this helps :-)

Regards,
Viktor Ivanov
0
 

Author Comment

by:menorcanet
ID: 1342976
Yeah ! it works now with StretchDraw !

thanx a lot you all !


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342977
Hello y'all,....

Boris....go for the points....

Cheers,
Viktor
0
 
LVL 4

Accepted Solution

by:
BoRiS earned 10 total points
ID: 1342978
menorcanet

Here is an answer for the question...

viktornet

Why thank you my good man.... :-)

Later
BoRiS
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342979
No problem :-)

Cheers,
Viktor
0
 

Author Comment

by:menorcanet
ID: 1342980
there you have the points.

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now