unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.54k stars 250 forks source link

[FEATURE] Structured optimizer interface #343

Closed gunnsth closed 4 years ago

gunnsth commented 4 years ago

Is your feature request related to a problem? Please describe. Currently the Optimizer interface only gets a slice of objects, no context as to what the objects fit into the document structure.

This is somewhat limiting since we can only consider either consider each object individually, otherwise we need to check the object relationships, which is inadequate since we already have all the information.

To do this without breaking changes could be to add another interface such as StructuredOptimizer {} that gets the catalog and pages dictionaries as inputs, or a struct so we can add more properties in the future.

Describe the solution you'd like Access to the Catalog, and Pages models would be useful.

The tricky part is that the optimize class cannot import model, so these need to be passed dictionaries.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context The alternative is to detect the Catalog by looping through all objects. And making a map of object numbers to object. Then inferring the structure. This seems inefficient and inaccurate since we already have more information.

gunnsth commented 4 years ago

Working from the Catalog and Pages is actually not bad and is flexible in terms of handling data from multiple input files etc. See for example implementation in https://github.com/unidoc/unipdf/pull/362