Comments (4)
Two options:
- 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 - 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.
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.
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.
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)
- How to draw Bezier curves using PDF-Witer library? HOT 2
- Parse a screenplay into scene objects? HOT 2
- color emojis HOT 16
- Links are removed when documents are merged HOT 8
- Color inversion problem occurs when exporting images HOT 1
- infinite loop HOT 2
- Crash when WriteUsedFontsDefinitions HOT 17
- Publish to github releases without PDFWriterTesting HOT 4
- U3D support, 10 years later HOT 10
- `Segmentation fault (core dumped)` just for adding `PDFWriter pdfWriter` in the `h` file HOT 11
- Fail to draw rectangle to pdf,if rectangle larger than(595x842) HOT 2
- german umlaute diacritic not rendered properly HOT 2
- Make a PDF with an image in memory HOT 4
- Double hex encoding in AbstractContentContext::TJHexLow HOT 3
- Perfectly kosher bug :) HOT 13
- bug: Stack overflow with Invalid PageTree HOT 1
- bug: Stack Overflow when loop in ParseNewObject -> ParseExistingInDirectStreamObject HOT 1
- bug: Requested Allocation Size too big HOT 2
- bug: Heap Use-after-free HOT 1
- bug: Allocation size too big when /Count is high HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdf-writer.