Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-10-15
22
Medium Priority
?
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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 40 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

604 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