Error processing SSI file
LEADTOOLS PDF Segmentation (Leadtools.PdfCompressor assembly)

Show in webframe

Write(String) Method






The name of the output file to be saved.
Writes the created file from memory to the file system using the path provided.
Syntax
public void Write( 
   string outputFileName
)
'Declaration
 
Public Overloads Sub Write( _
   ByVal outputFileName As String _
) 
'Usage
 
Dim instance As PdfCompressorEngine
Dim outputFileName As String
 
instance.Write(outputFileName)
public:
void Write( 
   String^ outputFileName
) 

Parameters

outputFileName
The name of the output file to be saved.
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.

For more information, refer to Creating a Compressed PDF File

.

Use Write(Stream) to write the result to a .NET stream.

Example

This example inserts an image into a PDF document without using the MRC.

Copy Code  
Imports Leadtools
Imports Leadtools.PdfCompressor
Imports Leadtools.Codecs

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
<TestMethod()> _
Public Sub PdfCompressorExample_PdfDocument()
   ' Load an image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True

   Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "MRCSegmentation.mrc"))

   Dim pdfCompressor As New PdfCompressorEngine()
   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(Path.Combine(LEAD_VARS.ImagesDir, "Image.pdf"))
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.PdfCompressor;
using Leadtools.Codecs;

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;
}

[TestMethod]
public void PdfCompressorExample_PdfDocument()
{
   // Load an image
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;

   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"MRCSegmentation.mrc"));

   PdfCompressorEngine pdfCompressor = new PdfCompressorEngine();
   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(Path.Combine(LEAD_VARS.ImagesDir,"Out_Image.pdf"));
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms

See Also

Reference

PdfCompressorEngine Class
PdfCompressorEngine Members
Overload List

Error processing SSI file
Leadtools.PdfCompressor requires a PDF Pro, Pro Suite, Document or Medical license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features