PDF file size
Version 6.1.0
In this article
Maximum PDF file size
Starting with PDFsharp 6.1, PDF files now can be larger than 2 gibibytes (2^31 = 2,147,483,648 bytes or 2.1 GB) by default.
The new theoretical maximum size is now only limited by the largest entry in the XRef table. Offsets in a PDF file are stored in this table and have exactly 10 decimal figures. So the file can now have a maximum size of about 10 gigabyte (9,999,999,999 byte).
Such large PDF files may be useful in prepress where PDF files can contain hundreds of high-resolution images.
Defining maximum file size
To allow files larger than 2 gibibytes, all file size and offset variables in the source code are switched form Int32 to Int64. The constant USE_LONG_SIZE
defines a
global using SizeType of either 32 or 64 bit.
#if USE_LONG_SIZE
global using SizeType = System.Int64;
#else
global using SizeType = System.Int32;
#endif
You can change the constant USE_LONG_SIZE
in the Directory.Build.targets
file.
<Project>
<PropertyGroup>
…
<DefineConstants>$(DefineConstants);USE_LONG_SIZE;…</DefineConstants>
</PropertyGroup>
</Project>
If you use PDFsharp on a 32 bit operating system like a Raspberry Pi running a 32 bit Linux, it may be useful to recompile PDFsharp with a 32 bit SizeType. Just rename USE_LONG_SIZE
to e.g. USE_LONG_SIZE_XXX
. Maybe this brings minimal performance or memory usage benefits.