Code Monkey home page Code Monkey logo

printnode-php's Introduction

PrintNode-PHP

PrintNode is a cloud printing services which allows you to connect any printer to your application using our PrintNode Client and easy to use JSON API.

See www.printnode.com for more information.

This quick start guide covers using the PHP API library. It shows how to find which Computers and Printers you have available for printing and how you can submit PrintJobs using the provided PHP API libraries.

Step 1: Sign Up

Before you can use the API, you will need to sign up to PrintNode account, and make a new API key. You can sign up here https://app.printnode.com/account/register

Step 2: Add a computer and printer

To have somewhere to print to you need to download and install the PrintNode desktop client on a computer with some printers. You can download the PrintNode Client installer here - www.printnode.com/download . It should be intuitive to setup but for more detailed instructions please see here: https://www.printnode.com/docs/installation/windows/ .

Step 3: Install library

Download the PHP Library

You can download the client from our Github account. If you have a git client installed locally, you can clone our repository

https://github.com/PrintNode/PrintNode-PHP/archive/master.zip

Install via composer

composer require PrintNode/printnode-php:dev-master

Step 4: See examples how to use this library

See examples directory to learn how to use this library.

printnode-php's People

Contributors

igormukhingmailcom avatar jbsiddall avatar joostfaassen avatar matthewjwbyrne avatar mattomlet avatar petertuthill avatar printnode-jake avatar printnodeltd avatar t-oates avatar tomaszdurda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

printnode-php's Issues

USB weighting scales bugs in code : 2 files to fix

Hi,

to be able to read a USB scale, i had to fix 2 files from your sources ๐Ÿ‘

1st is Request.php, at line 492

public function getScales(string $computerId)

changed to

public function getScales($computerId)

And 2nd file is Scale.php, at line 32

protected $clientReprotedCreateTimestamp;

changed to

protected $clientReportedCreateTimestamp;

(reported and not reproted)

Thomas.

Printing On PHP

Hi, I'm so facinated with this API, I've read all about it, I just want to print from my APP WEB and I think that this can help me, but, firstly I need to know something else:

Context Software
My system basically takes the register of a person, with his personal data.

  • ID
  • Name
  • LastName
  • HourRegister
  • DateRegister
  • Barcode (ID)
  • And the place that he goes, and with the label from my Dymo I print that data on it!

How I'm Doing The Printing For My Software
Actually my software is in production, and the printing proccess is with the preview printing from the navigator and what I need is for it to always be printed.

  • My Label is designed with HTML and that section is printed.
  • With the method window.print()

Why I'm here?

  • Because I need to know if the label was printed or not, and, with the preview printed I can press the button Cancel and only register the people without the label and the Label is my obvjective.

Label

  • 30256 Shipping

Questions

  1. Is it necessary that will be printed on PDF?
  2. If that is false, how can I create my Label?
  3. In production I have 3 PC's, so, I need to one account for everyone or ?
  4. What is wrong with this code, I've prove with some examples and it doesn't work!

CODE

` <?php
include 'PrintNode/Loader.php';

$credentials = new PrintNode\Credentials('xxxxx.xxxxxx',
'xxxxxxxxxxxxxxxxxxxx');
$credentials->setApiKey(PRINTNODE_APIKEY);
$request = new PrintNode\Request($credentials);

// Initialise a Child Account

$account = new PrintNode\Account();
// Set properties on the Child Account
$account->Account = array(
"firstname" => "11",
"lastname" => "111",
"password" => "111111",
"email" => "[email protected]"
);
// Post the Child Account to the API
$aNewAccount = $request->post($account);
// You can get the Child Account ID from the response object
$id = $aNewAccount->GetDecodedContent()["Account"]["id"];
?>`

RESULT

Fatal error: Class 'PrintNode\Entity' not found in C:\xampp\htdocs\Prueba\Code\PrintNode\Account.php on line 15

get() method missing in Request class

PrintNode\Request needs a get() method like the existing analogues for post(), put(), patch(). Without it, endpoints which require GET can't be used. For example, you can't use PrintNode\Whoami().

Copy/pasting the the put() method with just a change from PUT to GET in the call to curlSend() works.

how to use it in laravel ?

hi , i have some problem when i use in laravel
i copy the source code from example-1-submitting-a-printjob
and i already change the API key but i still have errors

Argument 1 passed to PrintNode\Request::__construct() must be an instance of PrintNode\Credentials, instance of PrintNode\ApiKey given, called in /Users/tatsuo769/Sites/sushi/app/Http/Controllers/PrintNodeController.php on line 16 and defined


$credentials = new PrintNode\ApiKey(
'xxx.xxx'
);
$request = new PrintNode\Request($credentials);

$computers = $request->getComputers();
$printers = $request->getPrinters();
$printJobs = $request->getPrintJobs();

$printJob = new PrintNode\PrintJob();

$printJob->printer = $printers[1];
$printJob->contentType = 'pdf_base64';
$printJob->content = base64_encode(file_get_contents('a4_portrait.pdf'));
$printJob->source = 'My App/1.0';
$printJob->title = 'Test PrintJob from My App/1.0';

Please tag a version number

Hi,

I've been using this module for nearly a year and found it to work quite well without any issue.

Could you tag the repository with a version number so that we don't have to require dev-master any longer.

I'm using this in a large project and this is the only non-stable package requirement so I would prefer if I didn't have to use minimum stability dev and prefer stable in my composer settings.

How to set printjob options?

Doc reference: https://www.printnode.com/docs/api/curl/#printjob-options

Hello PrintNode-Team,

I was trying to set the "copies" option of my printjob-object,
but since it doesn't seem to have a property called options,
an error is thrown by the Entity class:
'PrintNode\PrintJob does not have a property named options'.

So my question is: how do you set options for your printjobs?
(Other attributes like qty are missing too: https://www.printnode.com/docs/api/curl/#printjob-creating)

Used Branch: dev-master

Edit: Looking through the other branch(release/2.0.0), I saw that the PrintJob class seems to have those properties, but the readme files on both branches tell me to get 'dev-master', so am I using the wrong branch?

Regards,
Marcus Wanka

Error in Example 1 (with PR)

Example 1 has an error, attached PR will fix it. #36

Fatal error: Uncaught TypeError: Argument 1 passed to PrintNode\Request::__construct() must be an instance of PrintNode\Credentials, instance of PrintNode\ApiKey given, called in my-file.php on line 13 and defined in vendor/printnode/printnode-php/src/PrintNode/Request.php:85

Stack trace:
#0 /var/www/vhosts/shakepack.co.uk/public/printnode.php(13): PrintNode\Request->__construct(Object(PrintNode\ApiKey))
#1 {main} thrown in /var/www/vhosts/shakepack.co.uk/vendor/printnode/printnode-php/src/PrintNode/Request.php on line 85

InvalidArgumentException: Missing endPointUrl for entityName "PrintNode\Scale"

Activating the virtual scale using PrintNode-PHP results in an InvalidArgumentException: Missing endPointUrl for entityName "PrintNode\Scale"

Testcode:
$credentials = new \PrintNode\Credentials ();
$credentials->setApiKey ( ... );
$request = new \PrintNode\Request ( $credentials );
$scale = new \PrintNode\Scale ();
$scale->deviceNum = 0;
$scale->deviceName = 'PrintNode Test Scale';
$scale->computerId = 0;
$request->put ( $scale );//This results in InvalidArgumentException: Missing endPointUrl for entityName "PrintNode\Scale"

Solution:
in class Request: add endPointUrl: PrintNode\Scale

private $endPointUrls = array(
    'PrintNode\Client' => '/download/clients',
    'PrintNode\Download' => '/download/client',
    'PrintNode\ApiKey' => '/account/apikey',
    'PrintNode\Account' => '/account',
    'PrintNode\Tag' => '/account/tag',
    'PrintNode\Whoami' => '/whoami',
    'PrintNode\Computer' => '/computers',
    'PrintNode\Printer' => '/printers',
    'PrintNode\PrintJob' => '/printjobs',
    
    'PrintNode\Scale' => '/scale',
);

Setting PrintJob options

Hello Print-node team,
I'm trying to specify some options properties in the PrintJob object and can't get it working. What is the correct syntax for specifying bins and number of copies in a PrintJob?
Is there an example of this available?

I'm using release/2.0.0

Solved:
$printJob->options = array('bin' => 'Tray 2', 'copies' => 2);

error for updating

Hello guys, i use printnode in my project, some of our clients use it.

This morning I started to get this error when I try to update my composer... Has anything changed?

Failed to clone the [email protected]:PrintNode/PrintNode-PHP.git repository, try running in interactive mode so that you can enter your GitHub credentials

In my composer I requiere

"printnode/printnode-php": "dev-master" and i have configured a vcs repo

"repositories": [
{
"type": "vcs",
"url": "https://github.com/PrintNode/PrintNode-PHP"
}
]

PHP8 Warnings

Deprecated: ctype_digit(): Argument of type int will be interpreted as string in the future in /src/PrintNode/Request.php on line 316

Deprecated: ctype_digit(): Argument of type int will be interpreted as string in the future in /src/PrintNode/Request.php on line 329

No Printer found

I have installed this package and set api key in config. Printnode client software also installed and logged in with api key.

Printer is connected and showing active with online status on Printnode Client software.

But from code there is no printer id or name listing, it's all null.

$printers = Printing::printers(); foreach ($printers as $printer) { echo $printer->name(); }

Any help?

PHP Example 4 help text is wrong

The PHP comment and execution in Example 4 is incorrect:

  • We've set the first two arguments on the method in order to limit the amount
  • of records returned. The second argument is the number of records to retrieve
  • (10 in this case) and the first is the record to start on.
    $printJobs = $client->viewPrintJobs(0, 2);

This should say:

  • We've set the first two arguments on the method in order to limit the amount
  • of records returned. The first argument is the number of records to retrieve
  • (2 in this case) and the second is the record to start on.
    $printJobs = $client->viewPrintJobs(2, 0);

Support Offer

OFFER to the organiser of this repository.

I would like to keep using this library for my job but. I work with several PrintNode accounts across several smaller and bigger companies.

I'd like to offer my support free of charge to clean up this PHP repository. I'd like to get it into a shape so that the users can use this library again across several PHP versions.

If this offer sounds interesting to you, please get in touch with me.

Composer signature in readme has uppercase characters

Composer is giving me this warning:

Deprecation warning: require.PrintNode/printnode-php is invalid, it should not contain uppercase characters. Please use printnode/printnode-php instead. Make sure you fix this as Composer 2.0 will error.

I notice that you have it configured correctly in composer.json and therefore packagist as well. It's just a matter of updating your readme to use lowercase characters so that people who copy and paste will not make the same mistake that one of our devs made.

https://github.com/PrintNode/PrintNode-PHP/blob/master/README.md#install-via-composer

Is currently:

composer require PrintNode/printnode-php:dev-master

Needs to be:

composer require printnode/printnode-php:dev-master

Thanks

Is this maintained?

I am working with a company whose exploring installing PrintNode on its facilities. PHP is the language in use. The website does a good presentation and gives positive impression. It's obviously a paid product. However a this repository seems to not be maintained anymore. This is not acceptable for a paid product.

So how is it?

$printJob->options , What all values can be passed on this

Hi,

We need to know what all values can be passed on this options tag in PHP

$printJob->options

Example.
$printJob->options = '{"copies":2,"papers":"200,1600"}';

Is this possible or how to do this thing, we are shifting from Google Print, since those people are just shutting down, I think Google better shutdown.

--- I had found how to do the options part,

Printnode Timeout

curl_setopt($curlHandle, CURLOPT_TIMEOUT, 4);

Error message
RuntimeException: Uncaught exception 'RuntimeException' with message 'cURL Error (28): Operation timed out after 4000 milliseconds with 0 bytes received' in /var/www/html/vendor/printnode/printnode-php/src/PrintNode/Request.php:205

Setting Id to getPrinters

We're trying to use PrintNode as a hub on our web projct. Each user's default printer is recorded onto DB and we would like to call this printer directly.

However, getPrinter lists all printers and I have to select inside it. Instead of that, it should be like "getPrinters(123456)" and only printer with id :123456 may be detailed.

Thanks.

Package Naming Issue

When doing composer updates we get the following error:

Deprecation warning: require.PrintNode/printnode-php is invalid, it should not contain uppercase characters. Please use printnode/printnode-php instead. Make sure you fix this as Composer 2.0 will error.

PHP 8.2 Deprecated (Creation of dynamic property)

I get these warnings when using.

$printers = $client->viewPrinters();

Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$A3 is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$A4 is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$A5 is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$B4 (JIS) is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$B5 (JIS) is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$Executive is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$Legal is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$Letter is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$Statement is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$Tabloid is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$48mm x 200mm is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$48mm x Receipt is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29
Deprecated
: Creation of dynamic property PrintNode\Entity\PrinterCapabilities\Papers::$50.8mm x 200mm is deprecated in
/var/www/html/inc/lib/PrintNode/EntityDynamic.php
on line
29

$this->$propertyName = $value;

Library no longer works with PHP7.4

The 'mixed' pseudotype is used in the last commit, seemingly added for PHP8 compatibility. This is not available in PHP7.4 and throws a fatal error.

This caused all of our client's applications to break. Therefore, we are moving away from this PHP library since it's not reliable.

To improve in the future:

  • please create releases so we users have control over which version we are using. Using dev-master in composer.json is not acceptable for any kind of production environment;
  • please test in all supported versions of PHP before putting out a new release.

createPrintJob can return object, but code to get object is incorrect

if ($returnObject) {
            return $this->viewPrintJobs(0, 1, $this->lastResponse->body);
        }

The code for getting the object for createPrintJob's response uses viewPrintJobs, but the first argument is 0, and the code inside viewPrintJobs requires the value to be greater than or equal to 1

Offset and Limit does not work in client

You can set the limit and offset per Request, but it is not used. So you cannot get page 2 of the results.

There is a Reqeust->applyOffsetLimit() method, but that is not used in the client.

Can we print a Contents of URL

Hi, We were using Google Cloud Print, So can we know how can we print the contents of URL in PrintNode.

We see PDF as preferred, so can we know how to print the contents in URL

Errors coming back from API are not passed on by Request::__call()

Using this PHP SDK, I had a customer who was getting back an HTTP 403. That's all the information that could be learned by catching the RuntimeException.

But tinkering inside Request::__call(), I was able to discover that PrintNode was also sending back a useful body:

string(202) "{
  "code": "Forbidden",
  "message": "Your VAT information is inconsistent or incomplete.  Please log in to your account control panel and fix this",
  "uid": "42..."
}

It would be good if that information was obtainable by the consumer, rather than dropped.

Print job options for color

Is there any way to set the print job options color to either true or false. By default the color setting is based the printer capabilities. I have read the API References and there seems to be no way of changing the color option.

Not able to print by given example - 1

Hi Support Team,

I have used your given instruction in example code, I am getting below error.

Catchable fatal error: Argument 1 passed to PrintNode\Request::__construct() must be an instance of PrintNode\Credentials, instance of PrintNode\ApiKey given, called in /var/www/html/printnode/examples/example-1-submitting-a-printjob.php on line 28 and defined in /var/www/html/printnode/examples/vendor/printnode/printnode-php/src/PrintNode/Request.php on line 85

But i fixed it by adding below code.
$credentials = new PrintNode\Credentials();
$credentials->setApiKey(PRINTNODE_APIKEY);

After added this code, I am getting another error:

Fatal error: Uncaught exception 'RuntimeException' with message 'HTTP Error (401): Unauthorized' in /var/www/html/printnode/examples/vendor/printnode/printnode-php/src/PrintNode/Request.php:597 Stack trace: #0 /var/www/html/printnode/examples/example-1-submitting-a-printjob.php(39): PrintNode\Request->__call('getComputers', Array) #1 /var/www/html/printnode/examples/example-1-submitting-a-printjob.php(39): PrintNode\Request->getComputers() #2 {main} thrown in /var/www/html/printnode/examples/vendor/printnode/printnode-php/src/PrintNode/Request.php on line 597

Please let me know what i am doing wrong and how cloud i run my basic example code.

Thanks
Lokendra Meena

License is not mentioned

There is no license mentioned in the library, so it is unclear how this code may be used.

Since there is nothing special about this library, I would suggest MIT license.

It is important to mention how this code is licensed, so it can be safely used in other apps.

Color printing

Hi there, :)
I've set the default color profile on the "Printer Preferences" to COLOR and not Black & White.
Printing in color now happens automatically. However, I would like to print some documents in B&W and save money.
For the PHP options, I am using:

$options = new stdClass();
$options->bin = 'Tray 2';
$options->color = false;

This successfully prints from Tray 2 (which is not the default).
How can I get it to print B&W? What am I doing wrong?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.