Issue with Deleting Pages  SOLVED

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, 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
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Issue with Deleting Pages

Post by mmasood »

Hi Alex,

I am using 7.0.326.0 of Core Api and C#. I am having issues with deleting pages from pdf files. Following are the steps to reproduce the issue:

1. Runn the project CoreAPIDemo that is installed with the Core Api installer.
2. Run the project and click on the point "3.3 Remove first page from the current document"
3. Then click on the "Run Sample" button.
4. It deletes the page just fine and shows the document.
5. Click on the "Close" button or close down the application, an error occurs.

I have tried to debug the code but could not find where the error is originating from so I am not able to trap it.

I have attached a sample file that is crashing. Can you take a look and let us know why this is happening and what steps are needed to fix the issue?

Regards,
M
Attachments
FeatureChartEU Does Not Work.pdf
(38.55 KiB) Downloaded 174 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Issue with Deleting Pages

Post by Sasha - Tracker Dev Team »

Hello mmasood,

It's a known problem with the IPXC_Pages, IPXC_Page, IPXC_FormField and IPXC_NameTree. The thing is that if you use the statement like this

Code: Select all

m_CurDoc.Pages[0].get_Box(PXC_BoxType.PBox_MediaBox);
the .Net/Delphi will make virtual objects of IPXC_Pages and IPXC_Page. The problem is that these objects will only be released when the .Net/Delphi wants that. In this case these objects are being released after the IPXC_Inst Shutdown method - when the program destroys itself. This causes them to be "hanged" because everything is already destroyed and they are attempting to call these destroyed objects in the native code - thus the crash occur. I've already made a fix for that, though it will be only available with the next release, because we've also added few new methods that are already in the new samples. Thus merging to git will only be valid with the latest version of the dll that was not released yet.
The fixed 3.3 sample looks like this:

Code: Select all

[Description("3.3. Remove first page from the current document")]
static public int RemoveFirstPageFromTheDocument(Form1 Parent)
{
	if (Parent.m_CurDoc == null)
		Document.OpenDocFromStringPath(Parent);
	IAUX_Inst auxInst = (IAUX_Inst)Parent.m_pxcInst.GetExtension("AUX");
	IBitSet bs = auxInst.CreateBitSet(1);
	bs.Set(0);
	IPXC_UndoRedoData urd = null;
	IPXC_Pages pages = Parent.m_CurDoc.Pages;
	if (pages.Count > 1)
		pages.DeletePages(bs, null, out urd);
	else
		MessageBox.Show("The last page can't be removed from the document!");
	Marshal.ReleaseComObject(pages);
	return (int)Form1.eFormUpdateFlags.efuf_All;
}
Notice the Marshal.ReleaseComObject(pages); - this tells the .Net to forcefully release that object after the usage. And this should be done with all of the object interfaces that I mentioned. Note, that if you want to use an IPXC_Page method or property then you will have to make 2 variables (IPXC_Pages and IPXC_Page) so that you can release them properly. Here's how it should look like:

Code: Select all

IPXC_Pages pages = Parent.m_CurDoc.Pages;
IPXC_Page firstPage = pages[0];
PXC_Rect rcMedia = firstPage.get_Box(PXC_BoxType.PBox_MediaBox);
IPXC_UndoRedoData urd = null;
//Adding pages with the size of the first page of the current document
pages.AddEmptyPages(0, 3, ref rcMedia, null, out urd);
Marshal.ReleaseComObject(firstPage);
Marshal.ReleaseComObject(pages);
Also, the fix is very widespread because every class uses one of those interfaces and every one of them should be released properly. Thus fixing only this sample in your code won't work, because you should also fix the Form1.cs document for the correct behavior, as it loads the preview and all of the IPXC_NameTree with Destinations, Attachments etc.

PS: We will probably also address this in our native code - because this is not how it should work properly. The problem is with the declaration of these classes and the way that they are used inside of our native code. But for now, the fix that I mentioned should work.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Issue with Deleting Pages

Post by mmasood »

Hi Alex,

I extracted the code for deleting pages into a separate project that is attached. I added the Marshal call in the project and it is still crashing. Can you please check that out?

Regards,
M
Attachments
DeletePagesTest.zip
(329.42 KiB) Downloaded 168 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Issue with Deleting Pages

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Here's a line that you forgot:

Code: Select all

Form1.cs(64)
int liCurrentPageCount = (int)loDoc.Pages.Count;
You will have to do

Code: Select all

IPXC_Pages loPages = loDoc.Pages;
before it.

Also, I did not experience a crash.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Issue with Deleting Pages

Post by mmasood »

Hi Alex,

That line was supposed to be commented out, my mistake. I commented out that line and it is still crashing for me.

Are you using the file that I provided? Which version of VS are you using? (I am using VS 2017 with Core API 7.0.326.0)

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

Re: Issue with Deleting Pages  SOLVED

Post by Sasha - Tracker Dev Team »

Hello mmasood,

I've recreated that crash. Please add this line of code - it seems that the IPXC_UndoRedoData interface should also be released in case of page removal - missed that one:

Code: Select all

Marshal.ReleaseComObject(urd);
Marshal.ReleaseComObject(loPages);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Issue with Deleting Pages

Post by mmasood »

Hi Alex,

Thanks that fixed the code. I think it was the UndoRedo object that was the issue. I commented out the Marshal call for Pages and it still worked fine. I have the IPXC_Pages in a lot of other functions and they are all processing fine as well.

Also do you have an estimate on when the version with the fixes will be released?

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

Re: Issue with Deleting Pages

Post by Sasha - Tracker Dev Team »

Hello mmasood,

We plan to release a .1 build in a week or so - then we'll update the git project along with the CoreAPI sample projects.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Issue with Deleting Pages

Post by mmasood »

Hi Alex,

I was testing and found out that this was only happening on files that had at least one form element on them. The files that did not have Form elements work fine even without the fix.

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

Re: Issue with Deleting Pages

Post by Sasha - Tracker Dev Team »

Hello mmasood,

There is a problem with the IPXC_FormField interface that also needs to be released. We are aware of that and are investigating this matter.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Issue with Deleting Pages

Post by mmasood »

Hi Alex,

I just saw that the version 7.0.327.1 is out there now. Does it include the fixes and the updated sample code with it?

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

Re: Issue with Deleting Pages

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Yes, this build includes the new methods. Pushed the fixed version to the Tracker Git page:
https://github.com/tracker-software/PDFCoreSDKExamples

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply