Create PDF from search result

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
IronJosie
User
Posts: 4
Joined: Fri Apr 09, 2021 8:00 am

Create PDF from search result

Post by IronJosie »

Hello,

is it possible to create a PDF document containing the pages found during a search?

Thank you and best regards
Josefine
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Create PDF from search result

Post by Vasyl-Tracker Dev Team »

Hi Josefine.

Yes, it is possible, but not in just 'one click':
1. Search something.
2. Run the SearchPane/Options/AnnotateSearchResult/Highlight
3. Press Ctrl+J to show the JavaScript console, paste here the following script:

Code: Select all

var src = this;
var dst = app.newDoc();
var pagesCnt = src.numPages;

var start = -1;
var end = -1;
for (var i = 0; i < pagesCnt; i++)
{
	var annots = src.getAnnots(i);
	var hasEntries = false;
	if ((annots != null) && (annots.length != 0) && (annots[annots.length - 1].type == "Highlight"))
		hasEntries = true;
	if (start >= 0)
	{
		if (!hasEntries || ((end + 1) < i))
		{
			dst.insertPages ({
				nPage: dst.numPages - 1,
				cPath: src.path,
				nStart: start,
				nEnd: end,
			});

			start = -1;
		}
	}

	if (hasEntries)
	{
		if (start < 0)	
			start = i;
		end = i;
	}
}

if (start >= 0)
{
	dst.insertPages ({
		nPage: dst.numPages - 1,
		cPath: src.path,
		nStart: start,
		nEnd: end,
	});
}

dst.deletePages({nStart: 0, nEnd: 0});
- and run it. It will create a new document tab with extracted pages.

Important: before running that script be sure that your now annotated source document is active (tab is active).
Tip: if you want to have extracted pages highlighted(annotated) too - save the annotated source document before running the script.
Note: that script may work incorrectly for you when your original document already had the some highlights before your search&annotate.

In the future we may add the simple feature to extract pages with found entries...

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.
IronJosie
User
Posts: 4
Joined: Fri Apr 09, 2021 8:00 am

Re: Create PDF from search result

Post by IronJosie »

Yeah, that is really awseone - thank you for the fast reply.

The reason I want that solution is to extract pages with a certain date on them. Currently I searching for all possible dates using "any of these words": 2021/04/21 2021/04/20 etc.
I haven't found a option to use a wildcard search - is that correct?
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Create PDF from search result

Post by Vasyl-Tracker Dev Team »

I haven't found a option to use a wildcard search - is that correct?
Correct, unfortunately. This feature will be added in the future (support of regexp-s).
At the moment for your case you may try to find all text fragments that contain "/2021" OR "2021/" OR "2021-" OR "-2021".
I.e the AnyOfTheseWords field may contain:

"/2021" "2021/" "2021-" "-2021"

And sure, search it with turned off the WholeWords option..
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.
Post Reply