#1
Posted
:
Wednesday, November 22, 2017 11:15:07 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 89
Was thanked: 4 time(s) in 4 post(s)
Often when we convert a file type we need to delete the previous version of the file for the sake of saving space.
The example below shows how to implement the LEADTOOLS SDK in order to achieve this.
It is important to note that the DLLs needed for splitting the documents will depend on the documents that the application will be working with.
In our application we are working with PDFs and with Tifs so those DLLs are included.
Follow this link to see what you will need:
Files To Be Included With Your ApplicationC#Code:using Leadtools;
using Leadtools.Codecs;
namespace simplePdfReplaceDelete_20
{
class Program
{
static void Main(string[] args)
{
// Add License and Key here
RasterSupport.SetLicense("", "");
string pdfFileName = @"C:\Users\cthompson\Desktop\Leadtools.pdf"; //file to be deleted
string tifFileName = @"C:\Users\cthompson\Desktop\LeadtoolsConverted.tif"; //file path for output
CreateTifFile(pdfFileName, tifFileName);
File.Delete(pdfFileName); // deletes original file that is converted
Console.WriteLine(pdfFileName + ">> has been deleted.\n" + tifFileName + ">> has been created.");
Console.ReadLine();
}
public static void CreateTifFile(string pdfFileName, string tifFileName)
{
RasterCodecs codecs = new RasterCodecs();
codecs.Options.Load.AllPages = true; // Allows for multipage documents
RasterImage image = codecs.Load(pdfFileName);
codecs.Load(pdfFileName);
codecs.Save(image, tifFileName, RasterImageFormat.Tif, 0);
codecs.Dispose();
}
}
}
VBCode:Imports Leadtools
Imports Leadtools.Codecs
Module Module1
Sub Main()
'Add License and Key here
RasterSupport.SetLicense("", "")
Dim pdfFileName As String = "C:\Users\cthompson\Desktop\Leadtools.pdf" 'file to be deleted
Dim tifFileName As String = "C:\Users\cthompson\Desktop\LeadtoolsConverted.tif" 'file path for output
CreateTifFile(pdfFileName, tifFileName)
File.Delete(pdfFileName) 'deletes original file that Is converted
Console.WriteLine(pdfFileName + ">> has been deleted." + vbLf + tifFileName + ">> has been created.")
Console.ReadLine()
End Sub
Public Sub CreateTifFile(ByVal pdfFileName, ByVal tifFileName)
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Options.Load.AllPages = True 'Allows for multipage documents
Dim image As RasterImage = codecs.Load(pdfFileName)
codecs.Load(pdfFileName)
codecs.Save(image, tifFileName, RasterImageFormat.Tif, 0)
codecs.Dispose()
End Sub
End Module
C#VBChris Thompson
Developer Support Engineer
LEAD Technologies, Inc.
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.