WPCubed Product Support

How do you select programaticaly an area of a PDF and extract the text ou of it ? (VCL)

wpsupport

About the AV: If you use the viewer to work on a PDF, the window must be created.

Otherwise the DLL is not loaded and the engine was not created.

#16 ♥ 0
13.9k Views 3 users read 4 min
wpsupport

Please note that the 3. and 4. COMPDF_GetTextFilterRect parameters are X1 and Y1 values, not Width and Height.

I used this code to test:

procedure TForm1.SelRectEventToDrawrectangleandextracttext(
       Sender: TObject; const PageNr: Integer; R: TRect);
var WPViewPDF : TWPViewPDF;
    s : string;
begin
    WPViewPDF:= (Sender as TWPViewPDF);
    WPViewPDF.OnSelRectEvent := nil;
    try
        WPViewPDF.command(COMPDF_GetTextSetOptions, 4+2); // Activate the filter
        WPViewPDF.command(COMPDF_GetTextFilterRectX , r.Left );
        WPViewPDF.command(COMPDF_GetTextFilterRectY , r.Top );
        WPViewPDF.command(COMPDF_GetTextFilterRectX1, r.Right );
        WPViewPDF.command(COMPDF_GetTextFilterRectY1, r.Bottom );
        s := WPViewPDF.GetPageText(PageNr);
        ShowMessage( s );  
    finally
        WPViewPDF.command(COMPDF_GetTextSetOptions, 2); // DE-Activate the filter
    end;
end;

procedure TForm1.Drawrectangleandextracttext1Click(Sender: TObject);
begin
  if pdf<>nil then  // "pdf" is the current WPViewPDF instance
  begin
    pdf.OnSelRectEvent := SelRectEventToDrawrectangleandextracttext;
    pdf.CommandEx(COMPDF_SelectMode, 2); // let the user draw ...
  end;
end;
#15 ♥ 0

Zugriffsverletzung bei Adresse 0726446F in Modul 'wPDFViewPlus04.dll'. Lesen von Adresse 00000000.

Just after : WPViewPDF1.ViewerStart('wPDFViewPlus04.dll', 'aircraft data systems', 'YYYY-YYYY-YYYY-YYYY' , XXXXXXX );

Coordinates:

WPViewPDF1.command(COMPDF_GetTextSetOptions, 4+2); // Activate the filter

WPViewPDF1.command(COMPDF_GetTextFilterRectX , 457 );

WPViewPDF1.command(COMPDF_GetTextFilterRectY , 86 );

WPViewPDF1.command(COMPDF_GetTextFilterRectX1, 100 );

WPViewPDF1.command(COMPDF_GetTextFilterRecty1, 23 );

WPViewPDF1.AddHighlightRect(0, StrToInt(Edit6.Text), StrToInt(Edit7.Text), StrToInt(Edit8.Text), StrToInt(Edit9.Text) , 255, [wpAnnotAtFoundText] );

RzMemo1.Lines.Add(WPViewPDF1.GetPageText(0));

#14 ♥ 0
wpsupport

In your first post you had WPViewPDF1.ViewerStart('wPDFView03.dll',..) , this is why I asked.

Please send me a sample and the coordinates you are using so I can try it out myself.

#13 ♥ 0

What I have in my Installation and execution folders:

wp_type1ttf.dll Version 2.10.0.0

wp_type1ttf64.dll Version 2.4.6.2

wpdecodejp.dll Version 1.2.0.1

wpdecodejp64.dll Version 1.2.0.1

wPDFView03.dll Version 3.28.4.2

wPDFView03x64.dll Version 3.28.4.3

wPDFViewPlus04.dll Version 4.8.0.2

wPDFViewPlus04x64.dll Version 4.4.2.0

#12 ♥ 0

Hi,

I tried with that :

FormCreate :

WPViewPDF1.ViewerStart('wPDFViewPlus04.dll', 'aircraft data systems', 'YYYY-YYYY-YYYY-YYYY' , XXXXXXX );

WPViewPDF1.MouseMode(wpLeftButton, wpmDrawCustom );

WPViewPDF1.Command(COMPDF_SelectMode, wpmouse_DrawCustom );

And I get the same result.

The whole page is recongnized whatever I pass as parameters:

ButtonCLick:

WPViewPDF1.command(COMPDF_GetTextSetOptions, 4+2); // Activate the filter

WPViewPDF1.command(COMPDF_GetTextFilterRectX , StrToInt(Edit6.Text) );

WPViewPDF1.command(COMPDF_GetTextFilterRectY , StrToInt(Edit7.Text) );

WPViewPDF1.command(COMPDF_GetTextFilterRectX1, StrToInt(Edit8.Text) );

WPViewPDF1.command(COMPDF_GetTextFilterRecty1, StrToInt(Edit9.Text) );

WPViewPDF1.AddHighlightRect(0, StrToInt(Edit6.Text), StrToInt(Edit7.Text), StrToInt(Edit8.Text), StrToInt(Edit9.Text) , 255, [wpAnnotAtFoundText] );

RzMemo1.Lines.Add(WPViewPDF1.GetPageText(0));

#11 ♥ 0
wpsupport

Hi,

You are using Wpviewpdf version 3?

I added the feature to the current version 4.

Julian

#10 ♥ 0

What is that ?

function GetPageText(PageNo: Integer; format: string = ''): AnsiString;

{ :: This function retrieves the ANSI text of a certain page in the range 0..PageCount-1<br>

PageNo = -1 will read the complete text.<br>

PageNo = -2 will read the selected pages.<br>

PageNo = -3 will read the selected text<br>

This formats are possible: RTF, ANSI, UNICODE, HTML.<br>

For HTML it is possible to add a '=' and the path which will be used for the images: HTML=path

}

should I put : RzMemo1.Lines.Add(WPViewPDF1.GetPageText(-3)); ?

#9 ♥ 0

Hi,

I load the new version and started working on it...

{$I WPViewPDFINC.INC}

Uses WPDF_ViewCommands, WPViewPDF4, WPViewPDF3,..

...

WPViewPDF1.ViewerStart('wPDFView03.dll', 'aircraft data systems', 'yyyyyyyyyyyyyyyyy' , xxxxxxxxx);

WPViewPDF1.MouseMode(wpLeftButton, wpmDrawCustom );

WPViewPDF1.Command(COMPDF_SelectMode, wpmouse_DrawCustom );

...

WPViewPDF1.command(COMPDF_GetTextSetOptions, 4+2); // Activate the filter

WPViewPDF1.command(COMPDF_GetTextFilterRectX , StrToInt(Edit6.Text) ); --> 36

WPViewPDF1.command(COMPDF_GetTextFilterRectY , StrToInt(Edit7.Text) ); --> 483

WPViewPDF1.command(COMPDF_GetTextFilterRectX1, StrToInt(Edit8.Text) );--> 47

WPViewPDF1.command(COMPDF_GetTextFilterRecty1, StrToInt(Edit9.Text) ); --> 541

RzMemo1.Lines.Add(WPViewPDF1.GetPageText(0));

...

Coordinates were taken out of a direct selection on screen with the DoSelRectEvent event.

And it takes the whole page text every times.

#8 ♥ 0
wpsupport

Nein, aber man kann die DrawRechteck Funktion nehmen.

Command(COMPDF_SelectMode, wpmouse_DrawCustom )

mit einem solchen event handler fuer

OnSelRectEvent

procedure TWPViewPDFDemo.DoSelRectEvent(Sender: TObject; const PageNr: Integer;
  R: TRect);
begin
  ...
end;
#6 ♥ 0

Ist es auch möglich X, Y, X1, Y1 von einen selektierten Text zu bekommen?

#5 ♥ 0
wpsupport

With next release this will be possible:

pdf.command(COMPDF_GetTextSetOptions, 4+2); // Activate the filter

pdf.command(COMPDF_GetTextFilterRectX, 150);

pdf.command(COMPDF_GetTextFilterRectY, 150);

pdf.command(COMPDF_GetTextFilterRectX1, 400);

pdf.command(COMPDF_GetTextFilterRecty1, 300);

ShowMessage(pdf.GetPageText(0));

#2 ♥ 0

Hi,

I know this sounds possible but I could not figure any where how to do it.

I have thousands of PDFs that have their reference at the same place.

I would like to be able to select this area and get the text to identify the reference of the PDF.

Basically I would like to have something like :

WPDF_GETTEXT( x, y , width , height, Page number) : string;

How should I do ?

(No action from user requiered, batch fonctionnement).

thanks

#1 ✎ ♥ 0