space1 separator space2  

Code Samples - Neevia PDFcompress

Example 1: Compress a PDF file (high image quality, low compression) - ASP.NET

In order to compress PDF files from ASP.NET you need to make sure that Neevia PDF compress is installed on your Windows machine. After that copy the PDFcompress .NET assembly from the C:\Program files (x86)\neeviaPDF.com\PDFcompress\dotNet\ folder into your website bin folder and use the code below. It will compress your file while preserving the image quality.

Scroll down for the C# samples

Visual Basic Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  <%@ Page Language="VB" %>
  <HTML>
  <HEAD>
     <SCRIPT runat="server">
        Sub Button1_OnClick(Source As Object, e As EventArgs)
   	  Dim NVcomp As new PDFcompress.Neevia
	  Dim retVal

	  NVcomp.CI = "jpx"
	  NVcomp.CQ = 75

	  NVcomp.GI = "jpx"
	  NVcomp.GQ = 75

	  NVcomp.MI = "jbig2l"
	  NVcomp.MQ = 5

	  ' For better compression uncomment the line below
	  ' NVcomp.CreateObjectStreams = true

   	  retVal = NVcomp.CompressPDF("c:\in.pdf", "c:\out.pdf")
	  If retVal <> 0 Then
  	    Response.Write("Error code=" & CStr(retVal))
	  Else
	    Response.Write("Done")
	  End If
        End Sub
     </SCRIPT>
   </HEAD>
   <BODY><CENTER>
     <FORM id="Form1" enctype="multipart/form-data" method="post" runat="server">
     <INPUT id="Submit1" type="submit" value="Compress file" 
       OnServerClick="Button1_OnClick" name="Submit1" runat="server">
     </FORM>
   </BODY>
   </HTML>

VC# Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
   <%@ Page Language="C#" %>
   <HTML>
   <HEAD>
   <SCRIPT runat="server">
      void Button1_OnClick(object Source, EventArgs e)
      {
	  PDFcompress.Neevia NVcomp = new PDFcompress.Neevia();
	  int retVal;

          NVcomp.CI = "jpx";
          NVcomp.CQ = 75;

          NVcomp.GI = "jpx";
          NVcomp.GQ = 75;

          NVcomp.MI = "jbig2l";
          NVcomp.MQ = 5;

          // For better compression uncomment the line below
          // NVcomp.CreateObjectStreams = true;

	  retVal = NVcomp.CompressPDF(@"c:\in.pdf",@"c:\out.pdf");
	  if (retVal != 0) {
	    Response.Write("Error code = " + retVal.ToString());
	  } else {
	    Response.Write("Done");
	  }
      }
   </SCRIPT>
   </HEAD>
   <BODY><CENTER>
   <FORM id="Form1" enctype="multipart/form-data" method="post" 
   runat="server">
   <INPUT id="Submit1" type="submit" value="Compress file" 
   OnServerClick="Button1_OnClick" name="Submit1" runat="server">
   </FORM>
   </BODY>
   </HTML>