I need to Load that file using GdPicturePDF or GdPictureImaging and run through the Pages and check if it has a blank image or No Text .
If the page is blank then I should remove it .
Then If the page contain the Color image then I should make it Gray Scale or Black and White which will reduce the Size of the Newly generated file
I am getting trouble in understanding how can I loop through the Pages and move to next page.
Please let me know How should I proceed , i need some Code Sample
I am Using Code like below but it is working for Text on the PDF but not for the Images on the File
Code: Select all
private void ProcessPDF ()
{
GdPicture.LicenseManager OBJ_License = new GdPicture.LicenseManager();
OBJ_License.RegisterKEY("XXX");
FileInfo[] allFiles = new System.IO.DirectoryInfo(@"D:\PDF\OLD\").GetFiles("*.pdf", SearchOption.AllDirectories); // Get all the Files from Folder
foreach (var f in allFiles) // loop through each file
{
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
oGdPicturePDF.LoadFromFile(f.FullName, false); // Load Each File in PDF Object
oGdPicturePDF.EnableCompression(true);
int pages = oGdPicturePDF.GetPageCount(); // Count the Pages in File
for (int i = 1; i <= pages; i++)
{
bool selectPG = oGdPicturePDF.SelectPage(i);
//int PageNO = oGdPicturePDF.GetCurrentPage();
string txt = oGdPicturePDF.GetPageText(); // Get he Text on that Page
//MessageBox.Show(PageNO.ToString() + "---" + txt.ToString());
if (txt.Equals("")) // Check for the Text in the Page
{
oGdPicturePDF.DeletePage(PageNO);
}
}
oGdPicturePDF.SaveToFile(@"D:\PDF\NEW\" + f.Name, false); // Save the file to New Location
oGdPicturePDF.CloseDocument(); // Close the Object
}
}