•  
  •  
  •  
 

Convert Searchable PDF to non-searchable PDF

Last post 15 Feb 2007, 11:43 AM by Bill Bither. 0 replies.
Sort Posts: Previous Next
  •  15 Feb 2007, 11:43 AM 11464

    Convert Searchable PDF to non-searchable PDF

    A strange request, but something that I thought I'd share with you.  Here is a simple console application that converts all pages in a hidden text behind image searchable PDF to a image-only non-searchable PDF.  It requires that each page be in memory at once.  If you have more than a few pages, you might want to save a temporary image to a file and using PdfEncoder with PdfImageCollection to save.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using Atalasoft.Imaging;
    using Atalasoft.Imaging.Codec;
    using Atalasoft.Imaging.Codec.Pdf;

    namespace ConvertPdfToPdf
    {
        class Program
        {
            //first arg is input, second arg is output
            static void Main(string[] args)
            {
                string file = args[0];
                ImageCollection col = new ImageCollection();
                using (FileStream fs = File.OpenRead(file))
                {
                    using (Document doc = new Document(fs))
                    {
                        for (int i = 0; i < doc.Pages.Count; i++)
                        {
                            ExtractedImageInfo[] info = doc.Pages[i].ExtractImages();
                            if (info.Length > 1)
                                throw new ApplicationException("contains more than one image");
                            col.Add(info[0].Image);
                        }
                    }
                }
                col.Save(args[1], new PdfEncoder(), null);
            }
        }
    }

    Filed under: ,
View as RSS news feed in XML