Redian新闻
>
问一个关于pdf的问题
avatar
问一个关于pdf的问题# Java - 爪哇娇娃
d*k
1
现在做一个project, 主要是把一个Access 弄成web application. 现在的问题是,在
access里的一个table中,有一个column是以ole object形式存的pdf文件。我用SSIS
把这个table转到了sql server上,这个ole object的column到了sql server 的table
后,给转化成了image的type (觉着也算靠谱儿)
然后我在程序里把这个image 读到一个byte[]里,试图render 到web page:
byte[] pdf = pdfServcie.getPdfByte();
ServletOutputStream out = response.getOutputStream();
response.setContentType("application/pdf");
out.write(pdf);
out.flush();
.....
然后browser给了个错误:File does not begin with '%PDF-'
看了看database, 所有的pdf image data 都类
avatar
m*t
2
pdf files are supposed to begin with "%PDF-".
So after this line:
byte[] pdf = pdfServcie.getPdfByte();
If you write the byte array to a local file, can you
open it in acrobat reader?

table

【在 d**k 的大作中提到】
: 现在做一个project, 主要是把一个Access 弄成web application. 现在的问题是,在
: access里的一个table中,有一个column是以ole object形式存的pdf文件。我用SSIS
: 把这个table转到了sql server上,这个ole object的column到了sql server 的table
: 后,给转化成了image的type (觉着也算靠谱儿)
: 然后我在程序里把这个image 读到一个byte[]里,试图render 到web page:
: byte[] pdf = pdfServcie.getPdfByte();
: ServletOutputStream out = response.getOutputStream();
: response.setContentType("application/pdf");
: out.write(pdf);
: out.flush();

avatar
d*k
3
日!这下完犊子了! 存成文件也打不开,adobe说什么文件类型不支持什么的。我做了个
测试,找了个pdf文件,然后给读成binary,存到数据库里,发现数据都是
0x25:50:44:46:2d........, 跟从access里来的就不一样。
从数据库里把binary code 的开头儿一部分放到一个hex converter 里,再转化成
ascii, 结果就是%PDF-。
用同样的办法把access里来的binary 放进去一看,狗屁都不是。
我估摸着这个binary code可能只有access 自己用个什么内置的东西读出来吧?换个地
方就不灵了。有什么办法能转化一下吗?谢谢了


【在 m******t 的大作中提到】
: pdf files are supposed to begin with "%PDF-".
: So after this line:
: byte[] pdf = pdfServcie.getPdfByte();
: If you write the byte array to a local file, can you
: open it in acrobat reader?
:
: table

avatar
m*t
4
What's the column type in your sql server? Either that's wrong, or your code
actually saved the data as hex strings, instead of raw bytes.

【在 d**k 的大作中提到】
: 日!这下完犊子了! 存成文件也打不开,adobe说什么文件类型不支持什么的。我做了个
: 测试,找了个pdf文件,然后给读成binary,存到数据库里,发现数据都是
: 0x25:50:44:46:2d........, 跟从access里来的就不一样。
: 从数据库里把binary code 的开头儿一部分放到一个hex converter 里,再转化成
: ascii, 结果就是%PDF-。
: 用同样的办法把access里来的binary 放进去一看,狗屁都不是。
: 我估摸着这个binary code可能只有access 自己用个什么内置的东西读出来吧?换个地
: 方就不灵了。有什么办法能转化一下吗?谢谢了
:

avatar
d*k
5
column type 是 image,我觉得数据应该算是raw bytes了。感觉上是access 在存文件
的时候做了decode, 然后只有他自己能读。看来只有回头让用户自己upload了。

code

【在 m******t 的大作中提到】
: What's the column type in your sql server? Either that's wrong, or your code
: actually saved the data as hex strings, instead of raw bytes.

avatar
F*n
6
Did you remove the OLE header?

【在 d**k 的大作中提到】
: column type 是 image,我觉得数据应该算是raw bytes了。感觉上是access 在存文件
: 的时候做了decode, 然后只有他自己能读。看来只有回头让用户自己upload了。
:
: code

avatar
d*k
7
ehhhh, I have no idea about OLE header, so I guess the answer should be nope
. do I need to remove it from access or database?

【在 F****n 的大作中提到】
: Did you remove the OLE header?
avatar
T*e
8
I guess you need to either do it from SQL Server side or from your servlet
code serving the PDF files. If you need to keep updating your SQL Server
database from Access, the latter may be a better approach.
From SQL Server side, simply read out the PDF field and write back the
portion with OLE header stripped.
From the servlet side, you may check the first four bytes. If the PDF
header presents, write the whole field to output stream. Otherwise, write
everything after the OLE header. This me
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。