Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print PDF When Printer Does Not Support application/PDF #18

Closed
nawilson opened this issue Jul 23, 2015 · 8 comments
Closed

Print PDF When Printer Does Not Support application/PDF #18

nawilson opened this issue Jul 23, 2015 · 8 comments

Comments

@nawilson
Copy link

Hi,

Many of the printers that I am trying to connect to do not have support for the document-format "application/pdf". However, they all list the following document-formats as supported: "application/vnd.hp-PCL" and "application/octet-stream".

How I can print a PDF using IPP when the printer does not support application/pdf?

I have already tried switching the document-format to one of the supported options, but it does not print the expected output. Instead it prints some gibberish, and what looks like styling code.

var ipp = require('ipp');
var PDFDocument = require('pdfkit');

//make a PDF document 
var buffers = [];
var doc = new PDFDocument();
doc.fontSize(14);
doc.text("THIS IS A TEST PRINT JOB", 10, 10);

doc.on('data', buffers.push.bind(buffers)); 
doc.on('end', function() {
  var printer = ipp.Printer("http://myprinter/ipp");
  var msg = {
    "version": 1.1,
    "operation-attributes-tag": {
      "requesting-user-name": "testuser",
      "job-name": "Test7",
      // "document-format": "application/octet-stream"
      "document-format": "application/vnd.hp-PCL"
    },
    data: new Buffer(Buffer.concat(buffers))
  };

  printer.execute("Print-Job", msg, function(err, res) {
    console.log('Err: ' + JSON.stringify(err));
    console.log('Res: ' + JSON.stringify(res));
  });
});

doc.end();

Thanks

@lukas-zech-software
Copy link

@nawilson Did you find a solution to this problem?

@williamkapke
Copy link
Owner

I use PDF as an example because it is easy to work with- you can view it on your machine AND sent it to a printer. Some older printers and ones made by stubborn manufacturers can't process PDF. In my scenario- I only buy printers that support PDF. The other document types are too hard to work with.

So, for PCL variations, you will need a library that generates the Printer Control Language (PCL) data instead of PDF data.

Alternatively, you can look at using a CUPS server to handle it. HTH

@nawilson
Copy link
Author

@lukas-zech-software My solution was to convert the PDF documents to PCL via GhostScript and then send the PCL file to the printer.

@nathanhleung
Copy link

Setting "document-format": "application/octet-stream" worked for me. (for PDF)

@JayFang1993
Copy link

@nathanhleung could you show me your example code?

@nathanhleung
Copy link

@JayFang1993 I don't exactly remember what I was doing (this was over a year ago) but here's the repo with my code for my printer project: https://github.com/nathanhleung/print-anywhere

@lacmuch
Copy link

lacmuch commented Aug 28, 2020

Use https://github.com/Atlantis-Software/pclkit instead of pdfkit

PCL format is more standard

@sun4github
Copy link

Use https://github.com/Atlantis-Software/pclkit instead of pdfkit

PCL format is more standard

If the PCL document generation can read from a PDF and generate PCL, it will be awesome. I unfortunately do not see that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants