Solved

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

Posted on 1998-10-15
22
279 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert a string into a TDateTime 5 72
FMX and jaudiotracker playing memory stream 29 98
DBGrid or StringGrid ? 6 120
Get weeknumber and year from date 4 27
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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