jsreport / jsreport

javascript based business reporting platform :rocket:
https://jsreport.net
GNU Lesser General Public License v3.0
1.18k stars 228 forks source link

pdf content is blank #79

Closed satish2010 closed 7 years ago

satish2010 commented 9 years ago

Hello Team,

I am trying below in Advanced Rest Client of google chrome by making jsreport server up on localhost:8080.

url : http://localhost:8080/api/report Headers : Content-Type: application/json Body : { "template": { "content" : "Hello world", "recipe" : "phantom-pdf" } }

The response is coming as a pdf but it is totally blank, ideally it is should "Hello world". Can you please help on this issue.

Thanks, Satish

pofider commented 9 years ago

Hi Satish,

I get status code NO RESPONSE when doing request over https when there is not yet an ssl exception for the invalid certificate in the chrome. Isn't it your case? This can be solved by navigating in another tab to the jsreport url and adding exception in the chrome.

Are the requests working in jsreport studio?

Do you have authentication extension enabled or not?

Jan

mike-dnb commented 9 years ago

@satish2010 We see something very similar. In your PDF, select everything (even if it looks empty), copy and paste it into a text editor.

We try to render This is a heading. but what we get in the PDF is white text that says ihsish issi aa gheadinhadinge

It works on my Mac, but not on CentOS 6. My first thought is an encoding issue, but not sure if I'm on the right track with that.

I noticed some new jsreport releases recently. @pofider do you think any of your recent changes may affect the pdf recipe / phantomjs / encoding?

I'll continue to investigate,

Mike

pofider commented 9 years ago

I would guess phantomjs is missing some dependencies (fonts) required for rendering pdf. It runs for me if I spin up fresh centos VM on azure but I see people complaining sometimes required phantomjs dependencies are not preinstalled. Adding the missing package depends on your distribution

For example on ubuntu you may need to run:

sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev

on centos

sudo yum install freetype fontconfig
satish2010 commented 9 years ago

Hello Team,

  1. For recipe html it is working fine.
  2. For pdf it is working in jsreport studio, but not working when i am calling through REST.
  3. We haven't done anything related to authentication.
  4. I have windows operating system so can please suggest something.

Please find the response for pdf & when i save it is blank.

%PDF-1.4 1 0 obj << /Title (��) /Creator (��) /Producer (��Qt 4.8.4 (C) 2011 Nokia Corporation and/or its subsidiary(-ies)) /CreationDate (D:20150601184351+05'30')

endobj 3 0 obj << /Type /ExtGState /SA true /SM 0.02 /ca 1.0 /CA 1.0 /AIS false /SMask /None>> endobj 4 0 obj [/Pattern /DeviceRGB] endobj 7 0 obj << /Type /Catalog /Pages 2 0 R

endobj 5 0 obj << /Type /Page /Parent 2 0 R /Contents 8 0 R /Resources 10 0 R /Annots 11 0 R /MediaBox [0 0 595 842]

endobj 10 0 obj << /ColorSpace << /PCSp 4 0 R /CSp /DeviceRGB /CSpg /DeviceGray

/ExtGState << /GSa 3 0 R

/Pattern <<

/Font << /F6 6 0 R

/XObject <<

endobj 11 0 obj [ ] endobj 8 0 obj << /Length 9 0 R /Filter /FlateDecode

stream x��S�J�0��W�Y�6�I�ăEBi��x�]WY��u��IZ�m �e�t�d�e���]��o{������K n-����XC�{{[��2%�'l� �:�%��o���;�fh�2p__����6���̪�V�@���1F�A;�(1���u��%&� �/p�J���U�֡���.��:L=� ~�6���|����V���7�s�?}$u�9��Jnt�G�{�Q����3U�-ķ)�A������V�\�]᥻L�B���I���g�*�� �$' ������Ǔ� ��p�endstream endobj 9 0 obj 306 endobj 12 0 obj << /Type /FontDescriptor /FontName /QMAAAA+TimesNewRomanRegular /Flags 4 /FontBBox [-513.183593 -276.855468 1805.66406 909.179687 ] /ItalicAngle 0 /Ascent 625.976562 /Descent -194.824218 /CapHeight 0 /StemV 43.9453125 /FontFile2 13 0 R endobj 13 0 obj << /Length1 4224 /Length 16 0 R /Filter /FlateDecode

stream x��V[lY��\��v�8�c�I��\줹47'u�v�^S��%I/��N�I<�=���I�T�BE��\ ���H��J��]�j���U��K�@Z؊� R��� ����nRXD�9�������8@���rcO��#2j.���l?��wE��BCR��M{� ���?��uo{�<�rS2m��orQN�rJ�K�6q�+(W���p��C��RZ�xp�4�������+ B�xM� �֛�3\99��������a�8;�Q�������]z"^^�Ez�!��V KKK���☙ ��f����� ���͸��?9�ǟ����:�3��A� ���(��}�p$�� �������W��z}�ho�@��z^]��G�q1wq]���s�u4׹���.����Q�ކ��=���(�5T��k[L���p�:w��:�_� �|����'����$j�ӈ�x�@�� =��Ky�OB54T8�U�d?��� �Q����Ca��V����W?;<�Z[y��W��>C���ѥ�G�����Xh���;<��wf��6����ld￿0O��^��Pw�� �<n��O�5��)B���+58#�����,1���v8KK}�&�'��������R�������~�֗�JC2��e�C�8�U�C�&�l*�gf�[�WZG1y��.���'�{��bǏ�uuu����ñ9���$��uM�cC����ss�������Q������?~�0v�Zz(6�C��^�Y9**{QKv���[V�F�o$��E�uy<�7nm�5U��K�j�Iѽ���{��x�i����hX�WM`}??JJ��"�M�B~���C!���/�X ��uוyJ8����M\��r����n�s\8y�D���k��y�Ƶù��c�8�c��U�C��TU��HK���������l�U�q8�<�������ݻ��HS @h}yxj���(��9U�R�����֗� )a'5�x� ���Eq�����)��:������ƨ7l����z������ж� ��i�R�N��� �ݟ��"����u�68�׶wl8�e����'N�T[37��ͫ�����!kp�l�F}������o��YMȮSo�~eڼ�磟n~|�3�ȼ��-}(6c7+�#r�s�Wy~����,R����P> ;96��a y���%���f����p�&�d�=��"�(�hgZ�7��W���l��g�I&��.ژ�cc��G����h E6v�<��"��H.���6.��q��ڢ�;6&�٘'cͪ/&�l,����m�����Nڸ�{6.����b�2.�����c.��2,".s�3��a��L?�p�G.�9��š�--lqha��������8��š�--lqh�u��XmI���R��2\f����p�r�7�,���8�1\U��f{�p �y�����������?��Ῑ������\��{�������Ƈ�$A��8h��c@2L�%��J�W�G'ZF � ����d�$�[F�y\�9��4�R؇�楡N�H��,�0��{V����t��A8�rg�:)D��.��(�t�h�Ю� fi-�oE�L⎩O�@a �q�@�4�� ��<��k=�V�滀��Na?��a���|&q�Y] 5y;��5�����7����׬\Eũ�A/���hϡl�c�ɱ�5;M�}ϰ�c��3��4Z ��@a��5lv�A�7b�� ,v6 �g������y-���c�9�E��j�&�=��#ϪT�5���"��XV��l�5�k��<�#熲S�^�����5��w��EO���Φ�`��Wf���[���5T��ىՋ��-O���5��ֹ�&�ŝZLKϱ��������9�2l�����ɵ☞)���g�:�����SI��k�f�32ݮ�M� ES;�H_E'�٤��rV���D甒��t��@'���Nȳ���/�\e��}���g1&�vv Жq%�kYm�he��μL�O��d�D ]J�iI?C���\��r�\v�҂����33J\�tҐԔ�ǽ����vzH��N�$=!��������hZ��\V�Fs�hh��4#�i�0��ΣE�;���UgBF���A�.$�x�`/�5��%p��ф�ͤ0��&p��q�����.'��T��(�TNO����R��XsO�=�r�б;d� =n�5�_hQ0�!�M u�&�5�I�I�h�U�)��a\sF&gЄ<o��>I9�Y�����Jl���IJp�N������˶��6aݠ�5��+�m|��w���1����(搟�d�ƅv�BP�� ��͸ƞ����}�7Ͼ���F��$?�ͻc=u�Ω,�eMLendstream endobj 16 0 obj 2345 endobj 14 0 obj << /Type /Font /Subtype /CIDFontType2 /BaseFont /TimesNewRomanRegular /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor 12 0 R /CIDToGIDMap /Identity /W [0 [697 647 398 249 448 224 647 298 448 ] ]

endobj 15 0 obj << /Length 420 >> stream /CIDInit /ProcSet findresource begin 12 dict begin begincmap /CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def /CMapName /Adobe-Identity-UCS def /CMapType 2 def 1 begincodespacerange

<0000> endcodespacerange 2 beginbfrange <0000> <0000> <0000> <0001> <0008> [<0048> <0065> <006C> <006F> <0020> <0077> <0072> <0064> ] endbfrange endcmap CMapName currentdict /CMap defineresource pop end end endstream endobj 6 0 obj << /Type /Font /Subtype /Type0 /BaseFont /TimesNewRomanRegular /Encoding /Identity-H /DescendantFonts [14 0 R] /ToUnicode 15 0 R>> endobj 2 0 obj << /Type /Pages /Kids [ 5 0 R ] /Count 1 /ProcSet [/PDF /Text /ImageB /ImageC] endobj xref 0 17 0000000000 65535 f 0000000009 00000 n 0000004716 00000 n 0000000241 00000 n 0000000336 00000 n 0000000422 00000 n 0000004570 00000 n 0000000373 00000 n 0000000728 00000 n 0000001107 00000 n 0000000542 00000 n 0000000708 00000 n 0000001126 00000 n 0000001387 00000 n 0000003843 00000 n 0000004099 00000 n 0000003822 00000 n trailer << /Size 17 /Info 1 0 R /Root 7 0 R startxref 4814 %%EOF

Thanks, Satish

pofider commented 9 years ago

Ouu. You are using the chrome Advanced REST client to actually save the file??? I have tried it and I also get it blank but this is only an issue in Advanced REST client.

Make the request from the c#, node.js or anything else and it will work.

satish2010 commented 9 years ago

Hello Team,

  1. As per node.js client i have made client.js it has below code :

var client = require("jsreport-client")("http://localhost:8080"); client.render({ template: { "shortid" : "41WCRVZH" }, data: { "to": "sumeet", "from": "satish", "price": 800 } }, function(err, resp) { resp.body(function(body) { //prints hello world!! console.log(body.toString());
}); });

  1. For running client.js i am using "node client.js" which gives me response in the same format as mentioned above but when i am changing the content of the file for saving pdf as mentioned in client.js

var client = require("jsreport-client")("http://localhost:8080"); var express = require('express'); var app = express();

app.get("/report", function(req, res, next) { client.render({ template: { "shortid" : "41WCRVZH" }, data: { "to": "sumeet", "from": "satish", "price": 800 } }, function(err, response) { if (err) { return next(err); } response.pipe(res); }); });

it gives the error :

D:\GPP>node client.js module.js:338 throw err; ^ Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Object. (D:\GPP\client.js:2:15) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10)

Can you please help on this.

Thanks, Satish

pofider commented 9 years ago

Did you install express package?

npm install express
satish2010 commented 9 years ago

Hello Team,

  1. I have tried npm install express which has given the below error :

D:\GPP>npm install express npm WARN package.json gpp@0.0.0 No description npm WARN package.json gpp@0.0.0 No repository field. npm WARN package.json gpp@0.0.0 No README data npm WARN package.json karma-phantomjs-launcher@0.1.4 No README data npm ERR! fetch failed https://registry.npmjs.org/serve-static/-/serve-static-1.9.3.tgz npm WARN retry will retry, error on last attempt: Error: connect ETIMEDOUT npm ERR! fetch failed https://registry.npmjs.org/serve-static/-/serve-static-1.9.3.tgz npm WARN retry will retry, error on last attempt: Error: connect ETIMEDOUT npm ERR! fetch failed https://registry.npmjs.org/serve-static/-/serve-static-1.9.3.tgz npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "express" npm ERR! node v0.12.3 npm ERR! npm v2.9.1 npm ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! syscall connect

npm ERR! network connect ETIMEDOUT npm ERR! network This is most likely not a problem with npm itself npm ERR! network and is related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! Please include the following file with any support request: npm ERR! D:\GPP\npm-debug.log

  1. Please find the content of npm-debug.log :

0 info it worked if it ends with ok 1 verbose cli [ 'C:\Program Files\nodejs\node.exe', 1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', 1 verbose cli 'start' ] 2 info using npm@2.9.1 3 info using node@v0.12.3 4 verbose node symlink C:\Program Files\nodejs\node.exe 5 verbose run-script [ 'prestart', 'start', 'poststart' ] 6 info prestart gpp@0.0.0 7 info start gpp@0.0.0 8 verbose unsafe-perm in lifecycle true 9 info gpp@0.0.0 Failed to exec start script 10 verbose stack Error: gpp@0.0.0 start: node server.js 10 verbose stack Exit status 1 10 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:213:16) 10 verbose stack at EventEmitter.emit (events.js:110:17) 10 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14) 10 verbose stack at ChildProcess.emit (events.js:110:17) 10 verbose stack at maybeClose (child_process.js:1015:16) 10 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1087:5) 11 verbose pkgid gpp@0.0.0 12 verbose cwd D:\GPP 13 error Windows_NT 6.1.7601 14 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start" 15 error node v0.12.3 16 error npm v2.9.1 17 error code ELIFECYCLE 18 error gpp@0.0.0 start: node server.js 18 error Exit status 1 19 error Failed at the gpp@0.0.0 start script 'node server.js'. 19 error This is most likely a problem with the gpp package, 19 error not with npm itself. 19 error Tell the author that this fails on your system: 19 error node server.js 19 error You can get their info via: 19 error npm owner ls gpp 19 error There is likely additional logging output above. 20 verbose exit [ 1, true ]

pofider commented 9 years ago

This has nothing to do with jsreport. Please ask only questions related to it. I cannot put here basic support for node.js.....

It looks like a temporary connection problem. Try it again later....

satish2010 commented 9 years ago

I am extremely sorry sir yes there was a proxy issue, now express got install successfully.

But now i run my client.js which has the below content using D:\GPP>node client.js

var client = require("jsreport-client")("http://localhost:8080"); var express = require('express'); var app = express();

app.get("/report", function(req, res, next) { client.render({ template: { "shortid" : "41WCRVZH" }, data: { "to": "sumeet", "from": "satish", "price": 800 } }, function(err, response) { if (err) {
return next(err); } response.pipe(res); }); });

It does not give me any result, how to view the pdf in this case. Any help would be great.

Thanks, Satish

mike-dnb commented 9 years ago

Thanks @pofider, I already had the two packages installed as per

Package freetype-2.3.11-15.el6_6.1.x86_64 already installed and latest version
Package fontconfig-2.8.0-5.el6.x86_64 already installed and latest version

I've tried building phantomjs from source, getting different versions etc, but nothing seems to fix the issue.

If anything comes to your mind, please let me know. I'll do the same :)

Thanks

mike-dnb commented 9 years ago

There we go, it works. Here's what I did:

It's not an ideal solution, but it works for now

afshin2003 commented 9 years ago

On jsreport 0.8.2, I had to replace jsreport/node_modules/toner-phantom/node_modules/phantom-html-to-pdf/node_modules/phantomjs/lib/phantom/bin/phantomjs with the built one. It does not work however! The initial situation was different. I had overall picture but instead of every character there was a black rectangle. Right now the content is blank!

afshin2003 commented 9 years ago

jr-phantomjs-1 9 8 js-phantomjs-2 0 1-development

afshin2003 commented 9 years ago

I found in another thread that installing ImageMagick can solve the problem! It did :)

gdavalos commented 9 years ago

I'm having this problem too with the online version.

When I try viewing the reports using the urls provided by jsreport online everything works just fine, but when I try to use a REST client the encoding just randomly changes to "latin-1".

I can understand if it doesn't work with chrome's advanced rest client, but I use GWT(http://www.gwtproject.org/) for my web apps and RestyGWT(https://resty-gwt.github.io/index.html) to access REST APIs and I could make the html reports work but I get this problem with the phantom-pdf recipe.

I think the problem is encoding-related and I tried to change the headers to no avail, do you have any ideas of what I could try to make this work?

FernandoGOT commented 8 years ago

Not sure if it is your problem, but I was geting the pdf blank, just nedded to add a encoding: null at my request and it worked like magic. My full request in nodejs is as bellow:

url: 'https://localhost/api/report',
      strictSSL: false, // allow us to use our self-signed cert for testing
      rejectUnauthorized: false,
      encoding: null,
      headers: {
        'Content-Type': ' application/json',
        'accept-charset': 'utf-8'
      },
      json: true,
      body:{
        "template": { "shortid" : "V1BMBjzWl" },
        "data": {
          "someAttr": "value",
          "someAttr": "value"
        }
      }
vunb commented 7 years ago

Thank you @afshin2003 👍

pofider commented 7 years ago

Closing this. It covers several different problems with different solutions, but all looks to me quite exceptional to be in the docs. People can still easily find it here googling "jsreport pdf content blank".

shadyyehia commented 7 years ago

I run this code and I get a blank PDF: any idea plz? module.exports = function (callback) { var jsreport = require('jsreport')();

jsreport.init().then(function () {
    return jsreport.render({
        template: {
            content: '<h1>Hello </h1>',
            engine: 'jsrender',
            recipe: 'phantom-pdf'
        }
    }).then(function (resp) {
        callback(/* error */ null, resp.content.toJSON().data);
    });
}).catch(function (e) {
    callback(/* error */ e, null);
})

};

spk27 commented 6 years ago

Hi all,

I've trying many responses but not ones works to me.

Im getting myreport from a mvc view and made a post resquest from a rest api using Axios.. so i get "%PDF-1.4 ....... " response. When try to view or download it i get a blank pdf page. Note: the request from postman client works! Am i missing something? i'll be so happy if you can help me with this! Thank you all!

This is my request:

   function ProcessInvoice() {
        var uri = Base + '/Invoice';
    return axios.post(uri, {
         responseType: 'arraybuffer',
                     encoding: null,
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/pdf'
             }
     }).then(function (response) {
        return response;
     });
   }

Then on response:

 ProcessInvoice().then(response => {
    let blob = new Blob([response.data], { type:   'application/pdf' } );
    let link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = 'myReport.pdf';
    link.click();
     }).catch(function(err){
    alert(JSON.stringify(err.response.data));
  })
},
pofider commented 6 years ago

@spk27 I guess problem is in the code handling the response stream. Try to reuse what we have in the jsreport client for browser.

spk27 commented 6 years ago

Great That works! Thank you @pofider