Solved

CGI/PHP and Printing (a direction)

Posted on 2011-02-20
15
919 Views
Last Modified: 2013-12-25
In this thread....

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_26832474.html?cid=239#a34931907

I was told that a possilbe solution would be CGI printing. Sense I have access to all servers and code, I could do this , but sadly CGI isnt' a strong point atm. Can someone help (guide) me with a good link and or information on how to script out (or again point too) a printing script?

For knowing what I am looking to do, please see link. Basicly force printing from PHP; and before you chringe on the word force, this is an intranet application not internet :) thanx!

I want to directly print to the network printer a generated php (after the browser page has been generated) and dupe that to printing. Just like when you hit "print" link in your broswer. Again refer to link above as I have found other ways to bypass this function without user prompt. However, I need to reset the default print to goto a particular printer. This was all viable back in IE4, but not anymore.

So if you know a good place for links or how to or if you know even better! I know I have to setup cgi on apache, I know I have to make a script to link to a printer then same script to ID a particular page (this is where I need a link or help). Thnx again everyone!

-Chaintm
0
Comment
Question by:chaintm
  • 9
  • 6
15 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34938182
I just posted a simple example in the other question but it needs to be refined to do exactly what you want.
0
 

Author Comment

by:chaintm
ID: 34938691
aye I seen that, hopfully others have ran into this, I do appreciate your input! Don't feel bad if you don't have the exact answer. Sadly for me, I don't know this particular code at all. So it's all new to me, but again I can learn quickly, at least enough to get this to work.

Thnx again!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34939577
I used Active Perl http://www.activestate.com/activeperl .  You need to make sure that whatever you use will work thru Apache.  Active Perl installs to IIS but I didn't notice anything about Apache on Windows.  How did you install Apache on your machine?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34939908
Ok, I've figured out how to print text with a CGI script.  Rendering and printing a web page is quite another thing.  That usually requires the browser to 'render' it to send it to the printer.  Can you post a sample of what you want to print and what you want it to look like?
0
 

Author Comment

by:chaintm
ID: 34940309
As in my other post, I was able to make text as well actually through doing the ...

///////
$filename = '"order_items_print.php?all=".$oldvalues["Order_num"]?>"';
///////
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
///////
$handle = printer_open();
printer_set_option($handle, PRINTER_MODE, "raw");
printer_write($handle,$contents, "test");
printer_close($handle);
///////

there is a printer.dll that is avalible and this text did come through the network printer when I tested it, however attempting to render the page then print it has always been the issue. As the code rendered is information from the mysql server pulled from an order that is built on the php page with css,html,php and ajax. The format has to hold but all that is there is text as this is being printed directly into a contract/invoice.

The above code error'd because of rendering issues, I read something about doing conversions like convert to adobe then print with script, but again another object uses this referance and it will not be possible. The other option I read into was about putting it into a buffer, but even then a buffer is technically the same thing as printing and or session depending how you use it and I have a ton of sessions running etc. Again not viable.

The printer_open when looked at php manual and the following operations would work if I could figure how to render and print. Refering back to the original post again. The page I render (not at work atm) but it is just again text and frame work.

So while printing text isn't an issue, it's more force printing the rendered page to a print server or que. With the security features of windows explorer and pretty much all browsers ,this has been the issue. But I KNOW there has to be a solution. Before IE4, it was possible of course and even now possible to bypass the prompt (as shown in my other post) and never give the user option to print it just does.

In the end, I am suprised I can't just pick an IP and print to it. Oh well, hopfully someone will nab an idea or something they came across. CGI seems like the most plausable soultion thou.

Server setup:

Win2008
php
apache
and supporting software. I can install whatever I want.
0
 

Author Comment

by:chaintm
ID: 34940317
oh ps , i could put into the server that server as well, but it is not public to the internet so it didn't need it.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34940364
I'm not surprised that you can't pick an IP to print to since it does have to go through a driver of some sort.  If it's just text, my LaserJet 4 will accept that.  None of my other printers will because the driver does the formatting.  And if you wants the fonts displayed, that too has to go thru the driver.  However, I can select my LaserJet 4 on the network in my print menu and print a web page to it.
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!

 

Author Comment

by:chaintm
ID: 34946738
Thinking about going a different rout, what about print server 2008 handling the sorting , hmm thinking there has to be some way to ID a URL that the server can see coming threw then know it goes to a particular printer such as the servers dotmatrix printer, and all other docs go to the users default printer.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34946857
That won't work because it requires two different drivers to process the HTML file.  If you send the web page directly to the printer, if it prints anything, it will print the page source code.  Something like the web browser has to interpret the page and send it to the print driver which then sends it to the printer.  If you could "print to PDF", there are some printers that can interpret PDFs and print them.  Not cheap though.

Obviously I misunderstood the original question.  Unless you can print plain text, you need to forget about sending it to an IP.  You can't skip the formatting and driver steps and have it print correctly.

The things that you can do to 'force' print the information in addition to a normal print from the browser involve formatting the data yourself for the printer you want to use.  It's entirely possible if it's a simple enough printer with a published interface or language.  But it is a lot of work.
0
 

Author Comment

by:chaintm
ID: 34947462
Yea, finding this out, if I was on a unix box bash would work, being this is a dotmatrix printer, doing image dumping will not work as well. It's a rough one for sure, I seen the activex controller that would do this exact thing I need, but a 1000 a year is not a solution it just another addition to a problem hehe ;) oh well I shall keep up on this and come back with something when I get it.
0
 

Author Comment

by:chaintm
ID: 34947662
What about changing the default printer of the user on the fly? Basicly I have scripts that can ID the default printer, can by pass the prompt, I am thinking when the user hits Complete the invoice a prompt follows with "would you like to change your default printer to (network printer)? Basicly using the vb to ID the current default printer on the user end and if it != then prompt for change by user?

While this basicly nills the idea of not seeing a printer choice come up, I think the client would be more accepting to a yes and no then choose from the list. After the user then prints the system resets the user default by another prompt if user = (network printer).

Basicly making it idiot proof so someone doesn't use the network printer for printing out say a map :) but only the invoices.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34947936
Might as well give it a try.  But you know what they say about idiots.  Making something idiot proof just breeds better idiots.
0
 

Accepted Solution

by:
chaintm earned 0 total points
ID: 34948177
lol true to that, this whole thing would not be such a big deal if there was option one or two, but the printer box for windows (while being simple enough) bothers the owners that in fact someone could "accidently" print on an invoice like google map. I get that but like you said, make is so idiot proff and you just breed more morons later.

Bah, well I am going to look at this more, I found some serve side print managers, so far thou, nothing that will capture a URL and allow me to select a printer that way after it's sent to the spool. Being this is an internal http://192.168.1.107/ address, figured I could capture by the URL in the browser then just print job that way. So far no luck, I am suprised all these years sense IE4, and no one has come up with an alternative other then pdf.

I will find it or make it one of the above, dot matrix doesn't handle the pdf or graphic formats well to do this job justice.
0
 

Author Comment

by:chaintm
ID: 35112238
that sums it up.
0
 

Author Closing Comment

by:chaintm
ID: 35145564
wasn't really solved, but I did solve it by a totally different means, using print spooling itself to deal with the issues while using css/vbscript/php/html to force print to the printer which is very doable btw even thou everyone says no.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

706 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

19 Experts available now in Live!

Get 1:1 Help Now