Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Why pdf opens in browser but not in pdf reader ?

0 Kudos

After having an attachment in my order(VA03) , i use FM 'BDS_DOCUMENT_GET_TABLE' to get the binary table of this pdf then i send it by email/

When i open it using the browser, it opens correctly, but when i save it in my documents then trying to open it , i get this message

'There was an error opening this document. The file is damaged and could not be repaired'

what could have happened to the pdf after converting it into binary table ?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

Each software has its own implementation to display the PDF, so maybe your PDF is corrupted (the classic issue is extra zero bits at the end of the file) but the browser is able to display it. So, pay attention to the length of the file when you get it, or when you attach it to the email.

17 REPLIES 17

Sandra_Rossi
Active Contributor

Each software has its own implementation to display the PDF, so maybe your PDF is corrupted (the classic issue is extra zero bits at the end of the file) but the browser is able to display it. So, pay attention to the length of the file when you get it, or when you attach it to the email.

This is what I like in SCN 🙂

We will get an answer for every issue we face.If not an answer, atleast a lead which can lead us to the right solution.

Kudos to experts like you.

K.Kiran.

0 Kudos

If you like it, put an up-vote on it! 😉

0 Kudos

If you like it, put an up-vote on it! 😉

0 Kudos

Sandra, thank you. that's explains why some pdf documents works fine. As you said, i have many zeros at the end of this corrupted pdf binary table, but how to get rid of them ?!? 😕

matt
Active Contributor
0 Kudos

Is it BDS_DOCUMENT_GET_TABLE that's adding the extra x00 or is when you send the email? How are you creating the email? How are you attaching the pdf?

0 Kudos

You get the actual size from the parameter COMPONENTS (COMP_SIZE) (EDIT: of function module BDS_DOCUMENT_GET_TABLE, sorry it's COMP_SIZE not DOCUMENT_SIZE)

0 Kudos

yes, the BDS_DOCUMENT_GET_TABLE FM returns a content table with line x1022 with zeros at the last line of this table, then i convert this table into an xstring in a loop at this table

LOOP AT lt_content INTO DATA(ls_content).
CONCATENATE xdata ls_content-line INTO xdata IN BYTE MODE.

ENDLOOP.

and i send this xstring file (in this case with zeros at the end) to the server and it deals with it by it's own

0 Kudos

In which FM is this parameter ?

matt
Active Contributor
0 Kudos

Do you use method add_attachment of class cl_document_bcs? If so, you need to have the parameter i_attachment_size = size got from components(document_size).

0 Kudos

Wael,

If you have CL_BCS then you can find it in.....

CL_DOCUMENT_BCS>>ADD_ATTACHMENT>> Importing parameter I_ATTACHMENT_SIZE.

K.Kiran.

0 Kudos

Thank you for the answer.

No, i'm just sending the xstring file to the server.

i just need to know the size of my output xstring file from the binary table

let's say i have a binary table and it has next lines:

0123456789

0123456789

0123000000

the size of the xstring file should be 24 not 30

how can i get that ?

There is size of binary content in components-comp_size (BDS_DOCUMENT_GET_TABLE).

xdata = xdata(components-comp_size). "clip xstring size
-- Tomas --

matt
Active Contributor
0 Kudos

What do you mean by "Send it to the server"? What server? Originally you wrote "i use FM 'BDS_DOCUMENT_GET_TABLE' to get the binary table of this pdf then i send it by email". Is this not true? It would be enormously helpful if when people asked questions they'd be precise and accurate with the information they give!

Anyway. Since you know the size of the file from Tomas Buryanek's answer, your problem is solved. One line of basic ABAP.

0 Kudos

BDS_DOCUMENT_GET_TABLE

0 Kudos

My RFC FM is called from internet store on hybris platform and it returns an xstring file (which is the pdf).

there is no such BIG need in explaining what i do in the pdf file i get, Mr. Billingham.

matt
Active Contributor
0 Kudos

Notwithstanding Kiran K's comment above, yes there is a big need to explain what you do with the pdf file. The fact that you don't think so is immaterial. My experience with these issues is that there are many points where the corruption can happen. That is why I asked you earlier "How are you creating the email?", which you didn't deign to answer.

Anyway, you've got your solution now, so I'm closing the thread.