public void DeletePage(
string fileName,
int pageNumber
)
- (BOOL)deletePageInFile:(NSString *)file page:(NSInteger)page error:(NSError **)error
public:
void DeletePage(
String^ fileName,
int pageNumber
)
def DeletePage(self,fileName,pageNumber):
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.
The following file formats support delete operations:
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:\LEADTOOLS23\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document