본문 바로가기
Study/error 삽질

[FPDF] Failed to initialize parser: Failed to read pdf: Failed to read xref table: Expected xref to start with ‘xref’. Got: 103

by 코딩여걸 2022. 9. 7.
728x90

GoFPDF로 PDF template을 import 하려고 하는데 계속 이런 에러가 발생했다.

> Failed to initialize parser: Failed to read pdf: Failed to read xref table: Expected xref to start with ‘xref’. Got: 103

https://github.com/phpdave11/gofpdi/issues/16

 

Failed to initialize parser: Failed to read pdf: Failed to read xref table: Expected xref to start with 'xref' · Issue #16 · p

Certain formats of PDF documents do not contain the xref table which is causing the parsing error. Attaching the pdf so you can duplicate the error. example_012a.pdf

github.com

 

계속 검색을 해보다가 gofpdi 버전을 최신으로 업데이트 해봤다.

그랬더니 이제 잘 된다 ㅎㅎ


해결방법

Terminal에 밑에 사진처럼 입력해준다.

> go get github.com/phpdave11/gofpdi

 

이렇게 해주면 최신 버전으로 업데이트 끝이다!

이제 모든 템플릿이 에러 없이 import 될 것이다.

 

이런 식으로 버전이 바뀌어 있다~~


여기서 추가로

이렇게 해도 pdf template이 나오지 않거나 빈 화면으로 나오는 경우도 있다.

 

나는 업데이트 이전에

tplid := gofpdi.ImportPage(pdf, "sample.pdf", 1, "/ArtBox")

이렇게 ArtBox로 했었다.

 

근데 잘 안뜬다면

tplid := gofpdi.ImportPage(pdf, "sample.pdf", 1, "/MediaBox")

ArtBox를 MediaBox로 바꿔주면 된다!

 

그럼 해결~!

728x90

댓글