Set PDF Version with iTextSharp – C# and VB.NET

Changing the PDF version with iTextSharp is fairly easy, all you have to do is create a stamper and pass an extra parameter with the PDF version you want. Below is the code snippet to accomplish this in C# and VB.NET.






pCloud Premium

C# Code

PdfReader reader = new PdfReader(fileBytes);
MemoryStream ms = new MemoryStream();
PdfStamper stamper = new PdfStamper(reader, ms, "4");  //The number 4 changes the PDF version to 1.4 (or Acrobat 5)
stamper.Close();
fileBytes = ms.ToArray();
ms.Flush();
reader.Close();

VB.Net Code

Dim reader As PdfReader = New PdfReader(fileBytes)
Dim ms As MemoryStream = New MemoryStream()
Dim stamper As PdfStamper = New PdfStamper(reader, ms, "4")  'The number 4 changes the PDF version to 1.4 (or Acrobat 5)
stamper.Close()
fileBytes = ms.ToArray()
ms.Flush()
reader.Close()

Here is a nice table showing the different versions

Acrobat Product Version PDF
Version
New Features Affecting
Backwards Compatibility
Acrobat 8 PDF 1.7
  • Reader Enabled Forms
  • PDF Packages
  • PDF 1.7 XML Forms
Acrobat 7 PDF 1.6
  • Reader Enabled Review
  • Security Envelopes
  • XML Forms
  • Embedded multimedia including 3D content
  • Bookmark Compression
Acrobat 6 PDF 1.5
  • Linked multimedia
Acrobat 5 PDF 1.4
  • OCR Text Layer

Table came from this Adobe blog.

Esau Silva
Software Engineer at Region One ESC
Microsoft Full Stack Application Developer
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed.
Share