/// <summary>
        /// Gets an image resource by id
        /// </summary>
        /// <param name="id">Id to get</param>
        /// <param name="imageType">Image type to get</param>
        /// <param name="options">Options to use</param>
        /// <returns>Handle to image resource if successful, otherwise <c>IntPtr.Zero</c></returns>
        public IntPtr GetResource(int id, ImageType imageType, ImageLoadOptions options)
        {
            IntPtr handle = IntPtr.Zero;

            if (!hLib.Equals(IntPtr.Zero))
            {
                handle = LoadImageLong(hLib, id, (int)imageType, 0, 0, (int)
                                       options);
            }
            return(handle);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");


            var imageLoadOptions = new ImageLoadOptions();

            imageLoadOptions.SetOcrConnector(new OcrConnector());

            using (Converter converter = new Converter(Constants.SAMPLE_JPEG, () => imageLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nDocument converted successfully. \nCheck output in {0}", outputFolder);
        }
Example #3
0
 public FileImageSource(string path, ImageLoadOptions options) : base(options)
 {
     Path = Guard.NotNullOrEmpty(path, nameof(path));
 }
Example #4
0
        /// <summary>
        /// Recognize an image using Tesseract (free OCR library) and save the result as DOCX document.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/ocr-image-using-tesseract-and-save-as-docx-net-csharp-vb.php
        /// </remarks>
        static void RecognizeImage()
        {
            DocumentCore.Serial = "12345";
            // Here we'll recognize an image (perform OCR) containing a text on English, Russian and Vietnamese.
            // Next save the OCR result as a new DOCX document.

            // First steps:

            // 1. Download data files for English, Russian and Vietnamese languages.
            // Please download the files: eng.traineddata, rus.traineddata and vie.traineddata.
            // From here (good and fast): https://github.com/tesseract-ocr/tessdata_fast
            // or (best and slow): https://github.com/tesseract-ocr/tessdata_best

            // 2. Copy the files: eng.traineddata, rus.traineddata and vie.traineddata to
            // the folder "tessdata" in the Project root.

            // 3. Be sure that the folder "tessdata" also contains "pdf.ttf" file.

            // Let's start:
            string inpFile = @"..\..\image.png";
            string outFile = "Result.docx";

            ImageLoadOptions lo = new ImageLoadOptions();

            lo.OCROptions.OCRMode = OCRMode.Enabled;

            // You can specify all Tesseract parameters inside the method PerformOCR.
            lo.OCROptions.Method = PerformOCRTesseract;
            DocumentCore dc = DocumentCore.Load(inpFile, lo);

            // Make all text visible after Tesseract OCR (change font color to Black).
            // The matter is that Tesseract returns OCR result PDF document with invisible text.
            // But with help of Document .Net, we can change the text color,
            // char scaling and spacing to desired.
            foreach (Run r in dc.GetChildElements(true, ElementType.Run))
            {
                r.CharacterFormat.FontColor = SautinSoft.Document.Color.Black;
                r.CharacterFormat.Scaling   = 100;
                r.CharacterFormat.Spacing   = 0;
                r.CharacterFormat.Size      = 12;
            }

            // Change the page size and add page margins.
            Section section = dc.Sections[0];

            section.PageSetup.PaperType   = PaperType.Letter;
            section.PageSetup.Orientation = Orientation.Landscape;
            double m = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point);

            section.PageSetup.PageMargins = new PageMargins()
            {
                Top = m, Left = m, Right = m, Bottom = m
            };
            dc.Save(outFile);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
            {
                UseShellExecute = true
            });
        }
Example #5
0
 public StreamImageSource(Stream stream, ImageLoadOptions options) : base(options)
 {
     Stream = Guard.NotNull(stream, nameof(stream));
 }
 public BufferImageSource(byte[] buffer, ImageLoadOptions options) : base(options)
 {
     Guard.NotNullOrEmpty(buffer, nameof(buffer));
     Buffer = buffer;
 }
		/// <summary>
		/// Gets an image resource by id
		/// </summary>
		/// <param name="id">Id to get</param>
		/// <param name="imageType">Image type to get</param>
		/// <param name="options">Options to use</param>
		/// <returns>Handle to image resource if successful, otherwise <c>IntPtr.Zero</c></returns>
		public IntPtr GetResource(int id, ImageType imageType, ImageLoadOptions options) {
			IntPtr handle = IntPtr.Zero;
			if (!hLib.Equals(IntPtr.Zero)) {
				handle = LoadImageLong(hLib, id, (int)imageType, 0, 0, (int)
				 options);
			}
			return handle;
		}
Example #8
0
 protected ImageSource(ImageLoadOptions options)
 {
     Options = options;
 }
Example #9
0
 public VipsImageSource(Image image, ImageLoadOptions options) : base(options)
 {
     this.image = Guard.NotNull(image, nameof(image));
     imageType  = ImageType.FromImage(image);
 }