78

I tried this:

for ((i=1; i<=10; i++)); do convert 100MB.pdf 10MB.pdf 100MB.pdf; done

to create 100MB file but very quickly run out of RAM.

codewario
  • 19,553
  • 20
  • 90
  • 159
tkane
  • 1,597
  • 3
  • 14
  • 18

11 Answers11

59

The most simple tool: use pdftk (or pdftk.exe, if you are on Windows):

pdftk 10_MB.pdf 100_MB.pdf cat output 110_MB.pdf

This will be a valid PDF. Download pdftk here.

Update: if you want really large (and valid!), non-optimized PDFs, use this command:

pdftk 100MB.pdf 100MB.pdf 100MB.pdf 100MB.pdf 100MB.pdf cat output 500_MB.pdf

or even (if you are on Linux, Unix or Mac OS X):

pdftk $(for i in $(seq 1 100); do echo -n "100MB.pdf "; done) cat output 10_GB.pdf
Dustin Getz
  • 21,282
  • 15
  • 82
  • 131
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • 2
    Please edit with a workaround for ```Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS``` if you know any, thanks. – opyate Jan 05 '15 at 12:33
  • Download and install the PDF toolkit: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ Make sure to add the pdftk install directory to path during install. – Sinisha Mihajlovski Mar 07 '15 at 11:16
51

Windows: fsutil

Usage:

fsutil file createnew [filename].[extension] [# of bytes]

Source: https://www.windows-commandline.com/how-to-create-large-dummy-file/


Linux: fallocate

Usage:

fallocate -l 10G [filename].[extension]

Source: Quickly create a large file on a Linux system?

Emil
  • 1,131
  • 13
  • 23
  • 1
    How is this relevant with the original question about creating a PDF file? – anddam May 27 '22 at 16:58
  • @anddam "[extension]" in the commands in my answer is a placeholder. You can replace that with the extension, like pdf. pdf is an extension. – Emil May 28 '22 at 19:05
  • 4
    No I got that detail, as subtle as it was. But how does that have something to do with the actual initial question, or with my comment? OP is asking for a valid PDF file, what do you think a PDF validator answers if you pass it a 10 MB chunk of null bytes? – anddam May 29 '22 at 23:39
  • @anddam I will take a look when I get home. When I answered this in 2017, I came across this question because I also was trying to figure out how to create large PDFs, and this worked for my own testing purposes. – Emil May 30 '22 at 16:55
  • @anddam will get back to you but won't be tonight. Got busy. Wish I remembered how my answer served my testing purposes in 2017. Wouldn't have answered the question otherwise since I was also looking for a solution to creating large PDFs for testing. – Emil May 31 '22 at 02:55
43

For those using macOS mkfile might be a good alternative to fallocate or dd

mkfile 100m some100mfile.pdf

reference - https://stackoverflow.com/a/33478049/711401

styks
  • 3,193
  • 1
  • 23
  • 36
  • This has the same issue of the "Windows" and "Linux" answer with fsutil and fallocate: this does not produce a PDF file. The point is not dumping null or random data into a file, it is to get a valid PDF file. – anddam May 29 '22 at 23:42
  • 1
    @anddam - A valid PDF was not the point of the question. He asked for a quick, low overhead way to create a large file at specific sizes which just so happened to have a PDF extension. I get this from the example he provided and how the question was asked. I've used this on many occasions to test upload size limits. – styks Jun 05 '22 at 19:25
  • No, he did not. OP asked for a PDF file and was using imagemagick to output valid PDF files. It wasn't clear what his for loop was intended to do, but the desired output format was very firmly expressed, he used all ".pdf". – anddam Jun 06 '22 at 21:56
3

according to http://www.maketecheasier.com/combine-multiple-pdf-files-with-pdftk/ the command should be

pdftk file1.pdf file2.pdf file3.pdf cat output newfile.pdf

note that you should download windows version of pdftk

SᴇM
  • 7,024
  • 3
  • 24
  • 41
swaroop
  • 321
  • 4
  • 5
2

Under Linux there is pdfunite (part of poppler) that can concatenate the same pdf files to get one large pdf file:

pdfunite in.pdf in.pdf in.pdf out.pdf

see manpage

1

I had problems using pdftk with the cat parameter had a better success with output.

The following command worked for me:

pdftk file_1.pdf file_1.pdf file_1.pdf file_1.pdf cat output.pdf

Using cat produced the following error:

Error: Unexpected text in page range end, here: 
    output.pdf
    Exiting.
    Acceptable keywords, for example: "even" or "odd".
    To rotate pages, use: "north" "south" "east"
        "west" "left" "right" or "down"
Errors encountered.  No output created.
Done.  Input errors, so no output created.

http://www.pdflabs.com/docs/pdftk-cli-examples/.

I created a 172mb PDF is no time at all.

L33t8l
  • 49
  • 6
  • 2
    Huh? Your "worked for me" command also uses `cat`. However, it is missing the required `output` operator. (In your quoted command `output.pdf` is a filename.) The command can not be working (in the way you quoted it)! – Kurt Pfeifle Jan 05 '15 at 12:51
1

If you want a really big valid PDF file, then

  1. take all the biggest valid pdf you can
  2. With a tool like PDF24Creator make a fusion of pdfs

It works for me to create a big file (140MB) after some minutes.

harryssuperman
  • 465
  • 3
  • 7
0

Partly it depends on what you are trying to increase the size of... number of pages, number of images, size of a single image. In my experience, the vast bulk (90%+) of any given 'large' PDF file will be the images.

You could try using a pro product like Adobe InDesign to quickly build a large project and export it as a PDF.

Adobe Acrobat Pro has built-in tools to optimize PDF files -- you try using the tools to 'un-optimize' your file. :)

Uriah Carpenter
  • 6,656
  • 32
  • 28
  • As long as it's a valid PDF file I don't mind what causes the bloat. Unfortunately I don't have an access to the mentioned tools :-( – tkane Feb 23 '11 at 16:30
0

One possibility is, if you are familiar with PDF format:

  1. Create some simply PDF with one page (Page should be contained within one object)
  2. Copy object multiply times
  3. Add references to the copied objects to the page catalog
  4. Fix xref table

You get an valid document of any size, entire file will be processed by a reader.

p4553d
  • 818
  • 1
  • 7
  • 17
  • Thanks for the action plan. When I get five minutes I'll code something up and post the solution here. – tkane Feb 27 '11 at 11:18
0

This approach is laborious but would give you a valid pdf with an adjustable file size.

  1. Prepare an image, the bigger the file size the better.
  2. Open a google new google doc.
  3. Upload the image to google doc.
  4. Increase the size of the file by:
    • Creating another page
    • Manually upload the same image to this new page
      • Warning: Do not copy paste the existing image here, the file size won't grow if the image is copy pasted.
  5. Download file as pdf.
  6. Check pdf size, repeat Step4 to adjust to the size you want.

As mentioned, this process is more laborious and would take you more time to reach bigger file sizes. However, it did work for me and I was able to create a 50+MB valid PDF with multiple pages.

-9

Have you tried using cat to combine the files?

cat 10MB.pdf 10MB.pdf > 20MB.pdf

That should result in a 20MB file.

Trevor
  • 55,264
  • 2
  • 18
  • 12
  • It does result in 20MB file but is it a valid PDF? – tkane Feb 23 '11 at 15:20
  • I'm not sure how to validate a pdf. I can open it in a PDF viewer just fine. But cat just merges those two files into one, so the "headers" for each file will remain there. – Trevor Feb 23 '11 at 15:46
  • 2
    I don't think it's a valid PDF. Thanks anyway! – tkane Feb 23 '11 at 16:05
  • It is a valid PDF, some kind ugly and second part will be never read by a reader, but it is valid after PDF reference. – p4553d Feb 24 '11 at 13:46
  • Thanks for the clarification, p4553d. I would say this is a pretty decent solution if it does indeed create a valid file. – Trevor Feb 24 '11 at 14:09
  • 2
    One problem is, reader won't use double as much memory for such one file. To get reader really stuffed with it, one have to copy page objects of pdf on low-level and append them to the catalog. – p4553d Feb 25 '11 at 08:05
  • How did you generate the file "10MB.pdf"? – Emil Mar 22 '19 at 13:58