pdfcpu / pdfcpu

A PDF processor written in Go.

Home Page:http://pdfcpu.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Throw errors instead of os.Exit of invalid fonts

vedantmamgain opened this issue · comments

I faced an os.Exit when pdfcpu tried to perform pdf operation on a pdf with invalid font with the following log.
pdfcpu: user font not loaded: Arial.

I looked in the code an found the following line where we are doing an os.Exit instead of returning an error.

This is intentional!
Show me your stack trace.

@hhrutter I got pdfcpu: user font not loaded: Arial when trying to fill a pdf.

Why is this behaviour of throwing an os.Exit intentional, I'm using the PDFCPU API instead of CLI hence wouldn't we want to throw errors instead.

Show me your stack trace.
You should have gotten an error way before that!

Bottomline: You have to ensure you have all user fonts installed that you will need for your operation.

I need more info about what you are doing in oder to analyze this.

Even if the API is used in an incompatible way, using os.Exit in library code is considered bad practice. Better would be to use panic(fmt.Sprintf("pdfcpu: user font not loaded: %s", fontName)) here so it could be catched by the application while still aborting a commandline tool.

This is a judgement call and pdfcpu is still Alpha.
It's more an indication for that you should never ever get into this situation.
Instead of digressing I'd still like to get to the root of this and in order to do so I need more info.

@hhrutter There wasn't any other error before the os.Exit.

I need to see what you are doing in order to follow up.

@hhrutter I'm using the pdfcpu api's fill function on pdfs which are fetched from s3. I got the above os.Exit message when trying to perform fill action on a pdf. Following is my model configuration

	modelConfig := model.NewDefaultConfiguration()
	modelConfig.Reader15 = true
	modelConfig.WriteXRefStream = true
	modelConfig.NeedAppearances = true

Also before filling, I'm performing the optimise action on the pdfs as well.

There should have been a check if the font in question is installed as one of your pdfcpu user fonts prior to os.exiting.
In order to track that down I need to see a full stacktrace please.

@hhrutter Are you talking about checks in pdfcpu or checks that I should implement. I've verified the error log and post downloading the file from s3 the only log that I can see is pdfcpu: user font not loaded: Arial%