Leadtools.Pdf Requires PDF Plug-in license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Write Method
See Also  Example
Leadtools.Pdf Namespace > PdfCompressor Class : Write Method



outputFileName
The name of the output file to be saved.
outputFileName
The name of the output file to be saved.
Writes the created file from memory to the file system using the path provided.

Syntax

Visual Basic (Declaration) 
Public Sub Write( _
   ByVal outputFileName As String _
) 
Visual Basic (Usage)Copy Code
Dim instance As PdfCompressor
Dim outputFileName As String
 
instance.Write(outputFileName)
C# 
public void Write( 
   string outputFileName
)
C++/CLI 
public:
void Write( 
   String^ outputFileName
) 

Parameters

outputFileName
The name of the output file to be saved.

Example

This example inserts an image to pdf document without using the MRC.

Visual BasicCopy Code
Public Sub pdfCompressor_SegmentImage_PdfDocument(ByVal sender As Object, ByVal e As PdfCompressorSegmentImageEventArgs)
    'This will prevent addition to any segment with type background in all pages except the first page only
    If e.Page <> 0 And e.Segment.Type = SegmentTypeFlags.Background Then
       e.Cancel = True
    Else
       e.Cancel = False
    End If
End Sub
<Test> _
Public Sub PdfCompressorExample_PdfDocument()
  ' Load an image
  RasterCodecs.Startup()
  Dim codecs As RasterCodecs = New RasterCodecs()
  codecs.ThrowExceptionsOnInvalidImages = True

       Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "MRCSegmentation.mrc")

       Dim pdfCompressor As PdfCompressor = New PdfCompressor()
       Dim compressionTypes As PdfCompressorCompressionTypes = New PdfCompressorCompressionTypes()

       'Sets compression types needed for each segment
       compressionTypes.Comp1Bit = PdfCompressor1BitCompression.Zip1Bit
       compressionTypes.Comp2Bit = PdfCompressor2BitCompression.Lzw2Bit
       compressionTypes.CompPicture = PdfCompressorPictureCompression.JpgPic
       compressionTypes.QFactor = 2
       'Flags for used compression types should be set
       compressionTypes.Flags = EnabledCompressionsFlags.EnableOneBit Or EnabledCompressionsFlags.EnableTwoBit Or EnabledCompressionsFlags.EnablePicture

       pdfCompressor.SetCompression(compressionTypes)

       pdfCompressor.Insert(image)
       AddHandler pdfCompressor.SegmentImage, AddressOf pdfCompressor_SegmentImage_PdfDocument
       pdfCompressor.Write(LeadtoolsExamples.Common.ImagesPath.Path + "Image.pdf")
   End Sub
C#Copy Code
public void pdfCompressor_SegmentImage_PdfDocument(object sender, PdfCompressorSegmentImageEventArgs e) 

   //This will prevent addition to any segment with type background in all pages except the first page only 
   if(e.Page != 0 && e.Segment.Type == SegmentTypeFlags.Background) 
      e.Cancel = true; 
   else 
      e.Cancel = false; 

 
 
public void PdfCompressorExample_PdfDocument() 

   // Load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "MRCSegmentation.mrc"); 
 
   PdfCompressor pdfCompressor = new PdfCompressor(); 
   PdfCompressorCompressionTypes compressionTypes = new PdfCompressorCompressionTypes(); 
 
   //Sets compression types needed for each segment 
   compressionTypes.Comp1Bit = PdfCompressor1BitCompression.Zip1Bit; 
   compressionTypes.Comp2Bit = PdfCompressor2BitCompression.Lzw2Bit; 
   compressionTypes.CompPicture = PdfCompressorPictureCompression.JpgPic; 
   compressionTypes.QFactor = 2; 
   //Flags for used compression types should be set 
   compressionTypes.Flags = EnabledCompressionsFlags.EnableOneBit | 
      EnabledCompressionsFlags.EnableTwoBit | 
      EnabledCompressionsFlags.EnablePicture; 
 
   pdfCompressor.SetCompression(compressionTypes); 
 
   pdfCompressor.Insert(image); 
   pdfCompressor.SegmentImage += new EventHandler<PdfCompressorSegmentImageEventArgs>(pdfCompressor_SegmentImage_PdfDocument); 
   pdfCompressor.Write(LeadtoolsExamples.Common.ImagesPath.Path + "Image.pdf"); 
}

Remarks

The PDF Compressor object normally creates the compressed PDF document file in memory. It can add as many pages as required to the file. Once the PDF file in memory is complete, call this method to write the file to disk, before calling the Dispose method. You must call RasterCodecs.StartUp before using this function.

For more information, refer to Creating a Compressed PDF File

.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Leadtools.Pdf requires a PDF Plug-in license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features