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

api: return structs #621

Closed
CNLHC opened this issue May 16, 2023 · 5 comments
Closed

api: return structs #621

CNLHC opened this issue May 16, 2023 · 5 comments
Assignees

Comments

@CNLHC
Copy link

CNLHC commented May 16, 2023

func ListAnnotations(ctx *model.Context, selectedPages types.IntSet) (int, []string, error) {

currently, the ListAnnotation API returns a string array and each element in the array represents a line in the formatted output.

The extra parsing work is very inconvenient for the downstream program to integrate with this API.

What do you think about splitting the output format logic and annotations list logic? The API can return a Golang object and the cmd module can cover the formatting work.

@hhrutter
Copy link
Collaborator

Hi!

Interesting, please explain your usecase.
Thank you!

@hhrutter hhrutter changed the title ListAnnotation API return structure instead of formatted string api: return structs Jul 1, 2023
@geertjanvdk
Copy link

Just facing the same problem. Having an "API", I thought ListImages would indeed return raw information, and the presenting layer (CLI) would then use that raw information to print out. Instead, ListImages returns formatted strings.

Use case: I am generating PDFs using different tools, and I need to test the result. The pdfcpu API part sounded interesting, but it is not really useful if you got to parse strings.

Without breaking things, maybe introduce an SDK, which has all or most functions, but returns indeed (list of) objects? Like in my case []model.Image.

@fbueckle
Copy link

I would also love this. Currently I am using the library to fetch the form fields using ListFormFields and later turn them to read only using LockFormFields. Between those two steps I have to work with the returned string array and for each entry use RegEx to "extract" the IDs which could break at any point if the returned string format changes.

@hhrutter
Copy link
Collaborator

I am going to take up your suggestion, but I am doing this across the board for the whole API.
This will be part of the next release - couple of weeks since we just had a release.

@hhrutter
Copy link
Collaborator

This is part of https://github.com/pdfcpu/pdfcpu/releases/tag/v0.5.0

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

No branches or pull requests

4 participants