PlaceContent() runs very slow

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
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

PlaceContent() runs very slow

Post by whoit »

Hi -
I'm trying to take an existing PDF that has a lot of Text Comments, and make them searchable.
I'm reading each text comment, then creating a TextBlock to represent it, including position, etc.

My code is working fine, however, it is painfully slow.
It takes 2+ minutes to process a single page with 568 comments.

I've tested the same process by reusing my code with a competing library and it processes in under 2 seconds.

When I analyze my code performance in Visual Studio, the slowdown occurs with this statement which takes over 85%
of the code processing time:

Code: Select all

myPage.PlaceContent(contentCreator.Detach(), (UInt32)PXC_PlaceContentFlags.PlaceContent_After);
Why is this so slow?
How can I speed this up?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Well you should call this method only once for each page - this will be optimal.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

So how would I handle 568 text boxes?

Would I make 568 contentCreator.ShowTextBlock() calls, and then a single PlaceContent() ?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Of course, that would be the correct code usage - using PlaceContent each time, you are making the 568 times work that you need and of course the time for this would grow.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

OK, I've tried this and I'm only getting some of the expected TextBlocks (3 out of 20).

What is wrong?

Code: Select all

IPXC_ContentCreator contentCreator = pDoc.CreateContentCreator();
contentCreator.SetTextRenderMode(PXC_TextRenderingMode.TRM_Fill);
IColor txtColor = auxInst.CreateColor(ColorType.ColorType_RGB);
txtColor.Value = "#FF0000";
IColor oColor = auxInst.CreateColor(ColorType.ColorType_RGB);
oColor.Value = "#FFFFFF";

uint nFlags = (uint)PXC_DrawTextFlags.DTF_NoWordWrap;
int nTextLen = -1;
IPXC_CharFormat pCharFmt = null;
IPXC_ParaFormat pParaFmt = null;
IPXC_DrawTextCallbacks pCallbacks = null;
PXC_Rect pTextBounds; //will hold returned size of textblock
	pTextBounds.left = 0.0;
	pTextBounds.right = 0.0;
	pTextBounds.top = 0.0;
	pTextBounds.bottom = 0.0;
PXC_Rect annRect;
	annRect.left = 0.0;
	annRect.right = 0.0;
	annRect.top = 0.0;
	annRect.bottom = 0.0;
string curText = string.Empty;

for (int i = 0; i < 20; i++) {
	contentCreator.SetColor(txtColor, oColor);
	contentCreator.SetFontSize(6.0);
	curText = tmpData[i].ToString();
	// set annrect position values here - code not included for brevity
	contentCreator.ShowTextBlock(curText, annRect, annRect, nFlags, nTextLen, pCharFmt, pParaFmt, pCallbacks, out pTextBounds);
}
inPage.PlaceContent(contentCreator.Detach(), (UInt32)PXC_PlaceContentFlags.PlaceContent_After);
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Can you give us two sample files before and after the insertion?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

Ok, I've just sent samples to support....
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Will take a look at those when they get to me.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

So the basic code I posted would be correct?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Well it looks OK, but again we don't know the coordinates and don't have a fully working sample that recreates the issue (and we will probably need that one to investigate the problem).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

OK, I will send via email my test app and sample file.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

As for your files - the problem is with positioning. Open the Content Panel and Page 1 item and scroll to bottom - you will see your 20 text Content Items. Zoom to 6% or so and try selecting them - you will see that majority of them are way off the page.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

Hi Alex -

The positioning is fine when using PlaceContent() for each time through the loop.

So, is the positioning cumulative each time I use ShowTextBlock() ?

Have you checked my emailed sample code?

Thanks

P.S. I've tried zooming out in Acrobat Pro and X-Change Editor and I see nothing beyond the page edges after ctrl-a
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Not Ctrl+A:
Open the Content Panel and Page 1 item and scroll to bottom - you will see your 20 text Content Items. Zoom to 6% or so and try selecting them - you will see that majority of them are way off the page.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

As for your problem - I've found the case - you are changing the Content Creator each time you loop through (in your case you are rotating the matrix each time). You will have to do that before the cycle or do SaveState() before changing style and RestoreState() after the ShowTextBlock().

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

HI Alex -

Ok, that seems to have resolved the issue and it is now running significantly faster (0.44 sec instead of 2.5 min)

Thanks again,
Wayne

P.S. It would be nice if things like SaveState() and RestoreState() were documented! :wink:
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Well even if they were documented, you would not use them because you would have to understand the basic logic. Each time, you change something in the ContentCreator, it applies to all of the next Show/Draw methods. So the basic logic here would be not to "dirty" the ContentCreator before the next usage - this is being done with these two methods. Though even if there were no such methods, this would be also doable by remembering the last Matrix rotation, setting it with the new value and restoring it after the usage.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

True, but you could also document the usage (example?) ....you'd probably get a lot fewer questions!
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

That's also true ;)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit »

Or, you could keep communicating with me several times a month! :shock:
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply