Marak / Marak/pdf.js

node-demo produces 2 blank pages

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
396
Forks
41
PR merge metrics
No merged PRs in 30d

Description

Using latest pdf.js - the one with drawLine...
With node.js v0.4.12, which might have something to do with it, the demo produces 2 blank pages; no text or graphics. Select All, copy, paste into a text doc pastes nothing. testFile57.pdf in the repo and download displays properly, select/copy/paste pastes the text into a text editor. Ubuntu Natty 11.04.

I note that in the repo/download file, the node version is v0.3.0-pre.

There are differences between the files:
testFile57:
%PDF-1.3

<>
BT /F1 16.00 Tf ET
BT 56.69 785.20 Td (hello, I am PDF.) Tj ET
BT 56.69 756.85 Td (i was created using node.js version: v0.3.0-pre) Tj ET
BT 56.69 728.50 Td (i can also be created from the browser) Tj ET

endstream
endobj

testFile44 (mine):
%PDF-1.3

<>
BT undefined 16.00 Tf ET
BT /F0 16.00 Tf ET
BT 56.69 785.20 Td (hello, I am PDF.) Tj ET
BT /F0 16.00 Tf ET
BT 56.69 756.85 Td (i was created using node.js version: v0.4.12) Tj ET
BT /F0 16.00 Tf ET
BT 56.69 728.50 Td (i can also be created from the browser) Tj ET

endstream
endobj

Similar block a bit later on - also has 'undefined'.

Update: I was able to get it to work:

  1. node-demo.js:
    var doc = new pdf();
    doc.setFont(1); //<<<< added to make sure fonts[] had 1 font
    doc.text(20, 20, 'hello, I am PDF.');
    doc.text(20, 30, 'i was created using node.js version: ' + process.version);
    doc.text(20, 40, 'i can also be created from the browser');
  2. pdf.js:
    var _addPage = function() {
    beginPage();
    // Set line width
    out(sprintf('%.2f w', (lineWidth * k)));
// 16 is the font size
pageFontSize = fontSize;
pageFont = font;
//DLC-->>>>>delete out('BT ' + fonts[font] + ' ' + parseInt(fontSize) + '.00 Tf ET');    
//fonts[] is undefined at this point when called by _addPage();

}

Alternately, rename setFont: function... to var _setFont = function... and move the function up where _addPage() is. Then create
setFont: function(f){
_setFont(f);
},
in its place. Then, where _addPage() is called to automatically create the first page, FIRST call
_setFont(1);

This change removes the need for node-demo.js to have an initializing call to setFont.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with node-demo.js and pdf.js, reproduce the blank-page output using the reported Node.js version, and compare the generated font commands with testFile57.pdf. Trace the first page creation and font initialization, then verify that the generated PDF contains valid font references and renders selectable text and graphics.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.