Changing Defaults In CropPages pane

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

Changing Defaults In CropPages pane

Post by plgoldman »

About two weeks ago I began evaluating the Tracker "PDF-XChange Editor SDK" for a major project at my organization. Thus far I have been very pleased with the the software and have given a number of "proof of concept" demonstrations to the project stake holders and have gotten nothing but positive feedback. I spend a great deal of time reading through the available documentation and the user forums and for the first time I have a question that I have not been able to find an answer to using those resources.

We are working in an MS Windows environment, Windows 10, developing in C# with Visual Studio 2013. One of the key functions for the project is the ability to crop a page within a PDF document and save the document up to an including the cropped page. I have no issue invoking the page crop function as follows:

Code: Select all

var cmndString = uiInst.CmdManager.Cmds.Find("cmd.document.cropPages");
pdfCtl.Inst.ExecUICmd2(cmndString.ID);
and then using "op.document.resizePages" and "op.document.extractPages" to produce the desired end document. However, when the "Crop Pages" panel appears the selected defaults, e.g. "Remove the content outside of the crop box area" and "Current Page," are unchecked. For the convenience, speed and accuracy of our end users we would like to have these options always selected. Is there a way to either configure or programmatically select the desired options before displaying the panel to the end user.

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

Re: Changing Defaults In CropPages pane

Post by Sasha - Tracker Dev Team »

Hello Paul,

Here's what can be done - you can catch the ShowModal event and then see whether it's an CropPages dialog. Then modify the needed values. For this use this code:

Code: Select all

public partial class CropPagesEventMonitor : PDFXEdit.IUIX_EventMonitor
{
	private int m_nID = 0;
	public CropPagesEventMonitor(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("RangeCtl.Current", 1, true);
			dlg.CheckItem("crop.Redaction", 1, true);
		}
	}
}

private void cropDialogWihPredefinedSettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
	CropPagesEventMonitor myCropMonitor = new CropPagesEventMonitor(pdfCtl.Inst.Str2ID("DlgCropPages2"));
	uiInst.CurrentThreadCtx.RegisterEventMonitor(myCropMonitor);
	pdfCtl.Inst.ExecUICmd("cmd.document.cropPages");
	uiInst.CurrentThreadCtx.UnregisterEventMonitor(myCropMonitor);
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Re: Changing Defaults In CropPages pane

Post by plgoldman »

Alex,

Thank you so much. The code you presented did exactly what was wanted as well as showed me some useful techniques.

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

Re: Changing Defaults In CropPages pane

Post by Tracker Supp-Stefan »

Kudos to Alex! :)

Cheers!
Post Reply