Solved

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

Posted on 1998-10-15
22
263 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

18 Experts available now in Live!

Get 1:1 Help Now