// Open a connection to PrintNode // You first need to establish a connection to PrintNode. // This can be done by using a PrintNode\ApiKey instance using your api-key. $credentials = new PrintNode\ApiKey(PRINTNODE_APIKEY); // Hint: Your API username is in the format description.integer, where description // is the name given to the API key when you created it, followed by a dot (.) and an integer. // All this information is provided for you when you create your API Key. // Step 3: Get a list of computers, printers or printjobs which are available. // To get a list of computers, printers or printjobs, create a new PrintNode\Request // object, passing it your credentials as the argument to it's constructor. $request = new PrintNode\Request($credentials); // Hint: Before you can get a list of computers or printers, you must have successfully // connected using the PrintNode Client software. If you have not yet connected with // the client software you will not receive any results from the API. // Call the getComputers, getPrinters() or getPrintJobs() method on the object: $computers = $request->getComputers(); $printers = $request->getPrinters(); $printJobs = $request->getPrintJobs(); // Hint: The return value from these methods is always an array containing 0 or more // instances of PrintNode\Computer, PrintNode\Printer or PrintNode\PrintJob depending // on the method called. You can iterate over this array however you please, for example // you might use a while or foreach loop. // Step 4: Send a PrintJob to Printnode. // PrintNode currently only accepts PDF documents. // To print something, you need to create a new instance of PrintNode\PrintJob: $printJob = new PrintNode\PrintJob(); // You can then populate this object with the information about the print-job // and add the base64-encoded content of, or the URI to your PDF. To do this use the properties // as defined on the object. // // In this example, we're going to print a a base64-encoded PDF named invoice.pdf:
/** * @depends testComputers * @depends testPrinters * @depends testPrintJobs * */ public function testPrintingCombination() { $request = new PrintNode\Request($this->credentials); $computers = $request->getComputers(); $PrintersByComputers = $request->getPrintersByComputers($computers[0]->id); $PrintJobsByPrinters = $request->getPrintJobsByPrinters($PrintersByComputers[0]->id); $this->assertEquals($PrintJobsByPrinters[0]->printer->id, $PrintersByComputers[0]->id); $this->assertEquals($PrintersByComputers[0]->computer->id, $computers[0]->id); }