Problems with pxcInst.OpenDocumentFromFile

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.
troutinger
User
Posts: 8
Joined: Tue Apr 18, 2023 9:18 am

Problems with pxcInst.OpenDocumentFromFile

Post by troutinger »

Hey,

I have to load a basic pdf with text forms and fill in these forms. Therefore I have to load the basic pdf a couple of times.
Within this loop, I use some a new operator for a parser class. This leads to an error with the OpenDocumentFromFile function although this has nothing to with the loaded Doc.
test.pdf
.

I can also reproduce the error forcing the garbage collection to do its work. It seems to me, the OpenDocumentFromFile function has some memory problems when invoked several times within a loop.

Here is the the code:

private void btn_test_Click(object sender, EventArgs e)
{
m_Inst = new PXV_Inst();
m_Inst.Init();

IPXC_Inst pxcInst = (IPXC_Inst)m_Inst.GetExtension("PXC");
IPXC_Document Doc;

// iterate
for (int zz = 0; zz< 100; zz++)
{


Doc = pxcInst.OpenDocumentFromFile("D:\\Entwicklung\\FieldsModifySample\\test.pdf", null);

PDFXEdit.IPXC_FormField _anmeldenummer = Doc.AcroForm.GetFieldByName("Anmeldenummer");


Doc.Close();


System.GC.Collect();
}
}


Do you have any ideas solving this problem?

Regards,
Michael
You do not have the required permissions to view the files attached to this post.
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Problems with pxcInst.OpenDocumentFromFile

Post by zarkogajic »

Hi Michael,

https://sdkhelp.pdf-xchange.com/view/PXV:PXV_Inst

Do not call new / Init multiple times.

-žarko
troutinger
User
Posts: 8
Joined: Tue Apr 18, 2023 9:18 am

Re: Problems with pxcInst.OpenDocumentFromFile

Post by troutinger »

Hey,

there isn't any new or init in the loop...

Thanks,
Michael
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Problems with pxcInst.OpenDocumentFromFile

Post by zarkogajic »

Hi,

But is in button click.

Anyhow, try placing the following line inside the loop:

IPXC_Document Doc;

p.s.
Not official support nor C# guy.

-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Problems with pxcInst.OpenDocumentFromFile

Post by Vasyl-Tracker Dev Team »

Hi Michael.

Please try this one:

Code: Select all

// somewhere inside the Form::Init()
m_Inst = new PXV_Inst();
m_Inst.Init(....);
.....

private void btn_test_Click(object sender, EventArgs e)
{
	IPXC_Inst pxcInst = (IPXC_Inst)m_Inst.GetExtension("PXC");
	for (int zz = 0; zz < 100; zz++)
	{
		{ // set additional scope as 'tip' for GC

			IPXC_Document Doc = pxcInst.OpenDocumentFromFile("D:\\Entwicklung\\FieldsModifySample\\test.pdf", null);

			PDFXEdit.IPXC_FormField _anmeldenummer = Doc.AcroForm.GetFieldByName("Anmeldenummer");

			Doc.Close();
                        Doc = null;
		}

		if (((zz + 1) % 5) == 0) // each 5th doc
		{
			System.GC.Collect();
			System.GC.WaitForPendingFinalizers();
		}
	}
}
PS: thanks to Zarko for the good tip...

HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.