DeletePage(string,int) Method (original) (raw)

Summary

Deletes the specified page from a multipage file, if the format supports delete operations.

Syntax

C#

Objective-C

C++/CLI

Python

- (BOOL)deletePageInFile:(NSString *)file page:(NSInteger)page error:(NSError **)error 

Parameters

fileName
A String containing the name of the file from which to delete the page.

pageNumber
1-based index of the page to delete. Use -1 to delete the last page. Use 1 to delete the first page.

Example

using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; using Leadtools.Svg; public void SaveFile2Example() { RasterCodecs codecs = new RasterCodecs(); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_SaveFile2.tif"); // Use GDI+ to create a RasterImage with 4 pages containing text showing the page number RasterImage image = null; const int pageCount = 4; using (System.Drawing.Font f = new System.Drawing.Font("Arial", 36, System.Drawing.FontStyle.Bold)) using (System.Drawing.Bitmap btmp = new System.Drawing.Bitmap(320, 200)) using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat()) { System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, btmp.Width, btmp.Height); sf.Alignment = System.Drawing.StringAlignment.Center; sf.LineAlignment = System.Drawing.StringAlignment.Center; for (int i = 1; i <= pageCount; i++) { // Create a GDI+ bitmap with the text string text = "Page " + i; using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(btmp)) { g.FillRectangle(System.Drawing.Brushes.White, rc); g.DrawString(text, f, System.Drawing.Brushes.Black, rc, sf); } RasterImage tempImage = Leadtools.Drawing.RasterImageConverter.ConvertFromImage(btmp, Leadtools.Drawing.ConvertFromImageOptions.None); if (image == null) image = tempImage; else image.AddPage(tempImage); } } // Save all the pages to the file // The file should have 4 pages now: 1, 2, 3, 4 codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, pageCount, 1, CodecsSavePageMode.Overwrite); image.Dispose(); // Load the 3rd page and insert it as the second // The file should have 5 pages now: 1, 3, 2, 3, 4 image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 3, 3); codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 2, CodecsSavePageMode.Insert); image.Dispose(); // Load the last page, and insert it as the first // The file should have 5 pages now: 4, 1, 3, 2, 3, 4 image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 5, 5); codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert); image.Dispose(); // Replace the 5th page with the 2nd // The file should have 5 pages now: 4, 1, 3, 2, 1, 4 image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 2, 2); codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 5, CodecsSavePageMode.Replace); image.Dispose(); // Delete the 2nd and 6th pages // The file should have 5 pages now: 4, 3, 2, 1 codecs.DeletePage(destFileName, 2); // Notice, -1 because we already deleted a page, so 6th page is now 5th codecs.DeletePage(destFileName, 6 - 1); // Clean up codecs.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; }

Leadtools.Codecs Assembly

CompactFile(Stream,Stream,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(Stream,Stream,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

CompactFile(string,string,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(string,string,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

StartCompress(int,int,int,RasterByteOrder,RasterViewPerspective,int,byte[],int,int,CodecsCompression,CodecsCompressDataCallback) Method