Get warning Invalid stream: "FormatError: Bad FCHECK in flate stream: 120, 253"
See original GitHub issueHI, I have a Jersey Backend REST service to get the PDF from server to Client. I set the response to React state so that this will not retrieve the PDF from backend again in state changed. However, I got the error Warning: Invalid stream: “FormatError: Bad FCHECK in flate stream: 120, 253” in loading that PDF to Document. All content of PDF are lost.
May I know how to solve this?
Below is my code:
Server
@Override
@GET
@Path("/pdf")
@Produces(MediaType.APPLICATION_PDF_VALUE)
public Response testPdf() throws Exception {
File file = new File("C:\\Desktop\\test.pdf");
FileInputStream fileInputStream = new FileInputStream(file);
ResponseBuilder response = Response.ok((Object) fileInputStream);
response.type("application/pdf");
response.header("Content-Disposition", "filename=test.pdf");
return response.build();
}
Client
import React, { Component } from 'react';
import { Document, Page } from 'react-pdf';
import axios from 'axios';
class MyApp extends Component {
state = {
numPages: null,
pageNumber: 1,
pdfContent: null
}
componentDidMount(){
var that = this;
axio.get("url\Pdf).then((response) => {
that.setState({pdfContent: response });
}).catch((error) => {
console.warn(error);
});
}
onDocumentLoadSuccess = ({ numPages }) => {
this.setState({ numPages });
}
printHandler(){
window.print();
}
render() {
const { pageNumber, numPages } = this.state;
return (
<div>
<Document
file={this.state.pdfContent}
onLoadSuccess={this.onDocumentLoadSuccess}
>
<Page pageNumber={pageNumber} />
</Document>
<p>Page {pageNumber} of {numPages}</p>
<button onClick={() => this.setState(prevState => ({
pageNumber: prevState.pageNumber + 1 }))}>Next page</button>
<button onClick={() => this.setState(prevState => ({
pageNumber: prevState.pageNumber - 1 }))}>Prev Page</button>
<button onClick={this.printHandler}/>
</div>
);
} }
```
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:18 (6 by maintainers)
Top Results From Across the Web
"FormatError: Bad FCHECK in flate stream: 120, 239" on PDF ...
I know that the pdf itself is not corrupt, because when I make a get request to the API to retrieve the stored...
Read more >How can I load PDF from from a response? : r/learnjavascript
This however doesn't work. I get an error that says: Warning: Invalid stream: "FormatError: Bad FCHECK in flate stream: 120, 239".
Read more >Display PDF loaded from server - - Bountysource
[x] I have read documentation in README; [x] I have checked sample and test suites to see real life basic implementation; [x] I...
Read more >FormatError: Bad FCHECK in flate stream - pdf.js出现bug
pdf.js出现bug:Warning: Invalid stream: “FormatError: Bad FCHECK in ... 情况自行修改 } // get请求映射params参数 if (config.method === 'get' ...
Read more >[jira] [Comment Edited] (PDFBOX-4781) PDF files with invalid ...
... "FormatError: Bad FCHECK in flate stream: 120, 194" Warning: ... Object 9 is said to have a length of 37, but has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As mentioned above, make sure that the response type is set to ‘blob’. Here is an example using Axios that calls an API, sets the response type, and creates a blob url from the response.
Thanks, I’ve in the end set the
responseType:'arraybuffer'
inaxios
config and then passed theresponse.data
to theDocument
’sfile
prop as object{data:...}
which then is used in
Document