Cropping / Splitting Pages

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Cropping / Splitting Pages

Post by plgoldman »

Not long ago you guys were a great help in showing me how to set the defaults for the end user so that when "cnd.document.cropPages" is executed the modal dialog window is displayed with the desired options selected. This has been working perfectly. However, end users being what they are now want more.

The situation is that rather than just "cropping" a page the end users would like to "split" the page into two or three pieces. I know there is a split page function available to the end users via the "More for pages" menu item available when one right clicks on a thumbnail but given the number of pages that need to be processed and the volume of documents our end users have to go through on a given day, getting to that split function is rather unwieldy, It also produces a lot of what one of them called "clutter" on the screen just to get to a need operation.

So, question - is there any way to get to the split function programmatically?

If not, is there any way to get the coordinates of the crop box, and possibly its compliment, from the "cropPages" command so that I could produce my own version of split page from the crop box information in "cropPages."

More generally, any guidance on how to get two or more pages from one programmatically with the only end user requirement being their creating a crop box or horizontal split line with the mouse.

As always, thanks for your help,
Regards,
Paul
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Cropping / Splitting Pages

Post by Sasha - Tracker Dev Team »

Hello Paul,

Well the split operation is available for usage right now, though, it's not yet in the Wiki itself as it was just recently added - we will try to update the page shortly though.
Here's a respective CAB for the split pages operation Options:

Code: Select all

ITEMS_PUB(g_SplitLines)
{
	{ L"Position",				dt_Double,	0,					_D(0.0),				NULL			},
	{ L"IsVertical",			dt_Bool,	0,					_N(false),				&g_NamedBool	},
	{}
};

ITEM(g_SplitLine)	DIC(NULL, 0, g_SplitLines);

ITEMS_PUB(g_OperSplitPages)
{
	{ L"UsePercentValues",			dt_Bool,	0,		_N(true),						&g_NamedBool },
	{ L"UseDuplicateAndCropMode",	dt_Bool,	0,		_N(true),						&g_NamedBool },
	{ L"PreserveOriginalContent",	dt_Bool,	0,		_N(true),						&g_NamedBool },
	{ L"RemoveOriginalPage",		dt_Bool,	0,		_N(true),						&g_NamedBool },
	{ L"UseRTL",					dt_Bool,	0,		_N(false),						&g_NamedBool },
	ARR(L"Lines",					0,			&g_SplitLine),
	DIC( L"PagesRange",				0,			g_PagesRange),
	{},
};
As for the code sample:

Code: Select all

private void SplitPages(PDFXEdit.IPXV_Document Doc, PDFXEdit.IPXV_Inst Inst)
{
	int nID = Inst.Str2ID("op.document.splitPages", false);
	PDFXEdit.IOperation pOp = Inst.CreateOp(nID);
	PDFXEdit.ICabNode input = pOp.Params.Root["Input"];
	input.v = Doc;
	PDFXEdit.ICabNode options = pOp.Params.Root["Options"];
	options["UsePercentValues"].v = true;
	options["PagesRange.Type"].v = "Exact";
	options["PagesRange.Text"].v = "1-3"; //Select pages range that will be split
	PDFXEdit.ICabNode line = options["Lines"].Add();
	line["Position"].v = 50; //50%
	line["IsVertical"].v = false;
	pOp.Do();
	PDFXEdit.ICabNode output = pOp.Params.Root["Output"];
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Re: Cropping / Splitting Pages

Post by plgoldman »

Alex,
Once more, thank you. This is the piece I was looking for. I have a major demonstration of the work I have been doing this Wednesday as part of the "home stretch" of our evaluation. The product owner for this effort has been extremely pleased with what i have been able to produce and the demo is for "higher" level management. I keep reminding everyone that not only is this a great product but the support is outstanding.

So, please indulge me in one more question related to page splitting.

Besides the code sample you sent me I have a "Split Page" button in my program with a routine which starts out with:

Code: Select all

  var cmndString = uiInst.CmdManager.Cmds.Find("cmd.document.splitPages");
            pdfCtl.Inst.ExecUICmd2(cmndString.ID);
Simple enough and it does what it's supposed to. However, after the page split is complete I continue to do a resize on the pages which were just split using "op.document.resizePages" specifying a "PagesRange.Filter" of "All" and a "PageRange.Text" of exactly the pages that were output by the split. What I found is that if I leave all of the defaults on the "Page Split" window alone when splitting a page into three pieces and then perform the resize the first and third piece appear as expected but the middle piece is the original page even though before the resize the results were as expected. I have found that if I uncheck the "Preserve original content" under "Settings," things work perfectly. In fact on the three pages that are resized the extracted text appears dead center on the page which is something the product owner has wanted for a while.

So here's the question: I've attempted to emulate the work you supplied me for "Page Crop" with a "SplitPagesEventMonitor" class. In my routine for the "Split Page" button I tried the following:

Code: Select all

  SplitPagesEventMonitor mySplitMonitor = new SplitPagesEventMonitor(pdfCtl.Inst.Str2ID("DlgSplitPages"));
            uiInst.CurrentThreadCtx.RegisterEventMonitor(mySplitMonitor);
            pdfCtl.Inst.ExecUICmd("cmd.document.splitPages");
            uiInst.CurrentThreadCtx.UnregisterEventMonitor(mySplitMonitor);
In the "SplitPagesEventMonitor class I have the following:

Code: Select all

        public partial class SplitPagesEventMonitor : PDFXEdit.IUIX_EventMonitor
        {
            private int m_nID = 0;
            public SplitPagesEventMonitor(int nID)
            {
                m_nID = nID;
            }
            public void OnEventMonitor(PDFXEdit.IUIX_Obj pTarget, PDFXEdit.IUIX_Event pEvent)
            {
                if (pEvent.Code == (uint)PDFXEdit.UIX_EventCodes.e_ShowModal)
                {
                    IntPtr outPtr;
                    pTarget.QueryImpl(typeof(PDFXEdit.IUIX_Dialog).GUID, null, out outPtr);
                    PDFXEdit.IUIX_Dialog dlg = (PDFXEdit.IUIX_Dialog)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(outPtr);
                    if (dlg == null)
                        return;

                    if (dlg.ID != m_nID)
                        return;

                    dlg.CheckItem(WHAT SHOULD GO HERE TO TURN OFF "Preserve original content"?, 1, false);
                }
            }
        }
In testing I do in fact hit the "dlg.CheckItem" statement when the user clicks on the "Split Page" button, just don't know what to put there. Could you be of help on that?

Thanks again,
Paul
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Cropping / Splitting Pages

Post by Sasha - Tracker Dev Team »

Hello Paul,

To see the dialog item IDs, open the Resources.dat file as a zip file, then open the Misc\DlgTempates.xml file. Inside there are templates of all of the dialogs. You can use the ID of the Dialog that you have, to see the items that that dialog has. For example, the check box that you want has the id="dsp.chb.preserveContent".

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Re: Cropping / Splitting Pages

Post by plgoldman »

Hi Alex,

Thanks so much. You not only answered my specific question but provided me with the needed general approach to managing the options on all dialog panels.. It worked beautifully, once I figured out that you have to set the field following the option name to "0."

Regards,
Paul
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17941
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Cropping / Splitting Pages

Post by Tracker Supp-Stefan »

Glad we could assist Paul!

Cheers,
Stefan
Post Reply