ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Problem importing tif, exporting PDF
 New Topic  Reply to Topic
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

lorife

Italy
44 Posts

Posted - Jan 04 2022 :  12:13:11  Show Profile  Reply
Hello,
I'm trying your ImageEN DEMO. I need to open a PDF, and extract first 2 pages to another pdf.
This is what i'm doing:

IEGlobalSettings().RegisterPlugIns([ iepiPDFium ]);
iev_IN.PdfViewer.Enabled := True;

iev_IN.ClearAll;

iev_IN.IO.Params.ImageIndex := 0;
iev_IN.IO.LoadFromFile('c:\temp\IN.pdf');
iemv_OUT.AppendImage;
iemv_OUT.SetImage(iemv_OUT.SelectedImage, iev_IN.IEBitmap);

iev_IN.IO.Params.ImageIndex := 1;
iev_IN.IO.LoadFromFile('c:\temp\IN.pdf');
iemv_OUT.AppendImage;
iemv_OUT.SetImage(iemv_OUT.SelectedImage, iev_IN.IEBitmap);

iemv_OUT.MIO.SaveToFile('c:\temp\OUT.pdf');


it works, but the resulting file is all blurried, not sharp.
If i load a tif and export to PDF the resulting file is perfect.

do you have any idea on why?
thank you

xequte

38608 Posts

Posted - Jan 04 2022 :  14:59:31  Show Profile  Reply
Hi

A better method would be to use ExportPages:

https://www.imageen.com/help/TIEPdfViewerInteraction.ExportPages.html

Otherwise this output method should work better:

// Add current page to a TImageEnMView
idx := ImageEnMView1.AppendImage( 0,0,ie24RGB );
bmp := ImageEnMView21.GetTIEBitmap( idx );
ImageEnView1.PdfViewer.DrawTo( bmp );
ImageEnMView1.ReleaseBitmap( idx, True );



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 05 2022 :  02:43:24  Show Profile  Reply
Hello,
thank you for writing back.


I understand ExportPages might work better but I simplified a little the logic.
In reality I need to analyze each page and then decide, also I do not know the format IN and OUT so I was looking for something that could work for each format. ExportPages is very PDF specific.

My original code was format independent that's why I liked it.
Do you think you can fix the problem in a future version?

Thank you

Go to Top of Page

xequte

38608 Posts

Posted - Jan 05 2022 :  04:44:55  Show Profile  Reply
Please use:

bmp := TIEBitmap.create();
ImageEnView1.PdfViewer.DrawTo( bmp );
ImageEnMView1.AppendImage( bmp );
bmp.Free;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 05 2022 :  05:40:03  Show Profile  Reply
Like this it works but it's still not focused.

bmp := TIEBitmap.create();
iev_IN.PdfViewer.DrawTo(bmp);
iemv_OUT.AppendImage(bmp);

iev_IN.PdfViewer.SaveToFile('c:\temp\a.pdf');
bmp.Write('c:\temp\b.pdf');
iemv_OUT.MIO.SaveToFile('c:\temp\c.pdf');

bmp.Free;


what is strange is that a.pdf is focused (and 18MB) while b.pdf and c.pdf are not focused (and 1.4 MB)
Go to Top of Page

xequte

38608 Posts

Posted - Jan 08 2022 :  16:37:15  Show Profile  Reply
I have emailed you the latest source code which makes it easier to draw higher resolution PDF pages.

You can use the new parameters for DrawTo():

procedure DrawTo(Bitmap: TIEBitmap; Width: Integer = -1; Height: Integer = -1; MaintainAR: Boolean = True); overload;
procedure DrawTo(Bitmap: TBitmap; Width: Integer = -1; Height: Integer = -1; MaintainAR: Boolean = True); overload;
procedure DrawTo(Canvas: TCanvas; Width: Integer = -1; Height: Integer = -1; MaintainAR: Boolean = True); overload;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 20 2022 :  05:17:52  Show Profile  Reply
Hello,
thanks. I tried the beta with this code:

iev_IN.IO.Params.ImageIndex := 0;
iev_IN.IO.LoadFromFilePDF('c:\temp\OBR\S30C-921122015230.pdf');
bmp := TIEBitmap.create();
iev_IN.PdfViewer.DrawTo( bmp, 1024, 768, true );
iemv_OUT.AppendImage( bmp );
bmp.Free;
iemv_OUT.MIO.SaveToFile('c:\temp\OUT.pdf');


but the output file is empty.
I also tried this:

iev_IN.PdfViewer.DrawTo( bmp, -1, -1, true );


or this:

iev_IN.PdfViewer.DrawTo( bmp );


but no luck.
Also, what should I use as the new params? destination size will be A4 so I need bigger images to shrink to A4 (but keeping proportions).

thanks
Go to Top of Page

xequte

38608 Posts

Posted - Jan 20 2022 :  15:23:14  Show Profile  Reply
1. Please enable the PDF viewer:

ImageEnView1.PdfViewer.Enabled := True;


2. That is not a recommended way to create a PDF file. It will convert a PDF document (with images and text, etc) to a PDF file containing images.

Please see the notes at:

https://www.imageen.com/help/File_Formats.html


3. Mostly ImageEn only deals with images, so "A4" is not relevant. You can create an image of pixel size of A4 (i.e. considering size and DPI), but how it would display depends on the viewer.

For PDF files, see: https://www.imageen.com/help/TIOParams.PDF_PaperSize.html



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 20 2022 :  15:44:57  Show Profile  Reply
My problem is that i receive pdf coming from a scanner so each page is an image. I need to analyze each page for barcodes and then apply some logics. If correct i need to add the page to another pdf..but as the page (image) in the original pdf is quite big i need to shrink it so that I can have a smaller file.
Also the new pdf must be A4 so i don't want to shrink the image too much.

That's why I need to treat it as image and not as pdf.

Does it make any sense?

Thank you

Go to Top of Page

xequte

38608 Posts

Posted - Jan 20 2022 :  19:51:52  Show Profile  Reply
OK, then in principal that should work. Just set the PDF_PaperSize to iepA4 and use DuplicateCompressionInfo if the TImageEnMView has multiple pages:

ImageEnMView1.MIO.Params[0].PDF_PaperSize := iepA4;
ImageEnMView1.MIO.Params[0].PDF_ImageOptions := [iepioShrinkOnly, iepioCentered];
ImageEnMView1.MIO.DuplicateCompressionInfo(TRUE);
ImageEnMView1.MIO.SaveToFilePDF('d:\test.pdf');


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 21 2022 :  05:03:40  Show Profile  Reply
Hello,
thanks.

Please don't hate me...

so I tried:
iev_IN.PdfViewer.DrawTo( bmp, -1, -1, true );

and the output file was in bad quality.
then I tried:
iev_IN.PdfViewer.DrawTo( bmp, 2000, 2000, true );

and the quality is better but still a little blurried.
So I'm asking:
1. If I leave -1 shouldn't it use the maximum quality
2. what numbers should i write for height and width to achieve a good quality?
Please note i'm still not compressing anything, the only code is this:

IEGlobalSettings().RegisterPlugIns([ iepiPDFium ]);
iev_IN.PdfViewer.Enabled := True;
iev_IN.IO.Params.ImageIndex := 0;
iev_IN.IO.LoadFromFilePDF('c:\temp\OBR\S30C-921122015230.pdf');
bmp := TIEBitmap.create();
iev_IN.PdfViewer.DrawTo( bmp, 2000, 2000, true );
iemv_OUT.AppendImage( bmp );
bmp.Free;
iemv_OUT.MIO.SaveToFile('c:\temp\OUT.pdf');


thanks
Go to Top of Page

xequte

38608 Posts

Posted - Jan 23 2022 :  23:11:26  Show Profile  Reply
-1 will use the reported size of the PDF, which will look low quality if you enlarge the generated image. The best values to pass depend on your desired usage, e.g. if they are just for displaying on screen, then 2 x screen size might be good.

Can you please attach/link to your source PDF, the bmp you get from DrawTo( bmp, 2000, 2000, true ), and the output PDF, so I can see what you are seeing?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 24 2022 :  05:55:08  Show Profile  Reply
Hello,
I have sent you a demo project.
Go to Top of Page

xequte

38608 Posts

Posted - Jan 24 2022 :  18:05:28  Show Profile  Reply
Thanks, I've reviewed the project.

Quality is good and as expected when saving to image format.

Unfortunately the blurriness when viewing PDF files created in this manner is due to the way PDF saving is handled in ImageEn and the scaling of images by PDF viewers.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 28 2022 :  06:14:47  Show Profile  Reply
Hello,
Ok thanks.

Now I'm trying to read barcodes in the file. So, I load the file into imageen then:
selRect := IEVisionRect(0, 0, 0, 0);
m_symbols := IEVisionLib.createBarCodeScanner().scan(iev_IN.IEBitmap.GetIEVisionImage(), selRect);

However it does not find anything.

Could you try with the demo I sent you? In the first page there's a barcode, why doesn't int work?

thanks
Go to Top of Page

xequte

38608 Posts

Posted - Jan 28 2022 :  23:22:47  Show Profile  Reply
Hi

The issue here will be that the sync'ed bitmap of PDFViewer will be too low quality for good bar code detection, so you should draw to a bitmap at a larger size.

This works for me:

procedure TMainForm.Button2Click(Sender: TObject);
var
  s: TIEVisionBarCodeSymbol;
  i: integer;
  selRect: TIEVisionRect;
  n: TTreeNode;
  data: string;
  bmp: TIEBitmap;
begin
  bmp := TIEBitmap.Create;
  try
    TreeViewResults.Items.Clear();

    ImageEnView1.PdfViewer.DrawTo( bmp, 2000, 2000, True );
    selRect := IEVisionRect(0, 0, 0, 0);
    m_symbols := IEVisionLib.createBarCodeScanner().scan( bmp.GetIEVisionImage(), selRect );

    for i := 0 to m_symbols.size() - 1 do
    begin
      n := TreeViewResults.Items.AddChild(nil, IntToStr(i));
      s := TIEVisionBarCodeSymbol( m_symbols.getObj(i) );

      TreeViewResults.Items.AddChild(n, s.getSymbolType().c_str());

      data := s.getData().c_str();
      // Get rid of any hard returns (for display)
      data := StringReplace( data, #13#10, '/', [rfReplaceAll] );
      TreeViewResults.Items.AddChild( n, data );

      if CheckBoxShowConfidence.Checked then
        TreeViewResults.Items.AddChild(n, Format('Confidence: %d', [s.getQuality()]));
    end;

  finally
    bmp.Free;
  end;
end;




Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38608 Posts

Posted - Jan 28 2022 :  23:36:54  Show Profile  Reply
Also, in the next release you can double the resolution (apparent size on screen and size of created bitmap) using IEGlobalSettings().PdfViewerDefaults.DPI.

Loading your PDF into the bar code demo successfully detects it using the following:

  IEGlobalSettings().PdfViewerDefaults.DPI := 144; // Double the PDF resolution
  ImageEnView1.PdfViewer.Enabled  := True;
  ImageEnView1.PdfViewer.AutoSync := True;
  ImageEnView1.IO.LoadFromFilePDF( 'D:\in.pdf' );


You can email me if you want to test this update.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Jan 29 2022 :  17:20:35  Show Profile  Reply
Hello,
I have asked for the version in the mail.

Menwhile, I have a question.
I was doing this when it was not working:


iev_IN.PdfViewer.Enabled := True;
iev_IN.IO.LoadFromFilePDF(FullPathIN)
var selRect := IEVisionRect(0, 0, 0, 0);
var m_symbols := IEVisionLib.createBarCodeScanner().scan(iev_IN.IEBitmap.GetIEVisionImage(), selRect);


However you did this:


iev_IN.PdfViewer.Enabled := True;
iev_IN.IO.LoadFromFilePDF(FullPathIN)
bmp := TIEBitmap.Create;
ImageEnView1.PdfViewer.DrawTo( bmp, 2000, 2000, True );
var selRect := IEVisionRect(0, 0, 0, 0);
var m_symbols := IEVisionLib.createBarCodeScanner().scan(bmp.GetIEVisionImage(), selRect);
bmp.free


But I'm asking, as I already load each page into ImageEn, do I really have to draw to another bmp each page to read the barcode?
thanks
Go to Top of Page

xequte

38608 Posts

Posted - Jan 29 2022 :  17:35:31  Show Profile  Reply
I use the BMP to get a better quality rasterization of the PDF page (at size 2000x2000) as the default size is too low quality.

However you can achieve the same effect in the current beta by increasing the DPI:

IEGlobalSettings().PdfViewerDefaults.DPI := 144;

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

lorife

Italy
44 Posts

Posted - Feb 01 2022 :  05:48:38  Show Profile  Reply
Hello,
I confirm that using:

IEGlobalSettings().PdfViewerDefaults.DPI := 144;


produces very good results with image quality and barcode recognition.
However I have some things to ask:

1. FIRST NOTE:

Launching this code for many pages produces an access violation at the 3rd time.

IEGlobalSettings().PdfViewerDefaults.DPI := 144;
iev_IN.ClearAll; <-- here is the AV
iev_IN.IO.Params.ImageIndex := idx;
iev_IN.IO.LoadFromFilePDF(FullPathIN);
idx := iemv_OUT.AppendImage(0, 0, ie24RGB);
bmp := iemv_OUT.GetTIEBitmap(idx);
iev_IN.PdfViewer.DrawTo(bmp, 2000, 2000, true);
iemv_OUT.ReleaseBitmap(idx, True);


however this works:


iev_IN.ClearAll; 
iev_IN.IO.Params.ImageIndex := idx;
iev_IN.IO.LoadFromFilePDF(FullPathIN);
idx := iemv_OUT.AppendImage(0, 0, ie24RGB);
bmp := iemv_OUT.GetTIEBitmap(idx);
iev_IN.PdfViewer.DrawTo(bmp, 2000, 2000, true);
iemv_OUT.ReleaseBitmap(idx, True);


and this too:

IEGlobalSettings().PdfViewerDefaults.DPI := 144;
iev_IN.ClearAll;
iev_IN.IO.Params.ImageIndex := idx;
iev_IN.IO.LoadFromFilePDF(FullPathIN);
bmp := iev_IN.IEBitmap;
idx := iemv_OUT.AppendImage;
iemv_OUT.SetImage(idx, bmp);


1. SECOND NOTE:

now that i can use this:

IEGlobalSettings().PdfViewerDefaults.DPI := 144;


this code works great and quality is ok:


bmp := iev_IN.IEBitmap;
idx := iemv_OUT.AppendImage;
iemv_OUT.SetImage(idx, bmp);


so I guess i'll stick with it, there's no need to use the other method where I can specify the size. Is it correct?

3. THIRD NOTE:

Please help me understand this.
If I try to read a pdf and write a tif with this:

iemv_OUT.MIO.Params[0].PDF_Compression  := TIOPDFCompression.ioPDF_JPEG;
iemv_OUT.MIO.Params[0].PDF_PaperSize    := TIOPDFPaperSize.iepA4;
iemv_OUT.MIO.Params[0].TIFF_Compression := TIOTIFFCompression.ioTIFF_JPEG;
iemv_OUT.MIO.DuplicateCompressionInfo();


I have a good quality file, however it's bigger than a4 and the pages are 1194*1684 pixel.
I would like to resize the images on each page so that it fit into an A4.
How can I do that?
I tried
iev_IN.Proc.Resample(1000, 1000, TResampleFilter.rfFastLinear, true);

but 1000 probably it's not enough and it gets blurried.
Also I would like to shrink only bigger images, not make smaller images bigger.

thank you
Go to Top of Page

xequte

38608 Posts

Posted - Feb 01 2022 :  20:50:01  Show Profile  Reply
1. I can't reproduce that. Is there any content in the TImageEnView (e.g. layers). What version of Delphi are you using? 32bit or 64bit apps. What happens if you remove iev_IN.ClearAll; (which should not be necessary). Do you want to send me your PDF test file?

2. It really depends on your purpose. If you just want higher resolution when exporting, use PdfViewerDefaults.DPI. If you want a specific size, use DrawTo with params()

3. Well, for most purposes A4 is meaningless when it comes to images. But let's assume you want to print 1:1 at A4 size. That would mean your image would need to be 8.25 x 11.75 in (Again these are printing value, not image values). If your image is 96dpi, then your pixel size would need to be scaled to 792x1128 pixels. Alternatively, you could just adjust your DPI, which for an 1194*1684 image would need to be 144

for i := 0 to iemv_OUT.Count - 1 do
  iemv_OUT.MIO.Params[i].DPI := 144;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
Jump To: