Closed dakira closed 10 years ago
That's a cool feature. How do you create the barcodes? PHP library? Web service?
I think it is too specific in order to be included in the standard PDF engine. But maybe we can include PDF engines with more features in the Engine folder? We just have to decide whether we include these PDF engines in the system configuration or if we just ship them and document it in the README...
Please make sure to send the pull request for the development branch, not for the master branch.
We had the same discussion with Admin_Logger and if you ask me, just put them all in one module. makes it a little bigger, but far easier to install.
@Schrank so you think it should also be a PDF engine which can easily be activated in the admin configuration? Could you provide a link to the Admin_Logger discussion?
I think we had the discussion only verbal... The problem is to have the core extension up to date what other engines are out there and the ppl don't read readme files, therefore they will never know what great features can be added :-(
@sprankhub I'm currently using php-barcode as it's small and dead easy. The file just needs to live somewhere on the server where it is web-accessible. I buffer the barcode-image in a temp dir because Zend only supports inluding actual files in a PDF and not URLs. I'll prepare something for a pull request in the coming days. Here's a preview of my awfully hacked version:
protected function insertBarcode(&$page, $order){
$maxwidth = ($this->margin['right'] - $this->margin['left']);
$maxheight = 30;
$code = $order->getRealOrderId();
$imgurl = $_SERVER['SERVER_NAME']."/barcode.php?size=40&text=".$code;
$imagePath = sys_get_temp_dir() . '/' . $code . '.png';
file_put_contents($imagePath, file_get_contents($imgurl));
list ($width, $height) = Mage::helper('firegento_pdf')->getScaledImageSize($imagePath, $maxwidth, $maxheight);
if (is_file($imagePath)){
$image = Zend_Pdf_Image::imageWithPath($imagePath);
$position['x1'] = $this->margin['right'] - $width;
$position['y1'] = 720;
$position['x2'] = $position['x1'] + $width;
$position['y2'] = $position['y1'] + $height;
$page->drawImage($image, $position['x1'], $position['y1'], $position['x2'], $position['y2']);
} else die($imagePath);
unlink($imagePath);
}
I added this to the Abstract.php in Model/Engine and called it from the appropriate place in the invoice. The barcode.php currently lives in the server-root. I'm not sure on how to go about including it while still having it accessible. Maybe I just get what I need out of it and put it in Helpers.
@dakira thanks. For your pull request, make sure to create another engine which can be activated in the admin panel. And make sure to create it based on the development branch ;)
I think it should be a completely different engine since it is a rather rare requirement. If there are any other opinions on that, please comment @Schrank.
Why not just add a flag like the ones that show the order number on the invoice? (discuss in #magento-de?)
Barcode is a special Feature, i think own Engine is the better way
I have to admit that @dakira convinced me that it is not really so special. Barcodes on these PDFs can massively improve the packing process (barcode scanner at printing machine can be used in order to automatically print shipping labels etc). Hence, I vote for an option.
Couldn't we dispatch a custom event which can be observed by developers to inject their custom features which they want to print on the PDF?
With this event, it would also make sense to support some custom features (like the barcode) out of the box but implemented via observer rather than implementing it in the our core pdf implementation.
great idea and then we comment the observers, so they can copy the code in their own config.xml
LIKE :+1:
We still would have to decide whether we want to support a custom feature out of the box or not, though. Nonetheless, it would give us and the developers an enormous flexibility for adding custom features without always modifying our core pdf implementation.
This is already possible for the notes section as described in the Wiki. Do you think there should be other places where it should be possible to add content via observers? Other places are far more layout-critical, so that I think we should not provide any more possibilties.
Anyway, it is a good idea to implement the barcode feature as a configurable observer which adds the barcode to the notes section. Although I think that at the moment one can only add plain text...
We can think of a general event which makes it possible to add thinks with x and y. So one can add the barcode in the empty upper right corner for example.
But whatever people will add, if they have the possibility to pass x and y with it, they can do whatevery they want in their personal pdfs.
Since people cannot move other elements around, the advantage of such an event may be negligible. But since I do not see any disavantage of this approach, we can provide such an event.
@dakira You want to place the barcode at the same location as on the screenshot?
Right now I just add the barcode in Model/Engine/Invoice/Default.php like this:
/* add logo */
$this->insertLogo($page, $invoice->getStore());
/* add barcode */
$this->insertBarcode($page, $order);
With a hardcoded position on the right side of the logo as seen in the screenshot and code above. This wouldn't work of course, if the logo were centered or aligned to the right. A barcode in the notes-area would beat the purpose of barcodes because it would often not be easily accessible (on multi-page invoices). Another suitable area would be to the right of the document title (Invoice). Or maybe add a vertical barcode on the very right or left side of the document.
@sprankhub It's a good place as it is unused for me (I align the logo to the left). Having the option to display it on any x/y coordinates would be fine for me.
Alright guys, what do you think? https://github.com/firegento/firegento-pdf/commit/38ca9d327e7652c3f8dfd9bb999861328e1a6adf Just tested it and it works great. Here is the documentation which shows how it works: https://github.com/firegento/firegento-pdf/wiki#how-can-i-put-some-fancy-stuff-wherever-i-want-to-without-writing-my-own-engine
@dakira I like the idea to put the barcode vertically on the very right or left side of the document...
Do we know which page it is? If not, it should be passed to the observer as well.
You are probably interested in the page number of one current order/invoice. But this is quite difficult, because there is only a pagecounter for the whole PDF. Since people can print multiple invoices at once, the page number of the whole PDF does not help. I do not know if we should make the effort to implement a "current order page number" just for this event...
Fortunately, Zend framework already has a barcode component, which I used now. Feedback welcome, but I think this discussion can be closed now.
Hey. This is great! Just came back from my extended holiday to this. Nice job. I'm currently working of creating a plugin with the rest of the workflow. Look forward to collaborate on that.
@dakira: IRC? I already implemented a lot of stuff :D
I needed barcodes with the order increment_id on my invoices. So I hacked this directly into the invoices.
Now that it works I thought this could be a feature other people might want. Maybe configurable: on which documents does the barcode appear, what information does it contain, which barcode standard should be used.
Should I clean up, what I got or do you thing this is too much for this extension?