PDF — — pdf Invalid PDF structure/Warning: Ignoring invalid character ...

本文记录了使用vue-pdf加载PDF文件时遇到的跨域问题及解决过程。前端尝试处理跨域未果,最终通过后端配置解决。文章强调了PDF跨域问题前端难以独立解决,需后端配合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近接手了一个遗留的PDF报错任务,用vue-pdf获取服务器PDF报Warning: Ignoring invalid character “XX” in hex string错误

排错历程

  1. console.log获取的内容
      this.src = pdf.createLoadingTask(this.src)
      .then(res => {
         console.log(res)
      }).catch(err => {
         console.log(err)
      })

发现没有获取成功,报 Invalid PDF structure

  1. 寻找报错原因

Status Code: 200 OK,但是返回的内容是空

  1. 初步怀疑是跨域问题

但是前端同事说他已经处理了跨域,也确实没有报跨域错误

this.src = 'http://111.11.1.1/xxx/xxx/xxx.pdf'
this.src = this.src.replace('http://111.11.1.1', 'dev-api')
this.src = pdf.createLoadingTask(this.src)
  1. 继续寻找错误

多篇文章指向是跨域问题

  1. 后端配置跨域,问题解决

把找的文章甩给后端,PDF跨域前端配置不能解决问题,需要让后端去配置跨域。后端配置问题解决

遇到Warning: Ignoring invalid character … 可以先看看是不是后端的跨域没有配置
n file included from src/lab1/step1/step1.c:1:0: src/lab1/step1/../linklist.h: In function ‘addPoly’: src/lab1/step1/../linklist.h:62:7: error: expected identifier or ‘(’ before numeric constant PNODE 1=polyAddLeft->next; ^ src/lab1/step1/../linklist.h:65:8: warning: comparison between pointer and integer while(1!=NULL && r!=NULL) ^~ src/lab1/step1/../linklist.h:67:7: error: invalid type argument of ‘->’ (have ‘int’) if(1->exp==r->exp) ^~ src/lab1/step1/../linklist.h:70:16: error: invalid type argument of ‘->’ (have ‘int’) temp->exp=1->exp; ^~ src/lab1/step1/../linklist.h:71:17: error: invalid type argument of ‘->’ (have ‘int’) temp->coef=1->coef+r->coef; ^~ src/lab1/step1/../linklist.h:75:8: error: invalid type argument of ‘->’ (have ‘int’) 1=1->next; ^~ src/lab1/step1/../linklist.h:78:12: error: invalid type argument of ‘->’ (have ‘int’) else if(1->exp < r->exp) ^~ src/lab1/step1/../linklist.h:81:16: error: invalid type argument of ‘->’ (have ‘int’) temp->exp=1->exp; ^~ src/lab1/step1/../linklist.h:82:17: error: invalid type argument of ‘->’ (have ‘int’) temp->coef=1->coef; ^~ src/lab1/step1/../linklist.h:86:8: error: invalid type argument of ‘->’ (have ‘int’) 1=1->next; ^~ src/lab1/step1/../linklist.h:98:7: warning: comparison between pointer and integer if(1==NULL) sign=r; ^~ src/lab1/step1/../linklist.h:99:20: warning: assignment makes pointer from integer without a cast [-Wint-conversion] if(r==NULL) sign=1; ^ src/lab1/step1/../linklist.h: In function ‘printPoly’: src/lab1/step1/../linklist.h:132:7: error: expected ‘;’ before ‘printf’ printf("%dx^%d",p->coef,p->exp) ^~~~~~
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值