PlaceContent() runs very slow

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

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, 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: 271
Joined: Tue Jul 07, 2015 3:30 pm

PlaceContent() runs very slow

Post by whoit » Mon Jun 04, 2018 5:00 pm

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?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Mon Jun 04, 2018 6:22 pm

Hello Wayne,

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

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Mon Jun 04, 2018 6:32 pm

So how would I handle 568 text boxes?

Would I make 568 contentCreator.ShowTextBlock() calls, and then a single PlaceContent() ?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Tue Jun 05, 2018 5:24 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Tue Jun 05, 2018 1:17 pm

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);

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Tue Jun 05, 2018 1:43 pm

Hello Wayne,

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

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Tue Jun 05, 2018 1:50 pm

Ok, I've just sent samples to support....

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Tue Jun 05, 2018 1:54 pm

Hello Wayne,

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

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Tue Jun 05, 2018 2:01 pm

So the basic code I posted would be correct?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Tue Jun 05, 2018 2:04 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Tue Jun 05, 2018 2:34 pm

OK, I will send via email my test app and sample file.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Wed Jun 06, 2018 6:18 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Wed Jun 06, 2018 1:03 pm

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Wed Jun 06, 2018 1:39 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Wed Jun 06, 2018 1:46 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Wed Jun 06, 2018 1:58 pm

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:

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Wed Jun 06, 2018 2:05 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Wed Jun 06, 2018 2:18 pm

True, but you could also document the usage (example?) ....you'd probably get a lot fewer questions!

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Wed Jun 06, 2018 2:19 pm

That's also true ;)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

whoit
User
Posts: 271
Joined: Tue Jul 07, 2015 3:30 pm

Re: PlaceContent() runs very slow

Post by whoit » Wed Jun 06, 2018 2:23 pm

Or, you could keep communicating with me several times a month! :shock:

User avatar
Sasha - Tracker Dev Team
User
Posts: 4076
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PlaceContent() runs very slow

Post by Sasha - Tracker Dev Team » Wed Jun 06, 2018 2:26 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply