priPrinter: Page splitting - priPrinter

Jump to content

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

Page splitting

#1 User is offline   CoMPi 

  • Advanced Member
  • PipPipPip
  • Group: Senior Members
  • Posts: 208
  • Joined: 05-April 13

Posted 04 February 2014 - 10:12 PM

Hi,

I am just wondering. Is it possible to split page into 2 or more (sub)pages? In example, is it possible to split A4 page into 2 A5 pages?

Piotr
Piotr
0

#2 User is offline   Alex 

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

Posted 05 February 2014 - 02:14 PM

Not really.

But you can create empty page and cut content from first page and paste into second.

However size will be A4 not A5.
Please send or attach your priPrinter file (nice sample is always good) we will think what we can do.
0

#3 User is offline   CoMPi 

  • Advanced Member
  • PipPipPip
  • Group: Senior Members
  • Posts: 208
  • Joined: 05-April 13

Posted 05 February 2014 - 04:58 PM

The page fomat (A4, A5, etc.) is not important. The main problem is how to split plenty of pages at once. Here is a small example before and after split operation.

Attached File(s)


Piotr
0

#4 User is offline   Alex 

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

Posted 06 February 2014 - 09:24 AM

Nice test for our script engine. Will try to play with it...
0

#5 User is offline   Aron 

  • priPrinter Support
  • Group: Administrators
  • Posts: 131
  • Joined: 28-February 10

Posted 08 February 2014 - 11:14 AM

Hi Piotr,

Try this script:

function SplitPage(doc,index)
{
	local page=doc.GetPage(index);
	local size=page.size;
	// we have a size of source page

	local rectToCopy=Rect(size.x/2,0,size.x,size.y);
	local stream=page.CopyRect(rectToCopy);
	// stream contains right part of our page

	page.DeleteRect(rectToCopy);
	// now we deleted right part of source page - not required,
	// but it should help priPrinter to work faster

	page.SetSize(Point(size.x/2,size.y));
	// page has a new size

	local newPage=doc.InsertBlank(page,index+1);
	// this is a new page, with same size as previous one
	if(stream)
	{
		stream.Seek(0);
		newPage.Paste(stream,Point(0,0));
		// paste content into new place
	}
}

// main part
local doc=window.GetDocument();
local iPage=0;
while(iPage<doc.GetNumPages())
{
	SplitPage(doc,iPage);
	iPage+=2;// skip new page
}



PS
That was easy.
0

#6 User is offline   CoMPi 

  • Advanced Member
  • PipPipPip
  • Group: Senior Members
  • Posts: 208
  • Joined: 05-April 13

Posted 10 February 2014 - 02:13 AM

Great Posted Image To be honest I did not know how useful could be your script engine Posted Image I see now that I should seriously consider upgrading priPrinter Standard to Pro edition Posted Image


OK. But let's get back to the script. I tried the script on a few test files and I see that it does not support properly pages of different orientations. So I prepared my version of your script which takes into account booth the orientation and rotation of pages. The differences are clearly visible when you test both scripts with the included test files.

One thing. Working on the script I was trying to use a local variable to set the page size. I was really surprised that it did not work. I tried something like this
local size = page.size;
local newSize = Point(size.x / 2, size.y);
// some code
page.SetSize(newSize);

What did I wrong?

Piotr

PS. Sorry for my (weird) source formatting.

function SplitPage(doc,index) {
	// page to process
	local page = doc.GetPage(index);

	// reset page angle (will be restored after splitting)
	local angle = page.angle;
	page.angle = 0;

	// size of the page and the flag which is set for horizontal pages
	local size = page.size;
	local isHorz = size.x > size.y;

	// streams for the two subpages 
	local firstPage;
	local secondPage;

	// this script assumes that the first subpage is placed in the left half of a horizontal page or in the bottom half of a vertical page
	// documents containing pages of different orientations should be prepared in a manner that ensures compliance with these requirements
	if (isHorz) {
		if ((angle == 0) || (angle == 3)) {
			firstPage = page.CopyRect(Rect(0, 0, size.x / 2, size.y));
			secondPage = page.CopyRect(Rect(size.x / 2, 0, size.x, size.y));
		} else {
			firstPage = page.CopyRect(Rect(size.x / 2, 0, size.x, size.y));
			secondPage = page.CopyRect(Rect(0, 0, size.x / 2, size.y));
		}
		page.SetSize(Point(size.x / 2, size.y));
	} else {
		if ((angle == 2) || (angle == 3)) {
			firstPage = page.CopyRect(Rect(0, 0, size.x, size.y / 2));
			secondPage = page.CopyRect(Rect(0, size.y / 2, size.x, size.y)); 
		} else {
			firstPage = page.CopyRect(Rect(0, size.y / 2, size.x, size.y));
			secondPage = page.CopyRect(Rect(0, 0, size.x, size.y / 2)); 
		}
		page.SetSize(Point(size.x, size.y / 2));
	}

	// add two newly created pages and remove the source page
	local newFirstPage = doc.InsertBlank(page, index + 1);
	local newSecondPage = doc.InsertBlank(page, index + 2);
	doc.DeletePage(index);

	// contant pasting and autocrop for booth pages
	if (firstPage) {
		newFirstPage.Paste(firstPage, Point(0, 0));
		local crop = newFirstPage.AutoCrop();
		if (crop) 
			newFirstPage.SetCrop(crop);
	}
	if (secondPage) {
		newSecondPage.Paste(secondPage, Point(0, 0));
		local crop = newSecondPage.AutoCrop();
		if (crop) 
			newSecondPage.SetCrop(crop);
	}

	// restore page angle
	newFirstPage.angle = angle;
	newSecondPage.angle = angle;
}

// main part
local doc=window.GetDocument();
local iPage=0;
while(iPage<doc.GetNumPages())
{
	SplitPage(doc,iPage);
	iPage+=2;// skip new page
}

Attached File(s)


Piotr
0

#7 User is offline   Aron 

  • priPrinter Support
  • Group: Administrators
  • Posts: 131
  • Joined: 28-February 10

Posted 10 February 2014 - 07:51 AM

PRO, sure, you are welcome. When you will be ready, drop us an email and ask for discount.
Regarding local variable - yes something is wrong.

PS
Scripting - we are happy with script core, very small (<100k), easy to integrate.
0

#8 User is offline   CoMPi 

  • Advanced Member
  • PipPipPip
  • Group: Senior Members
  • Posts: 208
  • Joined: 05-April 13

Posted 10 February 2014 - 03:36 PM

I am now a happy user of priPrinter Pro :)
Thank you :)
Piotr
0

#9 User is offline   Aron 

  • priPrinter Support
  • Group: Administrators
  • Posts: 131
  • Joined: 28-February 10

Posted 10 February 2014 - 04:33 PM

View PostCoMPi, on 10 February 2014 - 03:36 PM, said:

I am now a happy user of priPrinter Pro :)/>

Thank you!

Issue with local variable is fixed. Please check beta page.
0

#10 User is offline   CoMPi 

  • Advanced Member
  • PipPipPip
  • Group: Senior Members
  • Posts: 208
  • Joined: 05-April 13

Posted 10 February 2014 - 05:43 PM

Strange. In the latest version the above script does not work properly. Try to split one of the test file. Works? Probably yes. But try to split the result one more time. It does not work for me.
Is there a way to download again the previous version (v6.0.3.2258)?
And another question. How to debug scripts? Any debuger? Anything?
Piotr
0

#11 User is offline   Aron 

  • priPrinter Support
  • Group: Administrators
  • Posts: 131
  • Joined: 28-February 10

Posted 10 February 2014 - 07:15 PM

View PostCoMPi, on 10 February 2014 - 05:43 PM, said:

Is there a way to download again the previous version (v6.0.3.2258)?


Unfortunately no. Crash in new version just a coincidence, old version had same problem.

But, I hope issue is fixed.
Try this one: www.priprinter.com/beta/priPrinterProSetup1.exe
0

#12 User is offline   CoMPi 

  • Advanced Member
  • PipPipPip
  • Group: Senior Members
  • Posts: 208
  • Joined: 05-April 13

Posted 10 February 2014 - 07:39 PM

Yes, it is. Thank you :)
Piotr
0

#13 User is offline   Aron 

  • priPrinter Support
  • Group: Administrators
  • Posts: 131
  • Joined: 28-February 10

Posted 10 February 2014 - 07:57 PM

Great.
There is no debugger right now, may be later...
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