GithubHelp home page GithubHelp logo

galkahana / hummusjs Goto Github PK

View Code? Open in Web Editor NEW
1.1K 33.0 172.0 26.32 MB

Node.js module for high performance creation, modification and parsing of PDF files and streams

Home Page: http://www.pdfhummus.com

License: Other

Python 1.42% JavaScript 0.51% C++ 18.04% C 73.71% CMake 0.19% Makefile 1.14% Awk 0.03% Shell 4.71% M4 0.19% HTML 0.06%
pdf-generation pdf-parsing pdf-modification nodejs pdf-manipulation

hummusjs's Introduction

HummusJS

Build Status NPM version Donate

Update 9/11/2019 Ending Support:
Hi All, after 6 years I decided to finish supporting HummusJS. You may still use the code as is, with the provided license, however I will not be providing answers, solutions, responses etc.

If you want to continue using HummusJS and are looking for a maintained version you can move to MuhammaraJS which is a drop in replacement for HummusJS. Thanks Julianhille for maintaining it.

I'd like to thank everyone who used HummusJS and wish you all the best going forward with your projects.
Gal.

Welcome to HummusJS.
A Fast NodeJS Module for Creating, Parsing an Manipulating PDF Files and Streams.
Documentation is available here.
Project site is here.

If you are looking for a C++ Library go here.

hummusjs's People

Contributors

astefanutti avatar brianreavis avatar chunyenhuang avatar cs-jfilmer avatar dependabot[bot] avatar galkahana avatar hhaidar avatar jaysonvaughn1981 avatar julianhille avatar lucis avatar marcelotavares avatar mattleff avatar moshensky avatar pelicanmaster avatar rauno56 avatar rbeeger avatar rosga avatar taxilian avatar willy2dg 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  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  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

hummusjs's Issues

"ReferenceError: imageObjectName is not defined" when modifying PDF

When using code similar to your test ModifyExistingPageContent.js, for some PDFs an error is thrown when calling pageModifier.writePage(). Here's a stack trace:

ReferenceError: imageObjectName is not defined
    at /code/node_modules/hummus/hummus.js:236:30
    at Array.forEach (native)
    at writeModifiedResourcesDict (/code/node_modules/hummus/hummus.js:234:19)
    at PDFPageModifier.writePage (/code/node_modules/hummus/hummus.js:159:34)
    at /code/app.js:52:31
    at callbacks (/code/node_modules/express/lib/router/index.js:164:37)
    at param (/code/node_modules/express/lib/router/index.js:138:11)
    at pass (/code/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/code/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/code/node_modules/express/lib/router/index.js:33:10)

From looking at the code at

var formObjectName = imageObjectName + '_' + inIndex;
, it looks like sourceObject['XObject'] is equal to false, therefore imageObjectName isn't set.

I'd submit a pull request to fix it, but I don't have any knowledge of PDF internals!

Strange behavior on converted pdf's (ppt to pdf / doc to pdf)

Hi, I have recently started using hummusJS for drawing on a pdf. It works great with the normal PDF's but if try to use it on a converted PDF, (i converted a pptx file to a pdf using libreoffice/unoconv), it behaves a bit strangely.

Here's a rough idea of what i am doing:
https://www.dropbox.com/s/a9lydm9haud4uov/draw-annotations-on-pdf.js?dl=0

The expected behavior should be a free hand drawing and a rectangle on page 1 and a free hand drawing on page2. However, when drawing on page 2, page 1 is also overwritten so i get the same free hand drawing on page 1,as i had intended to make on page 2 overwriting my page 1 drawings.
https://www.dropbox.com/s/odrxdm7fugllgd2/modfb.pdf?dl=0

The original file is : https://www.dropbox.com/s/jl8hzgcmd8x8r0l/fb.pptx?dl=0

The same code runs great on a PDF which has not undergone conversion. Works without any issue.

Stitch two different pdfs together?

I cannot deem from the documentation if hummus is capable of stitching two pdfs together. It looks like there's potential by reading the pdfs into a stream but I don't know what to do from there.

segfault on multipage tiff

gdb --args ./node TiffSpecialsTest.js
GNU gdb (GDB) 7.9.1
 Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./node...done.
(gdb) run
Starting program: /home/user/node_modules/hummus/tests/node TiffSpecialsTest.js
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff7ff7700 (LWP 29381)]
[New Thread 0x7ffff3fbd700 (LWP 29380)]


#
# Fatal error in ../deps/v8/src/api.h, line 378
# CHECK(allow_empty_handle || that != __null) failed
#

==== C stack trace ===============================

 1: V8_Fatal
 2: v8::Value::ToObject() const
 3: PDFWriterDriver::CreateFormXObjectFromTIFF(v8::FunctionCallbackInfo<v8::Value> const&)
 4: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&))
 5: ??
 6: ??

Program received signal SIGILL, Illegal instruction.
v8::base::OS::Abort () at ../deps/v8/src/base/platform/platform-posix.cc:278
278         V8_IMMEDIATE_CRASH();
(gdb) c
Continuing.
[Thread 0x7ffff7ff7700 (LWP 29381) exited]
[Thread 0x7ffff3fbd700 (LWP 29380) exited]

Program terminated with signal SIGILL, Illegal instruction.
The program no longer exists.

Changes in the test TiffSpecialsTest.js

for(var i=0;true;++i)
{
    var imageForm = pdfWriter.createFormXObjectFromTIFF('./TestMaterials/images/tiff/multipage.tif',{pageIndex : i});
    if(!imageForm) break;
    createPageFormImage(pdfWriter,imageForm);
}

Issues with form input elements when embedding PDF content

Hi,

I tried to use HummusJS to combine different PDF pages to one, as I didn't find any API in HummusJS to create and add FormInputElements into a PDF.

So my idea was to provide multiple PDFs where one is containing the relevant interactive FormField, to combine/embed them into one page.

But it doesn't take the interactive elements using the following:
...
var formIDs = pdfWriter.createFormXObjectsFromPDF('some_pdf_with_interactiveField.pdf',hummus.ePDFPageBoxMediaBox);
var page = pdfWriter.createPage(0,0,595,842);
var contentContext = pdfWriter.startPageContentContext(page);
contentContext.q()
.cm(0.5,0,0,0.5,0,421)
.doXObject(page.getResourcesDictionary().addFormXObjectMapping(formIDs[0]))
.Q()
.G(0)
.w(1)
.S();
...

Any idea how to achieve that?
Thanks a lot in advance!

Best regards,
Filip

unable to append page, make sure it's fine

Hi,

I'm using this code:

var hummus = require('hummus');

{ var pdfWriter = hummus.createWriter('./output/appendTest1.pdf',
{
version:hummus.ePDFVersion14
});

pdfWriter.appendPDFPagesFromPDF('./sample.pdf');
pdfWriter.appendPDFPagesFromPDF('./sample1.pdf');

pdfWriter.end();

console.log('done - ok');

}

When I tested it in other PDF, it works fine.
But when I tried it to the files I need,
The error was always, "unable to append page, make sure it's fine"

Does it require some version of PDF, or any format?
I just thought any PDF File will do.

Thanks in advance.

reading and writing from streams for Modification not working

Hi Gal

I'm trying to use streams to write to when modifying an existing PDF (I don't want to overwrite the original and want to send the response back on the http stream without having to set a temp file to write to).
I have no problem getting this to work when I'm not modifying an existing file (the first step below) but I get an error for the second step when using an existing PDF:

TypeError: Unable to modify PDF file, make sure that output file target is available and that it is not protected

Any idea what I might be doing wrong in this case?

(This is based on ModifyExistingPageContent.js test so you'll have all the resources mentioned.)

Thanks,
Ross

var hummus = require('../hummus');
var fs = require('fs');

var outStream = fs.createWriteStream( './output/BasicJPGImagesTestPageModified.pdf' );
var pdfWriter = hummus.createWriter(new hummus.PDFStreamForResponse(outStream));

var page = pdfWriter.createPage(0, 0, 595, 842);

pdfWriter.startPageContentContext(page).writeText('Test Text',
75,
805,
{font:pdfWriter.getFontForFile('./TestMaterials/fonts/Couri.ttf'),size:14,colorspace:'gray',color:0x00});
pdfWriter.writePage(page).end();;

console.log('done simple write to stream');

var inStream = fs.createReadStream( './TestMaterials/BasicJPGImagesTest.PDF' );
var outStream2 = fs.createWriteStream( './output/BasicJPGImagesTestPageModified.pdf' );
pdfWriter = hummus.createWriterToModify(inStream, new hummus.PDFStreamForResponse(outStream2));

var pageModifier = new hummus.PDFPageModifier(pdfWriter,0);

pageModifier.startContext().getContext().writeText('Test Text',
75,
805,
{font:pdfWriter.getFontForFile('./TestMaterials/fonts/Couri.ttf'),size:14,colorspace:'gray',color:0x00});
pageModifier.endContext().writePage();

pdfWriter.end();

console.log('done - done write to stream for modification');

Width Text Property in HummusJS PDF Writer

Hi,

Does this support setting the width of the text?
Like if my text was
"HELLO WORLD"
then I would like to set the width to 100.
If I added some text continuing the Hello World like,
"HELLO WORLD AND HELLO PHILIPPINES"
then it would exceed to the width size, it would be automatically displayed on the next line, like,
"HELLO WORLD AND
HELLO PHILIPPINES"

Thanks in advance.

Font characteristics

@galkahana I have high respect for your library. One thing makes the use for me problematic though: To arrange text exactly I need to know the font characteristics. getting the font dimensions using writer.getFontForFile(..).calculateTextDimensions is a first step but really the other characteristics are very important to align as well, i.e. a text with all small characters like "nano" has different dimensions than one with a "f" or "y" in it: In short The baseline is very important to arrange text carefully.

font-characteristics

Is there a way to figure that out?

Adding a CropBox

I'm building a pdf with the same MediaBox as "pdfFilePath.pdf" but I'd also like to be able to add the same CropBox. How do I go about adding a CropBox to my 'page'?

var pdfWriter = hummus.createWriter("outputPath.pdf");
var pdfReader = hummus.createReader("pdfFilePath.pdf");

_.times(numberOfPages, function(it) {
     var mediaBox = pdfReader.parsePage(it).getMediaBox();
     var cropBox = pdfReader.parsePage(it).getCropBox();
     var page = pdfWriter.createPage(mediaBox[0],mediaBox[1],mediaBox[2],mediaBox[3]);
     .....
     pdfWriter.writePage(page);
}

pdfWriter.end();

Thanks!

Test Suggestion

This week I used your excellent code to write a solution to stamp an image on multi-page PDFs and I learned a lot of about your code. I want to top my solution off by setting some of the document properties (title, creator, author, producer, etc.).

So, I started with this:

var docCtx = pdfWriter.getDocumentContext().getInfoDictionary();

I expected to be able to call:

docCtx.setAuthor() but the arguments seem to elude me and whatever I try I get a "no method" error from Node.

Adding a file to your tests might be helpful to illustrate the technique.

segfault

gdb --args ./node test
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./node...done.
(gdb) run
Starting program: /root/pdf/node test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6795310 in PDFArray::GetLength() () from /root/pdf/node_modules/hummus/build/Release/hummus.node
(gdb) backtrace
#0  0x00007ffff6795310 in PDFArray::GetLength() () from /root/pdf/node_modules/hummus/build/Release/hummus.node
#1  0x00007ffff672cf16 in PDFArrayDriver::ToJSArray(v8::FunctionCallbackInfo<v8::Value> const&) () from /root/pdf/node_modules/hummus/build/Release/hummus.node
#2  0x00000000007a2d48 in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) ()
#3  0x00000000007c3874 in v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) ()
#4  0x00002fc2e470740e in ?? ()
#5  0x00002fc2e4729102 in ?? ()
#6  0x00002fc2e4707361 in ?? ()
#7  0x00007fffffffe2e0 in ?? ()
#8  0x00007fffffffe360 in ?? ()
#9  0x00002fc2e47af711 in ?? ()
#10 0x0000165e4e03fd79 in ?? ()
#11 0x00002f4a3b1288f1 in ?? ()
#12 0x0000165e4e03fd79 in ?? ()
#13 0x000004456fb04121 in ?? ()
#14 0x000004456fb04121 in ?? ()
#15 0x000004456fb04121 in ?? ()
#16 0x000004456fb04121 in ?? ()
#17 0x0000000300000000 in ?? ()
#18 0x0000009400000000 in ?? ()
#19 0x0000165e4e058f81 in ?? ()
#20 0x00002f4a3b127d79 in ?? ()
#21 0x00007fffffffe3a8 in ?? ()
#22 0x00002fc2e47a46c9 in ?? ()
#23 0x00002f4a3b127031 in ?? ()
#24 0x0000165e4e058f81 in ?? ()
#25 0x00002f4a3b1269e1 in ?? ()
#26 0x00002f4a3b127031 in ?? ()
#27 0x00002f4a3b00e711 in ?? ()
#28 0x00002f4a3b00ceb9 in ?? ()
#29 0x00002f4a3b00cf01 in ?? ()
#30 0x00007fffffffe3d8 in ?? ()
#31 0x00002fc2e47a48b8 in ?? ()
#32 0x00002f4a3b00cf39 in ?? ()
#33 0x000004456fb561a9 in ?? ()
#34 0x00002f4a3b00cf51 in ?? ()
#35 0x00002f4a3b00cf01 in ?? ()
#36 0x00007fffffffe440 in ?? ()
#37 0x00002fc2e4759ec6 in ?? ()
#38 0x00002f4a3b00cf99 in ?? ()
#39 0x00002f4a3b00cfc1 in ?? ()
#40 0x00002f4a3b00cdb1 in ?? ()
#41 0x00002f4a3b00ce39 in ?? ()
#42 0x00002f4a3b00cf39 in ?? ()
#43 0x00002f4a3b00cf39 in ?? ()
#44 0x0000000500000000 in ?? ()
#45 0x0000000500000000 in ?? ()
#46 0x00002fc2e4759d21 in ?? ()
#47 0x0000000800000000 in ?? ()
#48 0x000004456fb635d1 in ?? ()
#49 0x00007fffffffe4b8 in ?? ()
#50 0x00002fc2e47a3966 in ?? ()
#51 0x00002f4a3b00cff1 in ?? ()
#52 0x00002f4a3b00cf39 in ?? ()
#53 0x00002f4a3b00cf51 in ?? ()
#54 0x000004456fb561f1 in ?? ()
#55 0x00002f4a3b00cff1 in ?? ()
#56 0x00002f4a3b00cf51 in ?? ()
#57 0x00002f4a3b00d011 in ?? ()
#58 0x000004456fb04121 in ?? ()
#59 0x000004456fb04121 in ?? ()
#60 0x00002f4a3b00cf99 in ?? ()
#61 0x00002f4a3b00ce39 in ?? ()
#62 0x0000165e4e01f729 in ?? ()
#63 0x00002f4a3b00ce81 in ?? ()
#64 0x00007fffffffe500 in ?? ()
#65 0x00002fc2e479de4c in ?? ()
#66 0x00002f4a3b00cfc1 in ?? ()
#67 0x00002f4a3b00d319 in ?? ()
#68 0x00002f4a3b00cdb1 in ?? ()
#69 0x0000165e4e01f729 in ?? ()
#70 0x00002f4a3b00d319 in ?? ()
#71 0x0000165e4e01f7c1 in ?? ()
#72 0x00002f4a3b004271 in ?? ()
#73 0x00007fffffffe548 in ?? ()
#74 0x00002fc2e479a600 in ?? ()
#75 0x00002f4a3b00cfc1 in ?? ()
#76 0x00002f4a3b00cdb1 in ?? ()
#77 0x00002f4a3b004239 in ?? ()
#78 0x0000165e4e01f7c1 in ?? ()
#79 0x00002f4a3b00d5e1 in ?? ()
#80 0x0000165e4e01f699 in ?? ()
#81 0x00002f4a3b004271 in ?? ()
#82 0x00007fffffffe5d0 in ?? ()
#83 0x00002fc2e478f6e5 in ?? ()
#84 0x00002f4a3b00cfc1 in ?? ()
#85 0x00002f4a3b00cdb1 in ?? ()
#86 0x0000165e4e01f699 in ?? ()
#87 0x00007fffffffe710 in ?? ()
#88 0x00002fc2e478f141 in ?? ()
#89 0x0000000000000002 in ?? ()
#90 0x00002f4a3b004271 in ?? ()
#91 0x00007fffffffe5d0 in ?? ()
#92 0x000004456fb04161 in ?? ()
#93 0x00002f4a3b00cdb1 in ?? ()
#94 0x000004456fb04121 in ?? ()
#95 0x000004456fb04121 in ?? ()
#96 0x00002f4a3b00cfc1 in ?? ()
#97 0x0000165e4e01f609 in ?? ()
#98 0x00002f4a3b004271 in ?? ()
#99 0x00007fffffffe618 in ?? ()
#100 0x00002fc2e478f0a4 in ?? ()
#101 0x000004456fb04161 in ?? ()
#102 0x000004456fb04101 in ?? ()
#103 0x00002f4a3b00d601 in ?? ()
#104 0x00002f4a3b0043c1 in ?? ()
#105 0x0000165e4e01f609 in ?? ()
#106 0x0000165e4e01f851 in ?? ()
#107 0x00002f4a3b004271 in ?? ()
#108 0x00007fffffffe688 in ?? ()
#109 0x00002fc2e476033f in ?? ()
#110 0x00002f4a3b0043c1 in ?? ()
#111 0x0000165e4e01f851 in ?? ()
#112 0x000004456fb04121 in ?? ()
#113 0x000004456fb04121 in ?? ()
#114 0x000004456fb04121 in ?? ()
#115 0x00002f4a3b0043c1 in ?? ()
#116 0x000004456fb04121 in ?? ()
#117 0x00002f4a3b00d629 in ?? ()
#118 0x000004456fb04121 in ?? ()
#119 0x00002f4a3b00d641 in ?? ()
#120 0x000004456fbb2351 in ?? ()
#121 0x00002f4a3b00d689 in ?? ()
#122 0x00007fffffffe6b8 in ?? ()
#123 0x00002fc2e475ed30 in ?? ()
#124 0x000004456fb56c01 in ?? ()
#125 0x000004456fbb2351 in ?? ()
#126 0x000004456fb63a61 in ?? ()
#127 0x000004456fb63aa9 in ?? ()
#128 0x00007fffffffe6f8 in ?? ()
#129 0x00002fc2e4756fe0 in ?? ()
#130 0x000004456fb63a01 in ?? ()
#131 0x000004456fb56c01 in ?? ()
#132 0x000004456fb63a61 in ?? ()
#133 0x00002fc2e4756f21 in ?? ()
#134 0x0000000800000000 in ?? ()
#135 0x0000000000000000 in ?? ()
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
hummus = require 'hummus'

pdfWriter = hummus.createWriterToModify './test.pdf',{modifiedFilePath:'./test_modified.pdf'}

pageModifier = new hummus.PDFPageModifier pdfWriter,0

pageModifier.startContext().getContext() #.writeText 'Test Text',
pageModifier = new hummus.PDFPageModifier pdfWriter,0

pageModifier.startContext().getContext().writeText 'Test Text',
                           75,
                           10, {
                                font:pdfWriter.getFontForFile('./arial.ttf'),
                                size:50,
                                colorspace:'gray',
                                color:0x00}

pageModifier.endContext().writePage()

pdfWriter.end()

console.log 'done - ok'

Hummus v1.0.39, node v0.12.2 x86_64 (./configure --without-ssl2 --without-ssl3 --without-npm --gdb --debug)

Module breaks in v0.12.0 of node

I updated my node the other day to find that any of my scripts that used hummus worked. The error I get is this:

module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: Module did not self-register.
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Volumes/RESOURCE/node_modules/hummus/hummus.js:2:18)
    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)

I thought it might have been a problem with node itself, so I opened an issue at nodejs/node-v0.x-archive#9252, and they told me the module is probably not compatible with v0.12.0 or v8.

It may or may not be helpful to note that even trying to install hummus with npm install hummus fails with these errors after a bunch of successful messages:

1218 error Darwin 12.6.0
1219 error argv "node" "/usr/local/bin/npm" "install" "hummus"
1220 error node v0.12.0
1221 error npm  v2.5.1
1222 error code ELIFECYCLE
1223 error [email protected] install: `node-gyp rebuild`
1223 error Exit status 1
1224 error Failed at the [email protected] install script 'node-gyp rebuild'.
1224 error This is most likely a problem with the hummus package,
1224 error not with npm itself.
1224 error Tell the author that this fails on your system:
1224 error     node-gyp rebuild
1224 error You can get their info via:
1224 error     npm owner ls hummus
1224 error There is likely additional logging output above.

So I'm guessing there's a problem with node-gyp somehow. A lot of this stuff is over my head though, so I'm not sure. I'm just using v0.10.36 of node for now, as that still works fine.

form fields question

Hi,

Terribly sorry if this is the wrong place, but I'm wondering if this library will allow me to work with form fields and determine the location of them in on a PDF page?

Thank you,

Mark

Modifying existing page doesn't work on non-test pdf

So this project looks amazing. Thanks!

I'm trying to run the ModifyExistingPageContent.js test script against a different PDF then the one used in the test. I don't get an error, but the text doesn't appear in the PDF. I tried it with the 'Original.pdf' file and the 'MultiChangeFile.pdf' as well as PDF of my own.

It's probably just a lack of understanding how to use the library, but I'd appreciate some pointers in the right direction.

Thanks again,
GF

Please HummusJS binding.gyp advice.(easy Proposal)

Hi galkahana.

HummusJS binding.gyp now build.

for exapmple;

git clone https://github.com/galkahana/HummusJS.git
git clone https://github.com/galkahana/PDF-Writer.git
mkdir HummusJS/deps
cp -r PDF-Writer/* HummusJS/deps/
cd HummusJS
node-gyp configure
node-gyp build

because HummusJS/binding.gyp and PDFWriter/binging.gyp

deps/PDFWriter
..

may be build easy

git clone https://github.com/galkahana/HummusJS.git
cd HummusJS
mkdir dpes
cd deps
git clone https://github.com/galkahana/PDF-Writer.git
node-gyp configure
node-gyp build

Ever so easy to follow even upstream, and than good?

I think that if the obtained the sympathy, I would like to change the binding.gyp.

thank you.

Add page and document properties

Hi,

Thanks for creating HummusJS - it's awesome to have such a good PDF library for Node!

I want to merge the first page from an existing pdf stream (a.pdf) to the start of another pdf stream (b.pdf) and copy all of the document properties from "b.pdf" into the output pdf stream. I'm a little confused about how to get this to work using HummusJS.

I tried using createWriterToModify to add "a.pdf" to "b.pdf" and creating a copyingContext to copy the Info dictionary into the combined document.

var pdfWriter = hummus.createWriterToModify(inStreamB, outStream);
pdfWriter.appendPDFPagesFromPDF(inStreamA, 
    {type: hummus.eRangeTypeSpecific, specificRanges:[[0,0]]});

var copyCtx = pdfWriter.createPDFCopyingContext('./b.pdf');
var infoIndirect = copyCtx.getSourceDocumentParser()
    .getTrailer().queryObject('Info');
copyCtx.copyObject(infoIndirect.getObjectID());

Here are the problems I had:

  1. createPDFCopyingContext won't take a stream (wiki docs say it should, but I get an error)
  2. The page from "a.pdf" is at the end of the output document instead of the start
  3. I'm not sure how to modify the Trailer in the output document to reference the new Info object (instead a new one seems to be there with only a modification date)

Hopefully, this isn't too confusing - I'd really appreciate your thoughts!

Thanks,
Dan

createReader returns empty object

When I use hummus.createReader() I don't get any errors but the returned object is empty. This is what happens in the node console...

> var hummus = require('hummus');
> var pdfReader = hummus.createReader('sample.pdf');
> pdfReader 
{}
>

How to add text to an existing PDF

I tried various combinations but finding it difficult to get the context correct for an existing page in an existing pdf.

I am basically trying to add a small text to an existing page in an existing pdf.

Can you please suggest how to do the same that you have in TextMeasurementsTest.js to an existing file.

I have an existing simple pdf with two pages and want that text to be added to the second page

CMYK Colors + Illustrator edit function

Hey there, first of thank for the library!

I'm trying to add a Text an existing pdf in CMYK (C:83 M:33 Y:74 K:17) - which is the same color as the ring in the existing pdf. When I try to add a text it somehow doesn't get the color right Here is the output

Any ideas why that? Also another question? Why isn't the text visible when I open the file in Illustrator (osx, CS6) while in acrobat reader it shows up?

var hummus = require('hummus');
var pdfWriter = hummus.createWriterToModify('./input.pdf',{modifiedFilePath:'./output.pdf'});
var pageModifier = new hummus.PDFPageModifier(pdfWriter,0);

pageModifier.startContext().getContext()
    .writeText('Test Text', 10, 10, {
        font: pdfWriter.getFontForFile('./tradegothicltstdbd2.ttf'),
        size: 12,
        colorspace: 'cmyk',
        color: 0x83337417 // C:83 M:33 Y:74 K:17
    });

pageModifier.endContext().writePage();
pdfWriter.end();

pdf form fills

Hi,

I've looked through the docs and didn't see anything mentioned, is it possible to use HummusJS to fill in a PDF form? If so, is there a call to do so, or would I have to iterate every form field and the modify it manually?

Thank you!

Mark

Segfaults when HummusJS included in a node+express project

Occurs with Node versions from 0.8.22 through 0.10.12
hummusjs 1.0.14

I am guessing it is a memory leak as the segfault doesn't occur immediately. Read/write/modify pdfs, works fine. Then you will try to make a connection to find that the server has faulted.

Thought it might be the local environment with 0.8.22, so pushed the project to Modulus to test that theory.

With 0.10.12 (my target since thats what Modulus is running by default) get the following build warnings as well.

CXX(target) Release/obj.target/pdfwriter/src/deps/PDFWriter/CharStringType2Interpreter.o
../src/deps/PDFWriter/CharStringType2Interpreter.cpp: In member function 'IOBasicTypes::Byte* CharStringType2Interpreter::InterpretRandom(IOBasicTypes::Byte*)':
../src/deps/PDFWriter/CharStringType2Interpreter.cpp:989:60: warning: integer overflow in expression

CXX(target) Release/obj.target/pdfwriter/src/deps/PDFWriter/DocumentContext.o
../src/deps/PDFWriter/DocumentContext.cpp: In member function 'void PDFHummus::DocumentContext::WriteCatalogInformationState(ObjectsContext*, ObjectIDType)':
../src/deps/PDFWriter/DocumentContext.cpp:1329:15: warning: 'rootNodeID' may be used uninitialized in this function

CXX(target) Release/obj.target/pdfwriter/src/deps/PDFWriter/PDFParser.o
../src/deps/PDFWriter/PDFParser.cpp: In member function 'PDFObject* PDFParser::ParseExistingInDirectStreamObject(ObjectIDType)':
../src/deps/PDFWriter/PDFParser.cpp:1514:13: warning: 'anObject' may be used uninitialized in this function

CXX(target) Release/obj.target/pdfwriter/src/deps/PDFWriter/PDFUsedFont.o
../src/deps/PDFWriter/PDFUsedFont.cpp: In member function 'PDFHummus::EStatusCode PDFUsedFont::WriteState(ObjectsContext*, ObjectIDType)':
../src/deps/PDFWriter/PDFUsedFont.cpp:117:15: warning: 'writtenFontObject' may be used uninitialized in this function

NPM Install Spaces in Path

I recently installed HummusJS with npm install hummus to a directory that had spaces in the path, and received clang: error: no such file or directory: for the space separated portions of the path. This occurs in the build process as follows:

$ npm install hummus
-
> [email protected] install PATH_WITH_SPACES
> node-gyp rebuild

CXX(target) Release/obj.target/pdfwriter/src/deps/PDFWriter/AbstractContentContext.o
clang: error: no such file or directory: ....

I solved the issue by moving the project to a path without spaces, at which point npm install hummus worked as desired.

Failing to install Hummus on Windows Server 2012

Hi,

I am not sure if the problem is me or it is residing somewhere else. I am unable to install Hummus on our Windows 2012 Server.

This is the message from npm:

> [email protected] install C:\inetpub\wwwroot\dossier\api\node_modules\hummus
> node-pre-gyp install --fallback-to-build


C:\inetpub\wwwroot\dossier\api\node_modules\hummus>if not defined npm_config_nod
e_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no
de_modules\node-gyp\bin\node-gyp.js" clean )  else (node  clean )

C:\inetpub\wwwroot\dossier\api\node_modules\hummus>if not defined npm_config_nod
e_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no
de_modules\node-gyp\bin\node-gyp.js" configure --fallback-to-build --module=C:\i
netpub\wwwroot\dossier\api\node_modules\hummus\binding\hummus.node --module_name
=hummus --module_path=C:\inetpub\wwwroot\dossier\api\node_modules\hummus\binding
 )  else (node  configure --fallback-to-build --module=C:\inetpub\wwwroot\dossie
r\api\node_modules\hummus\binding\hummus.node --module_name=hummus --module_path
=C:\inetpub\wwwroot\dossier\api\node_modules\hummus\binding )

C:\inetpub\wwwroot\dossier\api\node_modules\hummus>if not defined npm_config_nod
e_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no
de_modules\node-gyp\bin\node-gyp.js" build --fallback-to-build --module=C:\inetp
ub\wwwroot\dossier\api\node_modules\hummus\binding\hummus.node --module_name=hum
mus --module_path=C:\inetpub\wwwroot\dossier\api\node_modules\hummus\binding )
else (node  build --fallback-to-build --module=C:\inetpub\wwwroot\dossier\api\no
de_modules\hummus\binding\hummus.node --module_name=hummus --module_path=C:\inet
pub\wwwroot\dossier\api\node_modules\hummus\binding )
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
C:\inetpub\wwwroot\dossier\api\node_modules\hummus\build\src\deps\PDFWriter\pdf
writer.vcxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Def
ault.props" was not found. Confirm that the path in the <Import> declaration is
 correct, and that the file exists on disk.
C:\inetpub\wwwroot\dossier\api\node_modules\hummus\src\deps\FreeType\freetype.v
cxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.pro
ps" was not found. Confirm that the path in the <Import> declaration is correct
, and that the file exists on disk.
C:\inetpub\wwwroot\dossier\api\node_modules\hummus\src\deps\LibJpeg\libjpeg.vcx
proj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props
" was not found. Confirm that the path in the <Import> declaration is correct,
and that the file exists on disk.
C:\inetpub\wwwroot\dossier\api\node_modules\hummus\src\deps\ZLib\zlib.vcxproj(2
0,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was
not found. Confirm that the path in the <Import> declaration is correct, and th
at the file exists on disk.
C:\inetpub\wwwroot\dossier\api\node_modules\hummus\src\deps\LibTiff\libtiff.vcx
proj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props
" was not found. Confirm that the path in the <Import> declaration is correct,
and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\
npm\node_modules\node-gyp\lib\build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_proces
s.js:200:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodej
s\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallb
ack-to-build" "--module=C:\\inetpub\\wwwroot\\dossier\\api\\node_modules\\hummus
\\binding\\hummus.node" "--module_name=hummus" "--module_path=C:\\inetpub\\wwwro
ot\\dossier\\api\\node_modules\\hummus\\binding"
gyp ERR! cwd C:\inetpub\wwwroot\dossier\api\node_modules\hummus
gyp ERR! node -v v4.2.2
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp.cmd build --fallback-
to-build --module=C:\inetpub\wwwroot\dossier\api\node_modules\hummus\binding\hum
mus.node --module_name=hummus --module_path=C:\inetpub\wwwroot\dossier\api\node_
modules\hummus\binding' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\inetpub\wwwroot\doss
ier\api\node_modules\hummus\node_modules\node-pre-gyp\lib\util\compile.js:83:29)

node-pre-gyp ERR! stack     at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:818:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/chi
ld_process.js:211:5)
node-pre-gyp ERR! System Windows_NT 6.3.9600
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\inetpub\\ww
wroot\\dossier\\api\\node_modules\\hummus\\node_modules\\node-pre-gyp\\bin\\node
-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd C:\inetpub\wwwroot\dossier\api\node_modules\hummus
node-pre-gyp ERR! node -v v4.2.2
node-pre-gyp ERR! node-pre-gyp -v v0.6.13
node-pre-gyp ERR! not ok
Failed to execute 'node-gyp.cmd build --fallback-to-build --module=C:\inetpub\ww
wroot\dossier\api\node_modules\hummus\binding\hummus.node --module_name=hummus -
-module_path=C:\inetpub\wwwroot\dossier\api\node_modules\hummus\binding' (1)
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install" "hummus" "--save"
npm ERR! node v4.2.2
npm ERR! npm  v2.14.7
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-pre-gyp install --fall
back-to-build'.
npm ERR! This is most likely a problem with the hummus package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR!     npm owner ls hummus
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\inetpub\wwwroot\dossier\api\npm-debug.log

Please assist!

Kind regards.

Exception when calling writePage() after adding text to all pages for certain PDFs

Hello,

we are implementing a service that serves customized PDFs to paying customers. We are adding personal information as text to every page of the PDF, then save it and serve it to the user.
Unfortunately, we get an exception for a few PDFs, and I'm not sure what the poblem is. I'm not familiar with the internal structure of a PDF, so I can't make much out of the source code section in question.
Here is roughly what I'm doing:

    pdfReader = PDF.createReader(_this.filename);
    pageCount = pdfReader.getPagesCount();
    pdf = PDF.createWriterToModify(_this.filename);
    var page = 0;
    for (page = 0, page <= pageCount - 1; page++) {
      pageModifier = new PDF.PDFPageModifier(pdf, page);
      pageContext = pageModifier.startContext().getContext();
      lines = options.text.split("\n");
      y = ANNOTATION_INSET * (lines.length + 1);
      var j = 0;
      for (j = 0, j < lines.length; j++) {
        line = lines[j];
        pageContext.writeText(line, ANNOTATION_INSET, y, {
          font: pdf.getFontForFile(fontFilepath),
          size: FONT_SIZE,
          colorspace: 'rgb',
          color: 0xFF0000
        });
        y -= FONT_SIZE;
      }
      pageModifier.endContext().writePage();
    }
    pdf.end();

It works flawlessly for most of our PDFs, but for some I get

TypeError: Cannot call method 'toJSObject' of undefined
at writeModifiedResourcesDict (/home/www-content/app/node_modules/hummus/hummus.js:433:64)
at PDFPageModifier.writePage (/home/www-content/app/node_modules/hummus/hummus.js:365:34)

The affected PDFs also seem to have this problem only at specific page within the PDF. The outer loop iterates over the first few pages without problems, then the exception is thrown always for the same page.

If you need example PDFs, let me know, I can send you 2 examples where this happens reproducibly.
(we are using hummus.js v 1.0.36)

Embed multiple PDFs into an already existing PDF

I can see how to embed multiple PDFs into a new document, using pdfWriter.mergePDFPagesToPage(), but I'm having trouble figuring it out when I want to do the same thing, but to an already existing page.

The page parameter used in pdfWriter.mergePDFPagesToPage() in all of your examples was obtained by calling var page = pdfWriter.createPage(0,0,595,842); or similar, but I don't want to create a new page, and I'm not sure how to get the correct value to pass as the page parameter to pdfWriter.mergePDFPagesToPage()

NEW! "unable to append page, make sure it's fine"

Hi galkahana,

First off, thanks SOOO much for all you've built with HummusJS, it's great!

And to the issue I'm having, I've been using Hummus for a couple weeks now and it's working great! But this morning I grabbed a 'test-pdf' www.orimi.com/pdf-test.pdf and tried to merge it with another document that I know has been clean/worked in the past, and I got this error:

"unable to append page, make sure it's fine"

Here's a snippet of the code I'm using (note, I'm using underscore):

var pdfWriter = hummus.createWriter(outputPDFFilePath);

_.each(arrayOfFilePathsToAppend , function(nextFileToAppend) {
      pdfWriter.appendPDFPagesFromPDF(nextFileToAppend);
})

pdfWriter.end();

I don't usually have control over the pdfs that I need to append... Is there some way this can be fixed or that I can 'help' hummusJS by using a different method or providing more information?

Thanks so much for your help and for all you've done!

hummus doesn't build on node.js 4.0 :-(

As the subject says, I tried to install with node.js 4.0 (the new stable release) and it didn't work; though y'all should know

  CXX(target) Release/obj.target/hummus/src/hummus.o
../src/hummus.cpp:124:26: error: call to member function 'StartPDF' is ambiguous
        status = driver->StartPDF(*String::Utf8Value(args[0]->ToString()), pdfVersion,logConfig,PDFCreationSettings(compressStr...
                 ~~~~~~~~^~~~~~~~
../src/PDFWriterDriver.h:64:28: note: candidate function
    PDFHummus::EStatusCode StartPDF(const std::string& inOutputFilePath,
                           ^
../src/PDFWriterDriver.h:68:28: note: candidate function
    PDFHummus::EStatusCode StartPDF(v8::Handle<v8::Object> inStreamObject,
                           ^
../src/hummus.cpp:311:26: error: call to member function 'StartPDFParsing' is ambiguous
        status = driver->StartPDFParsing(*String::Utf8Value(args[0]->ToString()));
                 ~~~~~~~~^~~~~~~~~~~~~~~
../src/PDFReaderDriver.h:40:28: note: candidate function
    PDFHummus::EStatusCode StartPDFParsing(const std::string& inParsedFilePath);
                           ^
../src/PDFReaderDriver.h:41:28: note: candidate function
    PDFHummus::EStatusCode StartPDFParsing(v8::Handle<v8::Object> inStreamObject);
                           ^
2 errors generated.
make: *** [Release/obj.target/hummus/src/hummus.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 14.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/richard/code/hamstudy/node_modules/hummus
gyp ERR! node -v v4.0.0
gyp ERR! node-gyp -v v3.0.1
gyp ERR! not ok
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--save" "[email protected]"
npm ERR! node v4.0.0
npm ERR! npm  v2.14.2
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the hummus package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls hummus
npm ERR! There is likely additional logging output above.

text alignment for PDF

Hi,

I'm using this module to create PDF Files.
I need some texts alignment properties like center, left align or right align.
Does HummusJS support this one?
Because it's not useful for me to use the constant location.

Thanks in advance.

Issue using RGB colors with low level text operators

Hi Gal

I'm needing to use the low level pdf operators (as I needed to map some glyphs differently) but I can't seem to get RGB colors working (.k and .g work fine)

Easiest to show issue using a test:

{
var pdfWriter = hummus.createWriter('./output/SimpleTextUsageRGB.pdf');

var page = pdfWriter.createPage(0,0,595,842);

var font = pdfWriter.getFontForFile('./TestMaterials/fonts/arial.ttf'); 
pdfWriter.startPageContentContext(page).BT()
                                    .rg(1,0,0)
                                    .Tf(font,1)
                                    .Tm(30,0,0,30,78.4252,662.8997)
                                    .Tj("abcd")
                                    .ET();

var textOptions = {font:font,size:30,colorspace:'rgb',color:0xFF0000};                                      
pdfWriter.startPageContentContext(page).writeText('efgh',78.4252,562,textOptions)
pdfWriter.writePage(page)
        .end();

}

This is based on one of the existing test that uses CMYK color - I've just changed to use .rg(1,0,0)
The "abcd" text shows black in the resulting PD for meF. I have no issue using writeText with RGB colors - the "efgh" shows correctly in red.

Am I using the .rg operator right here?

Thanks,
Ross

Font as outline

Many printing services don't accept pdf's where the font is embedded. They require the font to be provided as "outline" It would be nice if there was an option where all written text is stored as shapes instead of font.

Instructions for running tests

I'm trying to add a test to reproduce the other issue I opened. I've run node-gyp rebuild successfully but when I run node runTests all the tests fail with an error like this:

geoff@nova:~/git/HummusJS$ node runTests.js

/home/geoff/git/HummusJS/tests/BasicJPGImagesTest.js:1
dule, __filename, __dirname) { var pdfWriter = require('../hummus').createWrit
^
TypeError: Unable to create PDF file, make sure that output file target is available
at Object. (/home/geoff/git/HummusJS/tests/BasicJPGImagesTest.js:1:100)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

XObject retrieval

I'm trying to get XObject from PDFParser, following the example from here, but converting it to node.js.

So far I have:

hummus = require 'hummus'
pdfReader = hummus.createReader './test.pdf'
page = pdfReader.parsePage 0
resources = pdfReader.queryDictionaryObject(page.getDictionary(), "Resources")
xobjects = pdfReader.queryDictionaryObject(resources, "XObject")

Converting resources to a JS object shows there are is no XObject defined, and so xobjects is undefined. Are you able to shed some light / point me in the right direction for how to accomplish this?

Main file name and package.json

Main filename is "Hummus.js"
package.json refer to "hummus"

#package.json
...
"version": "1.0.22",
"main": "hummus",
...

There is an error on Linux on require module

var hummus = require('hummus');

will give

Error: Cannot find module 'hummus'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

HummusJS build error.

Hi galkahana, first of all congratulations on the superb job you all have been doing creating this tool. I wanted to the PDF output full-fledged node.js.

deps folder fix PDF-Writer use / https://github.com/dai-yamashita/PDF-Writer/commit/506c1c219c051c0c6823b184a8e71b57cecdcef1

but node-gyp build error.

  CC(target) Release/obj.target/freetype/deps/FreeType/src/base/ftinit.o
make: *** No rule to make target `Release/obj.target/freetype/deps/FreeType/src/lzW/ftlzw.o', needed by `Release/obj.target/deps/FreeType/freetype.a'.  Stop.
make: Leaving directory `/home/admin/HummusJS/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/dai_yamashita/nvm/v0.10.1/lib/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:754:12)
gyp ERR! System Linux 3.8.4-202.fc18.x86_64
gyp ERR! command "node" "/home/dai_yamashita/nvm/v0.10.1/bin/node-gyp" "build"
gyp ERR! cwd /home/admin/HummusJS
gyp ERR! node -v v0.10.1
gyp ERR! node-gyp -v v0.9.5
gyp ERR! not ok 

soon pull request. deps/FreeType/binding.gyp typo miss.

Add Documentation for Parsing PDFs

Hi!

It seems like you may be actively updating this repo while I'm writing this (or were recently, at least), which is neat. I need a good, simple PDF parser, and I like the concept of this one but there's no documentation, seemingly, for doing the parsing within Node.

I'm also not sure if it installed properly. I tried it twice over the last hour or two and it seems like the files may have changed while I was doing it.

Even more specifically -- and I don't know if this is possible -- I'd like to parse PDFs as they are streamed down from a remote location. You talk about streams on the Hummus homepage, but the language isn't clear to me if that's what it's referring to.

Any chance of getting help on this? Thank you!

Convert multi-page pdf to images?

Hi, is there a way to use HummusJS to convert a multi-page pdf to a series of images? I didn't see any documentation or examples on how to do this.

build error (PDFDateDriver.cpp:93:57: error: 'labs' was not declared in this scope)

Hi galkahana.

now build 9535ffa.

but build error.

 CXX(target) Release/obj.target/Hummus/src/PDFDateDriver.o
../src/PDFDateDriver.cpp: In static member function 'static v8::Handle<v8::Value> PDFDateDriver::New(const v8::Arguments&)':
../src/PDFDateDriver.cpp:93:57: error: 'labs' was not declared in this scope
make: *** [Release/obj.target/Hummus/src/PDFDateDriver.o] Error 1

RTL support

I am trying to write Arabic text using the writeText function, but I am unable to figure out how to set the direction to be RTL. It is mentioned here that RTL support was added to the rendering service, so i guess there must be some way in Hummus to specify the direction?

Copy PDF pages to multiple destinations with one pdfWriter

I'm trying to take each page of a PDF, pass it through a hash, and write the page to file. Since this needs to be efficient I'm making use of streaming. The solution below works perfectly, but it's incredibly slow ~7s for a 44 page document (for obvious reasons).

Ideally only one pdfWriter would need to be created. I tried this in many different ways, but the main stumbling block is that pdfWriter.end() is necessary to make the resulting PDF valid. Since end can only be called once per pdfWriter, a pdfWriter per page needs to be created. I tried hacking this and storing the result from end() in a separate buffer and appending it to all pages, but that trick doesn't work. I also tried storing the context, but that doesn't work either. Cloning the pdfWriter doesn't work. createPDFCopyingContext doesn't accept a stream...

I'm all out of ideas! Are you able to make any suggestions on how this may be done efficiently? Or suggest where my reasoning is wrong? Thank you!

crypto = require 'crypto'
fs = require 'fs'
hummus = require('hummus')
{spawn} = require('child_process')
{Writable,PassThrough} = require 'stream'

getHash = ->
  hash = crypto.createHash 'sha1'
  hash.setEncoding('hex')
  hash

getThrough = ->
  new PassThrough()

# Copied from hummus.js
class PDFWriteForHash
  constructor: ->
    @position = 0
    @hash = getHash()
    @through = getThrough()

  write: (inBytesArray) ->
    if(inBytesArray.length > 0)crypto = require 'crypto'
      buf = new Buffer(inBytesArray)
      try @hash.write buf
      @through.write buf
      @position += inBytesArray.length
      return inBytesArray.length
    0

  getCurrentPosition: ->
    @position

handlePage = (idx) ->
  kls = new PDFWriteForHash()

  # This should not be called on every loop iteration.
  pdfWriter = hummus.createWriter(kls)
  copyCtx = pdfWriter.createPDFCopyingContext('main.pdf')
  copyCtx.appendPDFPageFromPDF(idx)
  kls.hash.end()
  pdfWriter.end()
  kls.through.end()
  kls.through.pipe(fs.createWriteStream('outputs/' + kls.hash.read() + '.pdf'))

idx = 0
while true
  try handlePage idx
  catch
    break
  idx++

Pre-gyp?

Thanks for the epic library! Are you open to setting up Travis and node-pre-gyp? With it in place it'd remove the need to compile the library on most machines. I could lay most of the groundwork if that'd be helpful. I've been using it for node-gdal (whose compile times are much longer) and it's been super helpful.

Parsing: cannot decode name of field. Characters garbled (question marks)

Hi!
I asked about this issue in other thread here. But I decided renew it and created a new issue for pay more attention for it here.

When I parse PDF receive name of field with incorrectly decoded value (may be wrong charset): e.g: ��. PDF file contains only english text. Why this happens? Should I check charset of PDF file or something other? How to decode such string?

Thanks!

How to modify an existing PDF file

Hi,

I need some help to modify an existing PDF file. I tried to follow the example but honestly I really don't understand the example.

So I've a PDF template file that I need to fill all inputs with many information mainly text but there is images too. Did you have a 'easily' understandable example for that ? :)

Another thing I tried this code. There is only 1 page in the PDF file that I use for my test.

var hummus = require('hummus');

var pdfWriter = hummus.createWriterToModify(
    './statement.pdf',
    {
        modifiedFilePath: './output/statement.pdf'
    }
);

pdfWriter.end();

It works but the newly created PDF file have now 2 pages ... the same page duplicated .. Is it normal ?

var hummus = require('hummus');

var pdfWriter = hummus.createWriterToModify(
    './statement.pdf',
    {
        modifiedFilePath: './output/statement.pdf'
    }
);

var context = pdfWriter.createPDFCopyingContextForModifiedFile(),
    contextParser = context.getSourceDocumentParser();

console.log(context);
console.log(contextParser.getPagesCount());

pdfWriter.end();
19 Jun 15:27:29 - [nodemon] starting `node index.js`
{}
2
19 Jun 15:27:29 - [nodemon] clean exit - waiting for changes before restart

Thank you.

PDFParser::StartPDFParsing returns failure for some PDFs

Hi,
For some PDFs PDFParser::StartPDFParsing returns failure. After an investigation I found out that the problem caused when parsing the Trailer dictionary, the failure prints to the log is: TRACE_LOG("PDFParser::ParseTrailerDictionary, failure to parse trailer dictionary");

In order to reproduce this issue you only need to execute the following lines.

InputFile pdfFile;
pdfFile.OpenFile(m_FilePath);

PDFParser pdfParser;
if (pdfParser.StartPDFParsing(pdfFile.GetInputStream()) == PDFHummus::eFailure)
return false;

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.