0

I'm trying to copy the actual file content, including the file header and binary contents of a file to the clipboard. The file is a .pdf in this case.

I've come across multiple solutions, but they don't seem to work for me.

xclip -sel c < file.pdf
xclip -sel clip < file.pdf
xclip -i -selection c file.pdf
cat ./file.pdf | xclip -i
xclip-copyfile file.pdf

None of the above would copy the file to the clipboard for me, or at least it is not pasteable anywhere (terminal or gui text editor)

I'm on Kali Rolling with the most recent updates.

edit: Apparently the question is not clear enough, so I'll try to elaborate it with the pdf example.

I made a simple PDF file, with Libre Office Writer, which looks like the following if viewed in a normal PDF reader:

screenshot of PDF viewer

Now, the file's data is way more than that - obviously. If the PDF is opened with a hex editor, this can be shown. See below:

00000000   25 50 44 46  2D 31 2E 34  0A 25 C3 A4  %PDF-1.4.%..
0000000C   C3 BC C3 B6  C3 9F 0A 32  20 30 20 6F  .......2 0 o
00000018   62 6A 0A 3C  3C 2F 4C 65  6E 67 74 68  bj.<</Length
00000024   20 33 20 30  20 52 2F 46  69 6C 74 65   3 0 R/Filte
00000030   72 2F 46 6C  61 74 65 44  65 63 6F 64  r/FlateDecod
0000003C   65 3E 3E 0A  73 74 72 65  61 6D 0A 78  e>>.stream.x
00000048   9C 4D 8D B1  0A 02 31 10  44 FB FD 8A  .M....1.D...
00000054   A9 05 73 BB  71 73 89 10  52 88 0A DA  ..s.qs..R...
00000060   1D 04 2C C4  4A 4F AB 53  EE 1A 7F DF  ..,.JO.S....
0000006C   98 2B 94 85  61 76 67 99  C7 46 F0 A6  .+..avg..F..
00000078   11 0C 2E CE  AD 9D B1 08  2A 26 60 EA  ........*&`.
00000084   E9 B4 C0 73  CE CA 4C 0F  DA 64 72 6D  ...s..L..drm
00000090   89 BC 57 E4  1B 9A BD 40  2C F2 FD 1C  ..W....@,...
0000009C   59 92 70 64  9B 96 21 F2  AA 6A B9 58  Y.pd..!..j.X
000000A8   1F 59 D3 25  1F 69 97 A9  A3 0E 23 84  .Y.%.i....#.
000000B4   D9 28 BC 84  C2 D1 D6 B8  59 7E AC B2  .(......Y~..
000000C0   B6 15 57 CD  FF F7 75 A0  E6 30 28 B6  ..W...u..0(.
000000CC   2F 7C AB 3E  2A 51 26 FE  0A 65 6E 64  /|.>*Q&..end
000000D8   73 74 72 65  61 6D 0A 65  6E 64 6F 62  stream.endob
000000E4   6A 0A 0A 33  20 30 20 6F  62 6A 0A 31  j..3 0 obj.1
000000F0   34 31 0A 65  6E 64 6F 62  6A 0A 0A 34  41.endobj..4
000000FC   20 30 20 6F  62 6A 0A 3C  3C 2F 54 79   0 obj.<</Ty
00000108   70 65 2F 58  4F 62 6A 65  63 74 2F 53  pe/XObject/S
00000114   75 62 74 79  70 65 2F 49  6D 61 67 65  ubtype/Image
00000120   2F 57 69 64  74 68 20 31  35 30 20 2F  /Width 150 /
0000012C   48 65 69 67  68 74 20 31  35 30 20 2F  Height 150 /
---  test.pdf       --0x0/0x316E------------------------------

This includes metadata and the actual data (test and the picture).

What I want to copy, is the complete data of the file, including the metadata, file header and so on.

It does not matter if there's non printable characters.

1

X does't really have a clipboard, only selections that allow communicating with each other, and this communication is used for cut and paste. So you either need a running clipboard manager like xclipboard or similar, which will take over the primary selection if instructed, or you need to run xclip with the -l option to make it wait until the contents have been pasted.

That said, I can't think of any application that would accept a PDF file as clipboard content (which application do you have in mind?), and I'm not sure what you mean by "file header", either. Selections only have content.

Possibly you want drag and drop interaction, instead of cut and paste?

  • I'll go and check out the xclipboard. By file header I meant, not just the content of a PDF, but the complete data a file has, which you see when inspecting a file with a hex editor. No, I want to copy and paste the file data for further processing. – SaAtomic Jun 20 '17 at 11:24
  • The complete data in the file is the whole file file.pdf, there's no special "header". Only part of that data encodes text, of course, but that has nothing to do with "file headers". So you just want the complete file. And you still haven't said what application you want to paste it into - besides not understanding the format, a complete PDF file is a bit large for that form of interaction. – dirkt Jun 20 '17 at 11:26
  • I'm sorry I worded it like this, I was worried people would not understand that a PDF is not just what is displayed in the viewer. As of where I want to paste it, that doesn't really matter, nor does the size to be honest. For the question, let's assume I'd paste it in any normal text editor, such as leafpad – SaAtomic Jun 20 '17 at 11:29
  • You can't paste a PDF in a normal text editor. Neither can you open it, and expect to edit it - the contents are compressed. Try opening the file directly, and have a look. – dirkt Jun 20 '17 at 13:51
  • I understand how the file looks, I can copy it into a text editor from the hex editor just fine. It's just convenience, I'm trying to achieve. – SaAtomic Jun 21 '17 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.