Re: PHP to access shell script to print barcodes
| From: | Rob Gould | Date: | Wed, 24 Mar 2010 05:09:05 +0000 |
| Subject: | Re: PHP to access shell script to print barcodes | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303173@lists.php.net to get a copy of this message | ||
Well, that did something, and it does sound like it should work. I've scoured the web and
haven't found anyone with code that does what I'm trying to do.
I've got a working, hardcoded Postscript file here:
http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps
But I need to somehow serve it with PHP, so I can change some variables in it.
By putting headers in place with PHP, and then doing an "echo" of the postscript, I get
postscript errors (though Preview doesn't tell me what the error is):
http://www.winecarepro.com/kiosk/fast/shell/serverps.ps
Trying to trick the web-browser into thinking it's receiving Postscript from a PHP file is
tricky. I don't know what to do next.
Here's the code I was using in the above url: http://www.winecarepro.com/kiosk/fast/shell/serveps.php.zip
It's not clear to me if the server is parsing the postscript first and then serving it, or if
the server is server the postscript as-is and the browser sends it to Preview which interprets it.
I basically want to replicate the functionality found here:
http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/
On Mar 23, 2010, at 5:37 PM, Peter Lind wrote:
> You can create a .php script that sets a proper header to make the
> browser download the file rather than display it. That also allows you
> to set the filename for the download. What you'd need to do is include
> something like:
>
> header("Content-Disposition: attachment; filename: 'barcodemerge.ps'");
>
> That tells the browser to download the file. You can also try setting
> the content-type
>
> header('Content-type: application/postscript');
>
> Either of the above might do the trick for you.
>
> Regards
> Peter
>
> On 23 March 2010 22:10, Rob Gould <gouldimg@me.com> wrote:
>> I love the idea of using PHP to insert data into Postscript. I'm just not sure how to
>> make it happen.
>>
>> The good news is that I've got barcodes drawing just the way I need them:
>>
>> http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps
>>
>> The bad news is that's all hard-coded Postscript. I'd like to take your
>> suggestion and use PHP to loop-through and draw the barcodes - - - however, if I put anything that
>> resembles PHP in my .ps file, bad things happen.
>>
>> Anyone know the secret to creating a postscript .ps file that had PHP code injecting data
>> into it?
>>
>> Here's the source file that works. Where PHP would be handy is at the very bottom of
>> the script....
>>
>>
>> http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps.zip
>>
>>
>> On Mar 23, 2010, at 7:48 AM, Richard Quadling wrote:
>>
>>> On 23 March 2010 05:48, Jochem Maas <jochem@iamjochem.com> wrote:
>>>> Op 3/23/10 3:27 AM, Rob Gould schreef:
>>>>> I am trying to replicate the functionality that I see on this site:
>>>>>
>>>>>
>>>>> http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/
>>>>>
>>>>> Notice after you hit SUBMIT QUERY, you get a PDF file with a page of barcodes.
>>>>> That's _exactly_ what I'm after.
>>>>> Fortunately, the author gives step-by-step instructions on how to do this on
>>>>> this page:
>>>>>
>>>>>
>>>>> http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/
>>>>>
>>>>>
>>>>> So I've gotten through all the steps, and have created the
>>>>> "barcode_with_samples.ps" file, and have it hosted here:
>>>>>
>>>>> http://www.winecarepro.com/kiosk/fast/shell/
>>>>>
>>>>> Notice how the last few lines contain the shell-script that renders the
>>>>> postscript:
>>>>>
>>>>> #!/bin/bash
>>>>>
>>>>> BASE=”100″;
>>>>> NR=$BASE
>>>>>
>>>>> for hor in 30 220 410
>>>>> do
>>>>> ver=740
>>>>> while [ $ver -ge 40 ];
>>>>> do
>>>>> printf -v FNR “(%06dL3)” $NR
>>>>> echo “$hor $ver moveto $FNR (includetext height=0.55) code39 barcode”
>>>>> let ver=$ver-70
>>>>> let NR=NR+1
>>>>> done
>>>>> done
>>>>>
>>>>>
>>>>> I need to somehow create a PHP script that "executes" this shell
>>>>> script. And after doing some research, it sounds like
>>>>> I need to use the PHP exec command, so I do that with the following file:
>>>>>
>>>>>
>>>>> http://www.winecarepro.com/kiosk/fast/shell/printbarcodes.php
>>>>>
>>>>> Which has the following script:
>>>>>
>>>>> <?php
>>>>>
>>>>>
>>>>> $command="http://www.winecarepro.com/kiosk/fast/shell/barcode_with_sample.ps";
>>>>> exec($command, $arr);
>>>>>
>>>>> echo $arr;
>>>>>
>>>>> ?>
>>>>>
>>>>>
>>>>> And, as you can see, nothing works. I guess firstly, I'd like to know:
>>>>>
>>>>> A) Is this PHP exec call really the way to go with executing this shell
>>>>> script? Is there a better way? It seems to me like it's not really executing.
>>>>
>>>> that's what exec() is for. $command need to contain a *local* path to the
>>>> command in question, currently your
>>>> trying to pass a url to bash ... which obviously doesn't do much.
>>>>
>>>> the shell script in question needs to have the executable bit set in order to run
>>>> (either that or change to command to
>>>> run bash with your script as an argument)
>>>>
>>>> I'd also suggest putting the shell script outside of your webroot, or at least
>>>> in a directory that's not accessable
>>>> from the web.
>>>>
>>>> --
>>>> PHP General Mailing List (http://www.php.net/)
>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>
>>>>
>>>
>>> I think this is a translation of the script to PHP.
>>>
>>> <?php
>>> $BASE = 100;
>>> $NR = $BASE;
>>>
>>> foreach(array(30, 220, 410) as $hor) {
>>> $ver = 740;
>>> while ($ver >= 40) {
>>> printf("$hor $ver moveto (%06dL3) (includetext height=0.55) code39
>>> barcode\n", $NR);
>>> $ver -= 70;
>>> ++$NR;
>>> }
>>> }
>>>
>>>
>>>
>>> It produces output like ...
>>>
>>> 30 740 moveto (000100L3) (includetext height=0.55) code39 barcode
>>> 30 670 moveto (000101L3) (includetext height=0.55) code39 barcode
>>> 30 600 moveto (000102L3) (includetext height=0.55) code39 barcode
>>> 30 530 moveto (000103L3) (includetext height=0.55) code39 barcode
>>> 30 460 moveto (000104L3) (includetext height=0.55) code39 barcode
>>> 30 390 moveto (000105L3) (includetext height=0.55) code39 barcode
>>> 30 320 moveto (000106L3) (includetext height=0.55) code39 barcode
>>> 30 250 moveto (000107L3) (includetext height=0.55) code39 barcode
>>> 30 180 moveto (000108L3) (includetext height=0.55) code39 barcode
>>> 30 110 moveto (000109L3) (includetext height=0.55) code39 barcode
>>> 30 40 moveto (000110L3) (includetext height=0.55) code39 barcode
>>> 220 740 moveto (000111L3) (includetext height=0.55) code39 barcode
>>> 220 670 moveto (000112L3) (includetext height=0.55) code39 barcode
>>> 220 600 moveto (000113L3) (includetext height=0.55) code39 barcode
>>> 220 530 moveto (000114L3) (includetext height=0.55) code39 barcode
>>> 220 460 moveto (000115L3) (includetext height=0.55) code39 barcode
>>> 220 390 moveto (000116L3) (includetext height=0.55) code39 barcode
>>> 220 320 moveto (000117L3) (includetext height=0.55) code39 barcode
>>> 220 250 moveto (000118L3) (includetext height=0.55) code39 barcode
>>> 220 180 moveto (000119L3) (includetext height=0.55) code39 barcode
>>> 220 110 moveto (000120L3) (includetext height=0.55) code39 barcode
>>> 220 40 moveto (000121L3) (includetext height=0.55) code39 barcode
>>> 410 740 moveto (000122L3) (includetext height=0.55) code39 barcode
>>> 410 670 moveto (000123L3) (includetext height=0.55) code39 barcode
>>> 410 600 moveto (000124L3) (includetext height=0.55) code39 barcode
>>> 410 530 moveto (000125L3) (includetext height=0.55) code39 barcode
>>> 410 460 moveto (000126L3) (includetext height=0.55) code39 barcode
>>> 410 390 moveto (000127L3) (includetext height=0.55) code39 barcode
>>> 410 320 moveto (000128L3) (includetext height=0.55) code39 barcode
>>> 410 250 moveto (000129L3) (includetext height=0.55) code39 barcode
>>> 410 180 moveto (000130L3) (includetext height=0.55) code39 barcode
>>> 410 110 moveto (000131L3) (includetext height=0.55) code39 barcode
>>> 410 40 moveto (000132L3) (includetext height=0.55) code39 barcode
>>>
>>>
>>> No idea if that is accurate or not. If you can run the script by hand
>>> once to confirm, then
>>> --
>>> -----
>>> Richard Quadling
>>> "Standing on the shoulders of some very clever giants!"
>>> EE : http://www.experts-exchange.com/M_248814.html
>>> EE4Free :
>>> http://www.experts-exchange.com/becomeAnExpert.jsp
>>> Zend Certified Engineer :
>>> http://zend.com/zce.php?c=ZEND002498&r=213474731
>>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
> --
> <hype>
> WWW: http://plphp.dk /
> http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> Flickr: http://www.flickr.com/photos/fake51
> BeWelcome: Fake51
> Couchsurfing: Fake51
> </hype>