priPrinter: page.GetText() etc - priPrinter

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

page.GetText() etc

#1 User is offline   sjx 

  • Member
  • PipPip
  • Group: Senior Members
  • Posts: 21
  • Joined: 17-November 11

Posted 26 September 2012 - 02:38 PM

I encountered 2 new problems

1. It looks like page.DeleteRect() does not actually delete the content in the Rect area, instead it hides the content. So after issuing page.DeleteRect(), page.GetText() still returns the whole content of the original page, right?

2. page.GetText(Rect()) does not work as expected. see remark incorrect1 and incorrect2 in the following example



first create a text file

local f=File("C:/1.txt","w");
local log;
for(local i=10;i<73;i++)
{
for(local j=10;j<22;j++)
{
log="LINE" + i + " ";
f.Write(log,"sa");
}
f.Write("\r\n","sa");
}


Now use windows notepad to open 1.txt and print it to PP, then run the following code. You may need to change the variable crop_area carefully to select the top left 12 (4 x 3) elements. The whole page search page.Search() returns 12 results as expected, but page.GetText(crop_area) returns the top full 4 lines, instead of the expected top left 4x3 elements. Furthermore, text.find(search_str) did not return the expected result 3.

local search_str="Line11";
local doc=window.GetDocument();
local page=doc.GetPage(0);

local crop_area=Rect(18,28.4,61.6,42.6);
local found=page.Search(search_str,{matchcase=false,wholeword=false}); // correct
if (found)
print("found \"" + search_str + "\" " + found + " times\n");

local text=page.GetText(crop_area); // incorrect1, returns 4 full lines
print("cropped text is:\n");
print(text+"\n");


found=text.find(search_str); // incorrect2, expect to return 3
if (found!=null)
print("found \"" + search_str + "\" " + found + " times\n");
-1

#2 User is offline   Alex 

  • Administrator
  • Group: Administrators
  • Posts: 238
  • Joined: 28-February 10
  • LocationHungary

Posted 26 September 2012 - 07:25 PM

We'll check.
0

#3 User is offline   Alex 

  • Administrator
  • Group: Administrators
  • Posts: 238
  • Joined: 28-February 10
  • LocationHungary

Posted 27 September 2012 - 01:21 PM

DeleteRect() removes commands ( like TextOut ) or applies clip rectangle to them. In this sample file, text strings are very long. They are not removed completely, delete works via applying clipping rectangle.

Similar situation is with GetText. It retrieves text of the whole text command. That's why you are getting the whole line.

GetText was fixed and now it should retrieve only characters inside of the rectangle.
You can pick an update from our beta page.
One more option is added. You may specify condition: include or discard character into output string. For instance, you may specify that at least 80% of character's rectangle should be inside of the crop rect in order to process it. If you are interested, please see description of this command.

found=text.find(search_str); // This one is case sensitive, so please use:
local search_str="LINE11";
BTW, it returns index of first sub string.
0

#4 User is offline   sjx 

  • Member
  • PipPip
  • Group: Senior Members
  • Posts: 21
  • Joined: 17-November 11

Posted 29 September 2012 - 03:56 AM

copyRect is working now. thanks. 2 new problems

file operation

SetSize(int size) doesn't work at all
CopyTo(File, [int size]) does not take the second parameter
0

#5 User is offline   Alex 

  • Administrator
  • Group: Administrators
  • Posts: 238
  • Joined: 28-February 10
  • LocationHungary

Posted 01 October 2012 - 06:40 AM

Thank you for bug report.
These functions should be fixed, update is in beta area.
0

#6 User is offline   sjx 

  • Member
  • PipPip
  • Group: Senior Members
  • Posts: 21
  • Joined: 17-November 11

Posted 01 October 2012 - 10:19 PM

It looked like DuplicatePage() and InsertPage() are by reference. So the new page and old page point to the same memory. See the remark in the following code

local doc=window.GetDocument();
local page0=doc.GetPage(0);
local page_size=page0.GetSize(0);


doc.DuplicatePage(page0,1);
local page1=doc.GetPage(1);
page1.DeleteRect(Rect(0,0,page_size.x,page_size.y/2)); // top half page is deleted for the first page too
doc.InsertPage(page0,1); // top half page got deleted for all 3 pages
window.SaveAs("c:/1.priPrinter");


now close PP then double click 1.priPrinter in windows explorer, page 2 and 3 are blank with a red X in the center
0

#7 User is offline   Alex 

  • Administrator
  • Group: Administrators
  • Posts: 238
  • Joined: 28-February 10
  • LocationHungary

Posted 02 October 2012 - 06:10 PM

Yes, new page is an instance of 'old' page. Page size and attributes are unique, but contents will be same.
Please use page.CopyRect and page.Paste.

Thank you!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users