Recent

Author Topic: How to print a PDF document from lazarus  (Read 4493 times)

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
How to print a PDF document from lazarus
« on: December 11, 2019, 09:31:18 pm »
Hello all,
I was searching to see how it is possible to print a PDF file
By simply send a print command from lazarus. Something like
On Button click event to call
PrintDocument(mydoc.pdf);

The only way I found which unfortunately did not work is to use windows API
Code: Pascal  [Select][+][-]
  1. Begin
  2.     Shellexecutew(application.handle,'print',pwidechar(myfile),nil,nil,sw_Hide);
  3. End;
  4.  
Any views. Many thanks for all

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to print a PDF document from lazarus
« Reply #1 on: December 11, 2019, 10:46:49 pm »
If you are in windows you can use the already installed PDF printer..

Simply use the Printer unit and select it.

That is what I do, it works a treat
The only true wisdom is knowing you know nothing

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: How to print a PDF document from lazarus
« Reply #2 on: December 11, 2019, 11:15:53 pm »
Thanks jamie,
The problem is not with the pdf printer. It is how to send the printing
Order to it. I.e to order the printer to print all pdf documents in a given folder .
The driver is installed on my windows machine.
Would you please show how you do it- many thanks.
« Last Edit: December 11, 2019, 11:17:40 pm by lazdeveloper »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to print a PDF document from lazarus
« Reply #3 on: December 12, 2019, 12:16:03 am »
maybe I miss understood you...

You want to print PDF's not print to a PDF ?

If that being the case, you can use the ShellExecute(0, 'print', PathNameOfPDF, '',SW_HIDE);

The last one I may have wrong, made..

Do this in a loop and using the list of names you have... It should all go to the Printers que with the currently selected printer.

 Of course if you want to do all of this inside your app and especially trying to make this cross platform then maybe we need a PDF viewer in laz that we can print from.
The only true wisdom is knowing you know nothing

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: How to print a PDF document from lazarus
« Reply #4 on: December 12, 2019, 05:47:18 am »
Thanks..
Quote
You want to print PDF's not print to a PDF ?
That's right.

well I could not have shellexecute doing this but could not even
Know why. While shellexecute is used by  openDocument function that is
Available in Lclintf, it does not work for sending a printing order to the defualt printer.
Regarding a pdf viewer within Lazarus, do you recommend any light free widget
To do so. May be then someone can use the viewer to view and print?
« Last Edit: December 12, 2019, 05:50:09 am by lazdeveloper »

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: How to print a PDF document from lazarus
« Reply #5 on: December 12, 2019, 06:46:33 pm »
Hi all,
Well it seems that no one has delt with documents printing from lazarus application.
This makes sence since we normally use the document application to preview and print I.e acrobat for PDFs and so on.
But guys in general can we send a document  printing job to the printer.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: How to print a PDF document from lazarus
« Reply #6 on: December 12, 2019, 07:19:00 pm »
It might surprise you but there are plenty of people who have other things to do with their time than sit with fingers poised to answer every question that arrives in the forum. Complaining that nobody's answered with less than an hour between your postings isn't really fair.

What OS are you running- some version of Windows apparently but /what/ version? What version of Lazarus? What happens when you try to use the example that Jamie supplied?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to print a PDF document from lazarus
« Reply #7 on: December 12, 2019, 11:29:10 pm »
I really don't fully understand his request but I assume there is an issue with the order in which they print ?

 It would be simply to just query the list if files and send them one at a time until done.

 a Wait state function can be used for that. That way the docs can be sent in any order desired.
The only true wisdom is knowing you know nothing

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: How to print a PDF document from lazarus
« Reply #8 on: December 12, 2019, 11:46:41 pm »
Well,
It was not a complaining - apologies if it sounds like that.
The code that Jamie has kindly suggested is the same one I have started the post with.
The problem is simply i have say a folder that has 3 pdf files and
I just wanted to print them by directly send a print command to the printer.
My lazarus is 2.0.6, windows 10.
Bottom line: thanks always go to everybody in this nice community and for having
the time to read or reply post.

paweld

  • Hero Member
  • *****
  • Posts: 970
Best regards / Pozdrawiam
paweld

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: How to print a PDF document from lazarus
« Reply #10 on: December 13, 2019, 05:51:56 am »
Thanks paweld,
This is a possible good solution with  the need to distribute smartpdfreader with application.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: How to print a PDF document from lazarus
« Reply #11 on: December 13, 2019, 09:22:30 am »
The code that Jamie has kindly suggested is the same one I have started the post with.

It's not. The code that you started off with used Application.Handle: you complained that it didn't work but didn't give us details.

The code that Jamie supplied used zero (and apparently had one fewer parameter) and you gave very few details as to why it didn't work for you.

I very rarely use Windows these days, but my general experience is (used to be :-) that the ShellExecute functions worked pretty well provided that the underlying file associations were set up- which in the case of a PDF might require a non-standard reader of some sort to be installed unless one's bundled with Windows.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: How to print a PDF document from lazarus
« Reply #12 on: December 15, 2019, 09:23:30 am »
Well,
The code by jamie has one parameter less because it is missing a parameter.
shellexecute has
A number of params passed as I started the topic. You can try that
shellexecute doesn't usually give you a feedback to know why it did not work.
For example OpenDocument function in lazarus uses shellexecute and the result
Is integer to be then false or true. See OpenDocument implementation or
https://wiki.freepascal.org/Executing_External_Programs
In the link above they provided a usefull proc
Quote
Code: Pascal  [Select][+][-]
  1. // or a useful procedure:
  2. procedure RunShellExecute(const prog,params:string);
  3. begin
  4.   //  ( Handle, nil/'open'/'edit'/'find'/'explore'/'print',   // 'open' isn't always needed
  5.   //      path+prog, params, working folder,
  6.   //        0=hide / 1=SW_SHOWNORMAL / 3=max / 7=min)   // for SW_ constants : uses ... Windows ...
  7.   if ShellExecute(0,'open',PChar(prog),PChar(params),PChar(extractfilepath(prog)),1) >32 then; //success
  8.   // return values 0..32 are errors
  9. end;
  10.  

What happened with me is nothing happend. Just it executes quietly with no action

« Last Edit: December 15, 2019, 09:38:02 am by lazdeveloper »

 

TinyPortal © 2005-2018