Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding text into existing pdf #120

Open
code-by opened this issue Nov 17, 2016 · 8 comments
Open

adding text into existing pdf #120

code-by opened this issue Nov 17, 2016 · 8 comments

Comments

@code-by
Copy link

code-by commented Nov 17, 2016

I need to add text to first page of existing pdf. I try this, but new pdf not opened in some pdf-viewers, adobe reader don't render new text.
Here is my code:

const hummus = require('hummus');
const pdfWriter = hummus.createWriterToModify(__dirname + '/existing.pdf', {
  modifiedFilePath: __dirname + '/output.pdf',
});
const pageModifier = new hummus.PDFPageModifier(pdfWriter, 0);
pageModifier.startContext().getContext().writeText(
  'Test Text', 10, 10
);
pageModifier.endContext().writePage();
pdfWriter.end();

is there is mistake, thank you

@galkahana
Copy link
Owner

should specify font/color/size. you're missing this

@code-by
Copy link
Author

code-by commented Nov 17, 2016

@galkahana how to get font in existing pdf file instead get font from ttf file?

@galkahana
Copy link
Owner

Doesn't work like that. have to have the font file. you could theoretically extract the font from the pdf to a file and use it like that, but given that the font may not be embedded, or that it will have just the glyphs used and not necessarily those you want to use, i wouldn't recommend this as a path.

wanna tell more about the scenario you have in mind?

@code-by
Copy link
Author

code-by commented Nov 17, 2016

I simply need add text using fonts already embedded in pdf. I saw some other node packages for creating pdf files and these don't needed external font file, but these packages don't allow modify existing pdf.

@galkahana
Copy link
Owner

K. Cant do that. Need to specify the font

@galkahana
Copy link
Owner

wanna give this a try? - https://www.npmjs.com/package/font-manager

@aathirag
Copy link

aathirag commented Jul 4, 2018

For me also after writing text. pdf is not opening in Adobe Reader. What I have to do for opening in Adobe Reader. It's opening in Browser and in ubuntu system default pdf reader.

@mohammedabualsoud
Copy link

mohammedabualsoud commented Oct 2, 2019

@galkahana It works when I added the fonts. My question is I have the position of a specific object which is a text it's form is like this:

placement { text: '{{C1}}',
  matrix: [ 1, 0, 0, 1, 168.912, 643.602 ],
  localBBox: [ 0, -2.898, 36.596000000000004, 10.052 ],
  globalBBox: [ 168.912, 640.704, 205.508, 653.654 ] }

How can I remove that object or better delete that object and render a new text on top of it.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants