bookmark export to text file

PDF-XChange Editor SDK for Developers

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

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.
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

bookmark export to text file

Post by jusWest »

Hello!

I'm using op.bookmarks.export, to export bookmarks now, but need to export to a textfile also.

I see the editor has a export to textfile function, is this also available in the Editor SDK?

Regards
Ronny
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: bookmark export to text file

Post by Sasha - PDF-XChange »

Hello Ronny,

For this one you should use the Bookmarks Plugin. Here's a sample on how to use the operation (I'm afraid that there is no documentation for this one as this is a plugin operation, but the sample is pretty straightforward):

Code: Select all

private void BookmarksToTextFile(PDFXEdit.IPXC_Document Doc, PDFXEdit.IPXV_Inst Inst)
{
	int nID = Inst.Str2ID("op.bookmarks.toTextFile", false);
	PDFXEdit.IOperation Op = Inst.CreateOp(nID);
	var input = Op.Params.Root["Input"];
	input.Add().v = Doc;
	PDFXEdit.ICabNode options = Op.Params.Root["Options"];
	options["FilePath"].v = "D:\\";
	options["FileName"].v = "Bookmarks.txt";
	//enum eBTTFlags //bookmarks to text file
	//{
	//	//sheet "Select Bookmarks and output params"
	//	ebttf_Default = 0x0000000,
	//	ebttf_ExportSelected = 0x0000001,
	//	ebttf_ExportCertainActType = 0x0000002,
	//	ebttf_ExportActTypesAll = 0x0000004,
	//	ebttf_ExportActType_Page = 0x0000008,
	//	ebttf_ExportActType_Launch = 0x0000010, //open document
	//	ebttf_ExportActType_GotoR = 0x0000020, //open document
	//	ebttf_ExportActType_URI = 0x0000040,
	//	ebttf_ExportActType_JS = 0x0000080,

	//	ebttf_CustomFilename = 0x0000100,
	//	ebttf_DoNotOverwriteExistingFiles = 0x0000200,
	//	ebttf_OpenContFolder = 0x0000400,
	//	ebttf_IncludeSubBookmarks = 0x0000800,

	//	ebttf_SelectBookmarksAndOutputFlags = 0x000FFFF,

	//	//sheet "Select bookmark props to export"
	//	ebttf_fDoNotExpActions = 0x0010000,
	//	ebttf_fDoNotExpPagesText = 0x0020000,
	//	ebttf_fDoNotResolveNamedDests = 0x0040000,
	//	ebttf_fUseDetailedDescr = 0x0080000,
	//	ebttf_fExpWebLinksText = 0x0100000,
	//	ebttf_fExpOpenFileText = 0x0200000,
	//	ebttf_fExpGotoRText = 0x0400000,
	//	ebttf_fExpJavascriptText = 0x0800000,
	//	ebttf_fExpTextStyleAndColor = 0x1000000,
	//	ebttf_fExpBkmrkClosedState = 0x2000000,
	//	ebttf_DoNotEscapeServiceSymbols = 0x4000000,

	//	ebttf_BookmarkExportPropsFlags = 0xFFFF0000,
	//};
	options["Flags"].v = 0x0000004 | 0x0000100;
	options["Separator"].v = ';';
	Inst.AsyncDoAndWaitForFinish(Op);
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: bookmark export to text file

Post by jusWest »

Hello!

Is there also a "op.bookmarks.fromTextFile" function in the plugin?

Would be nice to import bookmarks from text files too :)
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: bookmark export to text file

Post by jusWest »

I have tried this:

Code: Select all

                int nID = _Inst.Str2ID("op.bookmarks.fromTextFile", false);
                IOperation Op = _Inst.CreateOp(nID);
                ICabNode input = Op.Params.Root["Input"];
                input.v = _Doc;
                ICabNode options = Op.Params.Root["Options"];
                IAFS_Inst fsInst = (IAFS_Inst)_Inst.GetExtension("AFS");
                IAFS_Name impPath = fsInst.DefaultFileSys.StringToName(importFileName);
                options["ImportSource"].v = impPath;
                Op.Do();
nID gets a value, so the function seems to exist, but it dos nopt work, so maybee I have my paramters and input wrong?
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: bookmark export to text file

Post by Sasha - PDF-XChange »

Hello jusWest,

Here's a working sample for this one:

Code: Select all

private void BookmarksFromTextFile(PDFXEdit.IPXC_Document Doc, PDFXEdit.IPXV_Inst Inst)
{
	int nID = Inst.Str2ID("op.bookmarks.fromTextFile", false);
	PDFXEdit.IOperation Op = Inst.CreateOp(nID);
	var input = Op.Params.Root["Input"];
	input.v = Doc;
	PDFXEdit.ICabNode options = Op.Params.Root["Options"];
	options["FileName"].v = "D:\\Bookmarks.txt";
	options["Separator"].v = ';';
	options["ActionSeparator"].v = ',';
	Inst.AsyncDoAndWaitForFinish(Op);
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: bookmark export to text file

Post by jusWest »

Ahh, great, thank you!

Just one aditional question, given this enum:

Code: Select all

    public enum eBTTFlags //bookmarks to text file
    {
        //sheet "Select Bookmarks and output params"
        ebttf_Default = 0x0000000,
        ebttf_ExportSelected = 0x0000001,
        ebttf_ExportCertainActType = 0x0000002,
        ebttf_ExportActTypesAll = 0x0000004,
        ebttf_ExportActType_Page = 0x0000008,
        ebttf_ExportActType_Launch = 0x0000010, //open document
        ebttf_ExportActType_GotoR = 0x0000020, //open document
        ebttf_ExportActType_URI = 0x0000040,
        ebttf_ExportActType_JS = 0x0000080,

        ebttf_CustomFilename = 0x0000100,
        ebttf_DoNotOverwriteExistingFiles = 0x0000200,
        ebttf_OpenContFolder = 0x0000400,
        ebttf_IncludeSubBookmarks = 0x0000800,

        ebttf_SelectBookmarksAndOutputFlags = 0x000FFFF,

        //sheet "Select bookmark props to export"
        ebttf_fDoNotExpActions = 0x0010000,
        ebttf_fDoNotExpPagesText = 0x0020000,
        ebttf_fDoNotResolveNamedDests = 0x0040000,
        ebttf_fUseDetailedDescr = 0x0080000,
        ebttf_fExpWebLinksText = 0x0100000,
        ebttf_fExpOpenFileText = 0x0200000,
        ebttf_fExpGotoRText = 0x0400000,
        ebttf_fExpJavascriptText = 0x0800000,
        ebttf_fExpTextStyleAndColor = 0x1000000,
        ebttf_fExpBkmrkClosedState = 0x2000000,
        ebttf_DoNotEscapeServiceSymbols = 0x4000000,

        //ebttf_BookmarkExportPropsFlags = 0xFFFF0000
    };
I am trying to use thees flags to get this kind of output to the textfile:

Code: Select all

Page 1; goto:{11; XYZ; 12; 0.000; 844.000}
But I only get something like this:

Code: Select all

Page 1; 11
Which flag to use?
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: bookmark export to text file

Post by Sasha - PDF-XChange »

Hello jusWest,

Can you obtain such an output from the End-User Editor?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: bookmark export to text file

Post by jusWest »

Yes, see attached image, if this is enabled, the desired output happens
You do not have the required permissions to view the files attached to this post.
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: bookmark export to text file

Post by Sasha - PDF-XChange »

Hello jusWest,

This flag looks like what you need:
ebttf_fUseDetailedDescr

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: bookmark export to text file

Post by jusWest »

yop, that worked, thanks!
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: bookmark export to text file

Post by Sasha - PDF-XChange »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
troutinger
User
Posts: 10
Joined: Tue Apr 18, 2023 9:18 am

Re: bookmark export to text file

Post by troutinger »

Hey,

I also need to import bookmarks from a text file.

The code given above works quite well.

But if the pdf has already bookmarks, the bookmarks from the file are added.

Is there a way to overwrite existing bookmarks with the bookmarks from the text file?


Regards,
Michael
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19930
Joined: Mon Jan 12, 2009 8:07 am

Re: bookmark export to text file

Post by Stefan - PDF-XChange »

Hello Michael,

If you do not want to keep any bookmarks in your tarket file - just "remove any existing" before importing your new ones:
https://sdkhelp.pdf-xchange.com/view/PX ... rks_delete
(There is a snippet of sample code on the above page as well.)

Kind regards,
Stefan
troutinger
User
Posts: 10
Joined: Tue Apr 18, 2023 9:18 am

Re: bookmark export to text file

Post by troutinger »

Thanks a lot!

I have the following Doc:

PDFXEdit.IPXC_Document Doc = m_pxcInst.OpenDocumentFromFile(source_, null);

This Doc does not have the CoreDoc method. Running the delete operation leads only to one bookmark less but does not kill all at once.

Can I do it like this:

IPXC_Bookmark bkm = Doc.BookmarkRoot;
uint g = bkm.ChildrenCount;

if (g > 0)
{
for (uint u = 0; u < g; u++)
{
bkm.LastChild.Unlink();
}
}


Kind regards,
Michael
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3602
Joined: Thu Jul 08, 2004 10:36 pm

Re: bookmark export to text file

Post by Ivan - Tracker Software »

Yes, you can do that. For sure there will be no undo in this case.
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.