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 : Tuesday, May 10, 2022 7:43:07 PM(UTC)

Skyblux  
Skyblux

Groups: Registered
Posts: 2


I was trying and learning to use this sdk and now need to create a pdf from a photo taken from camera, I'm using the example provide on your website DocScanner, from ViewersDemo (Xamarin) on Example folder, the example works fine, but i need to convert the image or images to a pdf without using OCR engine. Just like this example https://www.leadtools.co...the-Document-Converters.

Searching I chnaged the method SetConversionOptions on file DocumentConvertHelper from Project Leadtools.Demos.Document.Xamarin and reference to DocScanner project

I try to use like the example but when running the example shows an alert "This conversion requires a valid OCR engine".

Any idea how to avoid use ocr recognition when convert an image to pdf using this examples ?

Best regards.

 

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.

#2 Posted : Wednesday, May 11, 2022 2:39:13 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Hello Norwill,

My name is Matt and I am a member of the LEADTOOLS Support Team.
I will be happy to assist you with any questions you may have.

You are receiving this error because this demo is set up to export to document file formats only. So, when you select to export to PDF or one of the supported PDF types, the demo is exporting the image to a searchable PDF. Raster image to document format conversion always requires our OCR engine to be enabled. If you want to convert solely to raster PDF you are going to need to pass in RasterImageFormat.RasPdf into the CreateJobData() method. See the sample code below, which does not require our OCR engine to be enabled:

static void ConvertToRaster()
{
RasterImageFormat imageFormat = RasterImageFormat.RasPdf;

string file = @"C:\LEADTOOLS22\Resources\Images\ocr1.tif";
string fileName = Path.GetFileNameWithoutExtension(file);
string ext = RasterCodecs.GetExtension(imageFormat);
string outFile = Path.Combine(@"C:\Temp", $"{fileName}.{ext}");

using (DocumentConverter docConverter = new DocumentConverter())
{

DocumentConverterJobData jobData = DocumentConverterJobs.CreateJobData(file, outFile, imageFormat);
jobData.JobName = "Convert to Image Job";

DocumentConverterJob job = docConverter.Jobs.CreateJob(jobData);
docConverter.Jobs.RunJob(job);

if (job.Errors.Count > 0)
foreach (var error in job.Errors)
Console.WriteLine($"Error during conversion: {error.Error.Message}\n");
else
Console.WriteLine($"Successfully Converted {file} to {outFile}\n");
}
}

Note that this is just a proof of concept and implementation method. If you want to adjust the demo you are going to have to take the LEADDocument given and export it to RasterImageFormat.RasPdf using the overload below.

CreateJobData(LEADDocument document, string outputDocumentFileName, RasterImageFormat rasterImageFormat)

If you have any further questions please feel free to reach back out to us. Note you can reach us via email at support@leadtools.com, or visit our Live Chat.
https://www.leadtools.com/support/chat

Thanks,
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#3 Posted : Wednesday, May 11, 2022 6:34:48 PM(UTC)

Skyblux  
Skyblux

Groups: Registered
Posts: 2


Hi Matt, thanks for your reply, I follow your instruction an change a few code lines.

On the CreateConverterJob method at DocumentConverterHelper

The original method
Code:
      
private DocumentConverterJob CreateConverterJob(DocumentConverter converter, ConversionData conversionData)
      {
         // Set the maximum page
         var firstPageNumber = conversionData.FirstPageIndex + 1;
         if (firstPageNumber == 0)
            firstPageNumber = 1;

         var lastPageNumber = conversionData.LastPageIndex + 1;
         if (lastPageNumber == 0)
            lastPageNumber = -1;

         bool hasAnnotations = DocumentViewerHasAnnotations(conversionData.Document);

         // Create a job
         var jobData = new DocumentConverterJobData
         {
            InputDocumentFileName = null,
            Document = conversionData.Document,
            InputDocumentFirstPageNumber = firstPageNumber,
            InputDocumentLastPageNumber = lastPageNumber,
            DocumentFormat = (conversionData.AnnotationsMode == DocumentConverterAnnotationsMode.Overlay && hasAnnotations) ? DocumentFormat.User : conversionData.OutputFormat.GetDocumentFormat(),
            OutputDocumentFileName = conversionData.OutputDocumentPath,
            AnnotationsMode = hasAnnotations ? conversionData.AnnotationsMode : DocumentConverterAnnotationsMode.None,
            OutputAnnotationsFileName = !conversionData.IsSharingDocument && conversionData.AnnotationsMode == DocumentConverterAnnotationsMode.External ? conversionData.OutputAnnotationsFileName : null,
            RasterImageFormat = (conversionData.AnnotationsMode == DocumentConverterAnnotationsMode.Overlay && hasAnnotations) ? RasterImageFormat.RasPdfJpeg422 : RasterImageFormat.Unknown,
            RasterImageBitsPerPixel = 24,
            JobName = "My Job",
            UserData = conversionData,
         };

         var job = converter.Jobs.CreateJob(jobData);
         return job;
}


A new method with little changes

Code:
        
private DocumentConverterJob CreateConverterJobImage(DocumentConverter converter, ConversionData conversionData)
        {
            // Set the maximum page
            var firstPageNumber = conversionData.FirstPageIndex + 1;
            if (firstPageNumber == 0)
                firstPageNumber = 1;

            var lastPageNumber = conversionData.LastPageIndex + 1;
            if (lastPageNumber == 0)
                lastPageNumber = -1;

            bool hasAnnotations = DocumentViewerHasAnnotations(conversionData.Document);

            // Create a job
            var jobData = new DocumentConverterJobData
            {
                InputDocumentFileName = null,
                Document = conversionData.Document,
                InputDocumentFirstPageNumber = firstPageNumber,
                InputDocumentLastPageNumber = lastPageNumber,
                DocumentFormat = DocumentFormat.Pdf,
                OutputDocumentFileName = conversionData.OutputDocumentPath,
                AnnotationsMode = hasAnnotations ? conversionData.AnnotationsMode : DocumentConverterAnnotationsMode.None,
                OutputAnnotationsFileName = !conversionData.IsSharingDocument && conversionData.AnnotationsMode == DocumentConverterAnnotationsMode.External ? conversionData.OutputAnnotationsFileName : null,
                RasterImageFormat = RasterImageFormat.RasPdf,
                RasterImageBitsPerPixel = 24,
                JobName = "My Job",
                UserData = conversionData,
            };

            var job = converter.Jobs.CreateJob(jobData);
            return job;
        }


An override with your recommendation
Code:
  
        private DocumentConverterJob CreateConverterJobImage(LEADDocument document, string outputDocumentFileName, RasterImageFormat rasterImageFormat)
        {

            DocumentConverter docConverter = new DocumentConverter();
            var jobData = DocumentConverterJobs.CreateJobData(document, outputDocumentFileName, rasterImageFormat);

            var job = docConverter.Jobs.CreateJob(jobData);
            return job;
        }


Your recommendation
Code:
  
        private static void CreateConverterImage(LEADDocument document, string outputDocumentFileName, RasterImageFormat rasterImageFormat)
        {
            using (DocumentConverter docConverter = new DocumentConverter())
            {

                DocumentConverterJobData jobData = DocumentConverterJobs.CreateJobData(document, outputDocumentFileName, rasterImageFormat);
                jobData.JobName = "Convert to Image Job";

                DocumentConverterJob job = docConverter.Jobs.CreateJob(jobData);
                docConverter.Jobs.RunJob(job);

                if (job.Errors.Count > 0)
                    foreach (var error in job.Errors)
                        Console.WriteLine($"Error during conversion: {error.Error.Message}\n");
                else
                    Console.WriteLine($"Successfully Converted");
            }
        }


All of them thrown two errors, always
"Object reference not set to an instance of an object."

Error 0
System.NullReferenceException
Leadtools.Document.Converter.DocumentConverterJobOperation.LoadRasterPage

Error 1
System.NullReferenceException
Leadtools.Document.Converter.DocumentConverterJobOperation.Started


Any idea on this ??

 
#4 Posted : Wednesday, May 18, 2022 4:06:40 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Hello Norwill,

From the code that you sent I am not seeing why you would be receiving this error. I believe the error is occurring due to the LEADDocument that is being passed into the DocumentConverterJobData. In the original method it is using `Document = conversionData.Document` and in your new `CreateConverterImage` method you are passing in `document` which comes from the object passed as the 1st parameter. So I would recommend using the code below in the `CreateConverterJobImage` method.

// Create a job
var jobData = new DocumentConverterJobData
{
InputDocumentFileName = null,
Document = conversionData.Document,
InputDocumentFirstPageNumber = firstPageNumber,
InputDocumentLastPageNumber = lastPageNumber,
OutputDocumentFileName = conversionData.OutputDocumentPath,
AnnotationsMode = hasAnnotations ? conversionData.AnnotationsMode : DocumentConverterAnnotationsMode.None,
OutputAnnotationsFileName = !conversionData.IsSharingDocument && conversionData.AnnotationsMode == DocumentConverterAnnotationsMode.External ? conversionData.OutputAnnotationsFileName : null,
RasterImageFormat = RasterImageFormat.RasPdf,
RasterImageBitsPerPixel = 24,
JobName = "My Job",
UserData = conversionData,
};

No need to have DocumentFormat and RasterImageFormat in the same DocumentConverterJobData, just use RasterImageFormat. But, since you are sticking with using the demo code, make sure the DocumentConverterJobData.Document that you use is set to `conversionData.Document`.

If the issue persist, I may need to see a sample that replicates the issue on your end.

Thanks,
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
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.097 seconds.