Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, November 22, 2017 11:15:07 AM(UTC)
Christopher

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 Application

C#
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();
        }
    }
}


VB
Code:
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#
File Attachment(s):
simplePdfReplaceDelete_20.zip (128kb) downloaded 178 time(s).


VB
File Attachment(s):
simplePdfReplaceDeleteVB_20.zip (124kb) downloaded 150 time(s).
Chris Thompson
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.118 seconds.