Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreadable PDF file #73

Closed
PYBurosse opened this issue May 10, 2019 · 1 comment
Closed

Unreadable PDF file #73

PYBurosse opened this issue May 10, 2019 · 1 comment

Comments

@PYBurosse
Copy link

PYBurosse commented May 10, 2019

Hello,

So I'm not sure this is actually a bug, but I can't get the API working using java (groovy/grails to be precise). I use the java HttpClient and MultipartEntity to create the http request, containing the remoteURL of the page I want to make into a PDF. The API do gives me what seems to be a PDF file, but it cannot be opened, neither by a local pdf viewer or the browser, both telling me that the file seems to be damaged or in an unsupported format.
Here is the code I use :

static def execute(def apiURL){
        def httpClient = HttpClients.createDefault()
        def request = new HttpPost(apiURL)

        MultipartEntityBuilder builder = MultipartEntityBuilder.create()
        builder.addTextBody("remoteURL", 'https://google.com')
        builder.addTextBody("marginTop", '0')
        builder.addTextBody("marginBottom", '0')
        builder.addTextBody("marginLeft", '0')
        builder.addTextBody("marginRight", '0')


        HttpEntity multipart = builder.build()
        request.setEntity(multipart)
        def response = httpClient.execute(request)

        BufferedReader rd = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent()))

        StringBuffer result = new StringBuffer()
        String line = ""

        while ((line = rd.readLine()) != null) {

            result.append(line)
        }
        return result
}

I do get a StringBuffer starting with
"%PDF-1.4%����1 0 obj<</Creator (Chromium)/Producer (Skia/PDF m74)/CreationDate (D:20190510164315+00'00')..."
that's why I say it looks like a PDF file.

I am sure the API works fine, since when I do a curl request, from a terminal or from my java project, I do have a proper PDF file. I can't use the curl request in my code, though, because it download the file into my project, instead of giving it as a variable I can easily use and convert as base64.
I am coming here for help since I can't figure out if the problem is from my request or the API, so if anyone has an idea, that would be great

@gulien
Copy link
Collaborator

gulien commented May 13, 2019

Hello @PYBurosse

I have no idea why it does not work with your code. Maybe an encoding issue?

@gulien gulien closed this as completed May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants