Giter Club home page Giter Club logo

Comments (4)

galkahana avatar galkahana commented on July 20, 2024

Two options:

  1. use helvetica font with PDFUsedFont but don't embed glyphs. Not embedding happens when calling the PDFWriter objct StartPDF and using false on EmbedFonts flag - https://github.com/galkahana/PDF-Writer/blob/master/PDFWriter/PDFWriter.h#L58
  2. The TFLow method: create you own font dictionary, register as a page/form resource and use with TFLow. For this follow the example in the PDF specs 5.1.1:

Create a font object

23 0 obj
<< /Type /Font
/Subtype /Type1
/BaseFont /Helvetica
>>
endobj

You can use the library extensibility options here to create the object and the dictionary. see here for documentation - extensibility and in particular the objects context. There's an example here of creating a new object, which if you get can save you reading the help.

When creating the object you will use the method StartNewIndirectObject. it will return the new object ID. save it somewhere, you'll need it for the later stage.

Create reference from page/form resources dictionary

To use with the TF operator you have to create reference to the object with a font name in the relevant page/form resource dictionary, as is shown in the specs here:

/Resources
<< /Font << /F13 23 0 R >>
>>

You will probably have a PDFPage object lying around somewhere, so assuming you got the object ID for the font dictionary object you just created in fontDictObjID you should be able to register the font like this:

page.GetResourcesDictionary(). AddFontMapping(fontDictObjID)

The return value from this call will give you as string that you can now use with TFLow.

use with TFLow

In the content stream just call the content context TFLow method with the name that you got.

Regards,
Gal.

from pdf-writer.

raimundomartins avatar raimundomartins commented on July 20, 2024

Nice, thank you for the very detailed response! I think you should include this in the wiki it's already nicely structured.

I do have a follow-up question: What about metrics? I don't have a handle to PDFUsedFont this way. What would you suggest? I've considered creating a FreeTypeWrapper, calling NewFace and manually creating a PDFUsedFont, but this seems to duplicate work your library already does, and extra FT_Library stuff.

An alternative would be to only embed the required fonts. I noticed the WriteState() and WriteFontDefinition() methods of PDFUsedFont. Can I (and how to) use these and StartPDF() without embedding fonts to "safely/cleanly" create a PDFUsedFont from PDFWriter and have extra fonts embedded?

Which do you htink would be the better method?

Thank you.

from pdf-writer.

galkahana avatar galkahana commented on July 20, 2024

Sounds like you want to simply have a choice of which fonts to embed and which not to, no? Right now i have all or nothing. How about we change the lib to allow definig on a used font whether it should be embedded or not? Or add a general flag on pdfwrite to embed (when embedding) onlu fonts that are not part of the default 14th?

from pdf-writer.

raimundomartins avatar raimundomartins commented on July 20, 2024

Sounds like you want to simply have a choice of which fonts to embed and which not to, no?

That and easy metrics for Base 14. From what I read in specs, metrics can be found somewhere here.

Maybe you can add PDFUsedFont* GetFontBase14() methods in which one can specify which of the Base 14 fonts this is (files are still required for metrics and glyphs translation).
Then add 2 flags to PDFUsedFont: isBase14 (for the auto embedding of non base 14 fonts) and allowEmbedding (this one settable by user). Final cost: 2 bools and 1 or 2 methods, no major rewrite/incompatibilities.

Or something like that... As a user I'd like that interface :)

from pdf-writer.

Related Issues (20)

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.