galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.15k stars 170 forks source link

added text not visible #154

Open nnnikolay opened 7 years ago

nnnikolay commented 7 years ago

Hi Gal.

Thanks for your tests in the test folder, using it I was able to modify existing pdf file, but the funny thing is, not every PDF can be modified using the same approach. I've tried to apply the same technic to my files and 90% of them was not modified (I mean, the changes were not visible). Is there a way how to figure out what is the reason for that? Maybe, some z-position instruction required?

P.S. One more thing I've found that HummusJS does not throw any exception if pdf file or font file not found, it would be great if it would do it. is there a way how to get more details (debug log)? because with some pdf files HummusJS does not work at all :(

Best,

galkahana commented 7 years ago

Theres log option. Check the docs. As for modification, itd be good if you know where would be a sensible position to place an element so you can see it. Consider the page dimensions. Try adding true as the last param of pagemodifier constructor

nnnikolay commented 7 years ago

Hi @galkahana

Sorry for such a big delay in the answer, it was quite busy weeks :)

I've tried your recommendations but it does not work for me, maybe I missing something.

Here is the code what I use

var pdfWriter = hummus.createWriterToModify(sourceRoot + '/data/input.pdf', {
    modifiedFilePath: sourceRoot + '/data/output.pdf'
});

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

pageModifier.startContext().getContext().writeText(
    'QwErT',
    75, 805,
    {font:pdfWriter.getFontForFile(sourceRoot + '/fonts/arial.ttf'),size:24,colorspace:'gray',color:0x00}
);

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

it works with that file input-5.pdf

and does not work with that input.pdf

nnnikolay commented 7 years ago

@galkahana do you have any ideas? Am I doing any mistake in the code?

galkahana commented 7 years ago

you are placing the text outside of the page boundaries. thats why you don't see it.

nnnikolay commented 7 years ago

@galkahana Thanks for your answers, one question in this topic is still left not covered. I was not able to found the answer in WiKi section, why y for writeText is starting from the bottom of the page? I was thinking that 0,0 it's a top left corner, am I wrong in that?

Thanks

galkahana commented 7 years ago

Thats how pdf works. Plain old cartesian coordinate system. Starts from left bottom and goes up and right

nnnikolay commented 7 years ago

@galkahana thanks, I did not know that