I need to convert .pdf -file to .zpl -label file for printing with zebra printers, but is this even possible?
The PDF comes in as a base64 encoded string, and somehow I need to output that as a .zpl -file.
I use PHP in my project, and I prefer the method in PHP, but basically any programming language is fine, as long as it gets the job done.
I was thinking about converting the PDF to image(which seems to be possible by quick googling), and then from image(PNG, JPG, etc.) to ZPL(which also seems to be ok by quick googling), but does anyone have any knowledge about this kind of operation or any insights before I start to do this? I'm on a tight schedule here, and I cannot afford any fruitless work.
Update 4.8.2016
I went the other way and created the ZPL from the scratch because it keeps our service faster than doing some conversions. So I don't have any more info on this than what the google already offers, if someone comes wondering about this same thing. PS. ZPL isn't that hard of a language. ;)
I had the some problem to solve: take a PDF file, convert it into ZPL code somehow and print it using a Zebra printer.
Thanks to stackoverflow and the ZPL Programming Guide, I learned about embedding bitmaps with the Graphic Field command (^GF).
Basically, you have to do these steps:
Render a PDF file as a bitmap
Make it monochrome
Convert the bitmap into ASCII hexadecimal (as defined by ZPL)
Compress the ASCII hexadecimal (otherwise our printers struggled with megabytes of bitmap data)
Put the data into this code template ^XA^GFA{some parameters and tons of bitmap data}^XZ
Our services were running on ASP.NET so I wrote a C# library to do just that. It wraps the native calls to Google's PDFium for rendering and returns a string with valid ZPL code for printing.
You could convert base64 encoded PDF files like that:
public static string GetZplCode(string pdfBase64, int page = 0, int dpi = 203)
{
return PDFtoZPL.Conversion.ConvertPdfPage(pdfBase64, page: page, dpi: dpi);
}
I hope this nuget package will prevent others from spending weeks in searching on how to make this ^GF command work.
Related
I have a PDF with some text in it that I would like to modify dynamically using PHP. This is being done already with another PDF, and what happens is that PHP simply replaces a token in the form %token% with another value pulled from a database. If you open that PDF in a text editor, you can find the %token% in plain text. But with this other PDF that I want to do the same thing with, if you open it in a text editor, there are no tokens in plaintext (even though I explicitly created one using Adobe Acrobat Pro). Obviously, the PDF's string content in this PDF is either encrypted, compressed, or both. What I want to know is how can I save a PDF so that the string content remains as plaintext such that PHP can manipulate it.
Please note, I do not want to dynamically create the whole PDF from scratch using some PHP library. I know that is something that can be done, but the PDF I am working with already exists and I just want to modify it slightly in the manner described.
For things like that I like to use the free command line tool PDFtk, which can compress / decompress PDFs and some nice thinks more. You may have a look at: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
PS: I edit a special pdf calendar form from the internet. I decompress it and replace the awful pink color for the weekend with gray (Saturday) and blue for Sunday. Violet I use as small bar to mark vacation days.
A mobile AIR app needs to send a large image to the back end for later display in a web page.
It takes for ever for PNGEncoder in the AIR app to complete, so the idea is to convert the image data to a ByteArray, compress it and send it to the PHP backend where it is saved as PNG by the PHP code. So I'm looking to port PNGEncoder.as and BitmapData class to PHP to accomplish this. I found PNGEncoder.as in as3corelib but can't find source for BitmapData class that it uses.
So the questions are
1. Is there code out there that does what I'm trying to do?
2. Where can I find BitmapData source code?
3. Is there another way to accomplish this that I'm missing?
Note1. I realize that I can decompile airglobal.swf where BitmapData resides, but looking for a cleaner way
Note2. I'm aware of AMFPHP but it does not support BitmapData type
Thanks
Andy
I see two solutions to this issue.
First, you can consider using a Worker to do just the conversion and sending routine, because image conversion is a pretty standalone and straightforward task to offload, and since most modern devices have more than one core anyway, it's better to put the hardware to work on the client rather than on server. Of course, you will have to take some measures to provide the worker instance with required data and to properly upload the image (cookies might not be handled well in a worker), but this approach is generally cleaner and requires no server side alterations.
The second approach is to use BitmapData.getPixels() to convert a region of pixels into a sequence of bytes, then send them unaltered to the server for conversion. Be warned however, the amount of data in a raw bitmap can be too large for the server to accept, you are looking to no less than 4 bytes per pixel, as bitmaps in AS3 are 32-bit. You can use a server side image encoder to convert raw data on the server after uploading.
I'm just wondering about a small problem I have. I'm creating a simple website with PHP, HTML and CSS. The user enters the dimensions of a rectangle into a form, and this all works perfectly. However, I'm unsure how to proceed.
The system should then use these dimensions (both stored as separate variables) to draw a rectangle of that size (in cm). The rectangle should be draw in a .pdf document, which the user can then download.
I'm a beginner, so sorry if there's anything wrong with this question.
You're going to want to start with looking into the html5 canvas element for drawing. There's plenty of tutorials online for you. As far as saving to pdf, see this: Convert canvas to PDF good luck.
Take a look at the fpdf extension available for php. Or even better and more consequent: use its unicode capable variant 'tfpdf'.
It allows you to generate a pdf document on the server side in a step by step way. You can control all details of that document. When finished you can return the document to the requesting client.
I find myself manually encoding background images in the css in base64 often.
When I mean manually, I mean that I encode the image, copy the resulting string, paste it into the css file and so on. This is stupid!
I came to the conclusion that writing a script in PHP or Python that does it automatically would not be difficult, it's just a matter of parsing the css, finding the image on the HD, encoding it in base64, replace the result with the original string in the css file and save a new file.
Then I thought: "how come nobody has already done this? Maybe it would be better to ask before doing it."
So here I am, does a similar solution exist?
Thanks
Well, Chris Coyer # CSS-Tricks published an article talking about Data URIs, where he explains how to use them and how they are useful. Near the end, he states that's it's very easy to generate those on the fly with PHP, like so
if you are using PHP (or PHP as CSS), you could create data URIs on the fly like this
<?php echo base64_encode(file_get_contents("../images/folder16.gif")) ?>
However, take not that you shouldn't use base64_encode on all images on a website. the size of the string generated by base64_encode is larger by about 33% of the original image. Data URIs are great when you have small pictures and you don't want to waste requests on them.
Does anyone know of a script, preferably PHP-based that will allow conversion of a static flash to an image?
As long as you're talking about converting a flash DisplayObject (which nearly everything in flash is) to a jpeg, as3 core libs has a fantastic jpeg exporter that I use on a regular basis. It sends the converted jpeg or png as raw post data, so you can pretty much do anything you want with it on the php side of things.
You can get the as3corelib package here: http://github.com/mikechambers/as3corelib - There's many many tutorials on getting the bitmap encoder up and running all over the web, and it's super simple, but if you need help with that I can help as well.