Open rclai opened 10 years ago
Did you try type: 'PDF'
instead of type: 'RAW'
?
What OS do you use?
Yes, tried PDF, and it threw error because it is not compatible. I'm on Windows 7 Professional.
on windows is not yet supported. You can send RAW/TEXT data only. Feel free to propose PDF support on windows. Originally this code was created to communicate with printer directly (Zebra barcode printer).
Any news? Or is there a way to print html using node-webkit?
good link to start is: https://msdn.microsoft.com/en-us/library/windows/desktop/dd145226(v=vs.85).aspx
This link claims that a PDF can be printed with the seemingly similar approach utilised by the Windows version of node-printer
: https://vishalsbsinha.wordpress.com/2014/05/06/how-to-programmatically-c-net-print-a-pdf-file-directly-to-the-printer/.
It depends on the printer and processor format. I tried on my printer and it is not possible.
The code from the link just read the file bytes and sends it to printer as RAW
type.
Here's an example of how to do this from Chromium. See RenderPDFPageToDC
by that link. Do you think this might be the way to go for the module? I am actually using it in node-webkit environment, which indeed has the pdf.dll
shipped with it on Windows, so some integration on that end is possible.
What are your thoughts on how this should be implemented @tojocky?
From the code I see it transform the PDF format into EMF format. Technically it is possible, but not sure if it worth to import the whole library of PDFium. The library contains more than transforming PDF format into EMF.
Yeah, here is what I meant. Anyways, to print a PDF on Windows we definitely need a tool to render it, so unless this library is used, we will need to find another one.
Another approach that I came across now is rather a workaround — why don't we allow printing images on Windows, and then printing a PDF will be a 2 step process, one of which is PDF rasterization that can be done elsewhere. What do you think @tojocky?
I did some investigation and you are right. PDFium seems to be the only reliable solution. Other solutions like imagemagick, require more dependencies (postscript) and does not work properly in the end.
I will reconsider the PDFium project to be included in node-printer or to create as a separate node package. Thanks for this.
I have good progress. I managed to link pdfium to node/iojs and render PDF to PNG and PPM on both systems. It remains to render to EMF, BMP for windows. will upload the pdfium binding to https://github.com/tojocky/node-pdfium once I it is finished.
Done.
Will ad here an example.
feel free to test.
does this also support sending base64 data or a canvas image ? (windows)
You can send buffer, why do you want to send base64? What do you mean by canvas? EMF is a canvas, by using node-pdfium can be converted from a PDF format.
Nice work @tojocky! Have you already tried to actually print a PDF via a combination of node-pdfium and node-printer and possibly got a working example? Also, is there a way to pass a dpi
value for rendering?
Also, on a side note, I posted a feature request to NW repo too and it was confirmed that this will be supported in NW 0.13 or earlier, too: https://github.com/nwjs/nw.js/issues/3240.
I tested on windows to save the EMF file and it does OK, I could open to see it. Regarding DPI, I didn't do yet, I've seen chromium has something on this but needs more investigation. I tried to send EMF format to printer, but still don't have the desired result, even the saved file I could open and see it. I will update here, once I have good result.
Somebody can test this code on windows 7/8?
I have a virtual windows 10 and seems EMF is removed.
Instead I have the following formats: NT EMF 1.003
, NT EMF 1.006
, NT EMF 1.008
, NT EMF 1.008
. I tried these but no luck. The generated EMF file I could open and see it.
The following piece of code:
var pdfium = require('pdfium'), // in your case require('pdfium');
util = require('util'),
fs = require('fs'),
path = require('path'),
os = require('os'),
util = require('util'),
printer,
options = {
data: fs.readFileSync(path.join(__dirname, 'pdf-sample.pdf')),
outputFormat: process.argv[2] || 'EMF' // could be a item from pdfium.getSupportedOutputFormats();
},
printerType = process.argv[3] || options.outputFormat;
try {
printer = require('printer');
} catch (err) {
return console.log('please install printer module `npm install printer`');
}
var supportedPrintFormats = printer.getSupportedPrintFormats();
if(supportedPrintFormats.indexOf(printerType) == -1) {
return console.log('unsupported format ' + options.outputFormat + '. please select one of:' + util.inspect(supportedPrintFormats, {colors: true}));
}
console.log('converting PDF to ', options.outputFormat);
//async
console.log('run async');
pdfium.render(options, function(err, pages) {
if(err) {
return console.error('error from async convert: ', err);
}
console.log('start printing');
var i, processing = 0,
endProcessing = function() {
--processing;
if(processing <= 0) {
console.log('finished');
}
};
for(i = 0; i < pages.length; ++i) {
console.log('print page ' + i);
var page = pages[i];
printer.printDirect({
data: page,
type: printerType,
success: function(id) {
console.log('sent to printer with ID:' + id);
endProcessing();
},
error: function(err) {
console.log('error from printer:' + err);
endProcessing();
}
})
}
})
I can try this later in the week @tojocky
@tojocky i am currently trying to get this to work on Windows 7 and mac and seem to be running into a lot of issues trying to install node-pdfium.
On windows : Mainly cannot find some .h files in /third_party/pdfium
On Mac:
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/javascript/third_party/pdfium/fpdfsdk/src/javascript/app.o] Error 1
It fails during node-gyp rebuild
on both platforms for me. Do you want me to give you the npm-debug.log
?
FYI : I have Visual Studio 2012 installed on windows 7
What header files are missing?
@tojocky heres the full traceback. It says multiple times that the headers are missing
https://s3-ap-southeast-1.amazonaws.com/temp-files-dump/npm-install.txt
c:\users\vikrant pogula\desktop\node test\third_party\pdfium\core\src\fxcodec\fx_libopenjpeg\libopenjpeg20\opj_inttypes.h(36): fatal error C1083: Cannot open include file: 'inttypes.h': No such file or directory (..\..\..\third_party\pdfium\core\src\fxcodec\fx_libopenjpeg\src\fx_image.c)
Most of them seem to be this inttypes.h
from fx_libopenjpeg
Let me know if you need anything else
I tried to compile with msvs 2013, could you please retry with this compiler? On 31 Mar 2015 16:33, "Vikrant Pogula" notifications@github.com wrote:
@tojocky https://github.com/tojocky heres the full traceback. It says multiple times that the headers are missing
https://s3-ap-southeast-1.amazonaws.com/temp-files-dump/npm-install.txt
c:\users\vikrant pogula\desktop\node test\third_party\pdfium\core\src\fxcodec\fx_libopenjpeg\libopenjpeg20\opj_inttypes.h(36): fatal error C1083: Cannot open include file: 'inttypes.h': No such file or directory (......\third_party\pdfium\core\src\fxcodec\fx_libopenjpeg\src\fx_image.c)
Most of them seem to be this 'inttypes.h' from fx_libopenjpeg
Let me know if you need anything else
— Reply to this email directly or view it on GitHub https://github.com/tojocky/node-printer/issues/29#issuecomment-88135371.
downloading the compiler. Do you by chance have a direct link around for it ?
EDIT: I got it kind of run with msvs 2012, with only one error (instead of many). Missing inttypes.h
. Will update you once i try 2013
with msvs 2013 on win7 i get this now.
Warning: Missing input files:
C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\..\..\..\third_party\pdfium\core\src\fxcodec\libjpeg\makefile
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\third_party\bigint.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fdrm.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\formfiller.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fpdfapi.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fpdfdoc.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fpdftext.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\third_party\freetype.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\fx_lpng.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fxcodec.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fxcrt.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fxedit.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\fxge.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\javascript.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\jsapi.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\third_party\pdfium_base.vcxproj]
C:\Program Files\Windows Kits\8.1\DesignTime\CommonConfiguration\neutral\Windows.arm.props : error MSB4025: The project file could not be loaded. Root element is missing. [C:\Users\Virtual\Desktop\node-pdfium\build\third_party\pdfium\pdfwindow.vcxproj]
did you rebuild?
did you try to build with node-gyp --msvs_version=2013
or the same param for nw-gyp?
yes, this is the error i get for node-gyp rebuild --msvs_version=2013
strange, I see Windows.arm.props
. What is your arch in the end?
I was using a boxed windows 7, maybe thats they issue. Should I try it with windows 8 which i have on bootcamp ? I actually want to get it to run on windows 7
I've been unable to get it to build with a variety of combinations. Same errors.
Just hit a new one.
os_posix is not defined for condition [os_posix==1]
I will try again over the weekend.
btw thanks for maintaining this package ! its one of the most useful part of my app right now :)
@vikrantpogula Please open an issue in https://github.com/tojocky/node-pdfium/issues to separate by windows PDF.
@tojocky sure, done !
@tojocky I noticed that this is still open, it's recommended in node-printer to use pdfium. Is this still a viable solution for printing pdf's on windows?
Hi @dougludlow I think it is a solution to use pdfium to print PDF on windows. Unfortunately I didn't have time to finish pdfium node port to be PROD ready. Feel free to test it and propose PR.
+1
Use "pdftops.exe" to convert "pdf" to "PostScript" Use RAW Print
tool download: " Xpdf tools " http://www.xpdfreader.com/download.html
Here's the link to the PDF:
https://drive.google.com/file/d/0B4xBPiAxQ7h5STZPWjlGREJKd0k/view?usp=sharing
We used MS Word to create a PDF and that printed fine. The above PDF was generated using a PHP library called FPDF:
I'm using this code to print it. When we attempt to print the above PDF, the printer will get the data, but it will not print it.