Skip to content

Instantly share code, notes, and snippets.

@Polaringu
Last active August 27, 2020 17:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Polaringu/76323564c9948b2e0b5f5b4d60010a39 to your computer and use it in GitHub Desktop.
Save Polaringu/76323564c9948b2e0b5f5b4d60010a39 to your computer and use it in GitHub Desktop.
private void AutoGenerateBookmarksFromText(PDFXEdit.IPXC_Document Doc, PDFXEdit.IPXV_Inst Inst)
{
int nID = Inst.Str2ID("op.bookmarks.autoGenerateFromText", false);
PDFXEdit.IOperation Op = Inst.CreateOp(nID);
var input = Op.Params.Root["Input"];
input.v = Doc;
PDFXEdit.ICabNode options = Op.Params.Root["Options"];
options["PagesRange.Type"].v = 1; //All
//enum eAGBFlags
//{
// eagb_None = 0x00,
// eagb_StopWords = 0x01,
// eagb_IgnoreDulpicates = 0x02,
//};
options["Flags"].v = 2; //eAGBFlags
PDFXEdit.ICabNode stopWords = options["StopWordsData"];
//enum eStopWordsFlags
//{
// eswf_None = 0x00,
// eswf_MatchCase = 0x01,
// eswf_MatchWords = 0x02,
// eswf_UseRegexp = 0x04,
//};
stopWords["StopWordsFlags"].v = 1; //eswf_MatchCase
stopWords["StopWords"].Add().v = "Word";
PDFXEdit.ICabNode level = options["Levels"].Add();
level["Index"].v = 1;
//enum eTreeItemFlags
//{
// etif_None = 0x000000,
// //Level Description
// etif_FontSize = 0x000001,
// etif_FontColor = 0x000002,
// etif_FontName = 0x000004,
// etif_MatchTextPattern = 0x000008,
// etif_LevelDescFlags = 0x0000FF,
// //Text Content Rules
// etif_MultilineTitles = 0x000100,
// etif_MatchTextCase = 0x000400, //Used with pattern only
// etif_LimitToPatternMatch = 0x000800, //Used with pattern only
// etif_ContentRulesFlags = 0x00FF00,
//};
level["Flags"].v = 0x000001 | 0x000100; //eTreeItemFlags
PDFXEdit.ICabNode levelDesc = level["LevelDescription"];
levelDesc["FontSize"].v = 10.0;
levelDesc["FontTolerance"].v = 0.2;
PDFXEdit.ICabNode appearance = level["Appearance"];
appearance["Color"].v = "rgbd(1,0,0)";
appearance["Style"].v = 0; //PXC_BookmarkStyle
appearance["DestFlags"].v = (/*1 | 2 | */4 | 8);
appearance["DestType"].v = 0; //PXC_DestType
PDFXEdit.ICabNode formatting = level["Formatting"];
//enum eTitleCase
//{
// etc_DoNotChange = 0,
// etc_SentenceCase = 1,
// etc_UpperCase = 2,
// etc_LowerCase = 3,
// etc_TitleCase = 4,
//};
formatting["TextCase"].v = 0; //eTitleCase
formatting["Prefix"].v = "BM_";
//enum eLeadingNumbers
//{
// eln_NoChange = 0,
// eln_Add = 1,
// eln_Remove = 2,
//};
formatting["LeadingNum"].v = 1; //eLeadingNumbers
//enum eLeadingNumberType
//{
// elnt_Numbers = 0,
// elnt_Letters = 1,
// elnt_RomanLetters = 2,
//};
formatting["NumType"].v = 1; //eLeadingNumberType
//enum eTitleFormattingFlags
//{
// etff_None = 0x00,
// etff_Prefix = 0x01,
// etff_Suffix = 0x02,
// etff_RemoveDupSpaces = 0x04,
// etff_UseRegex = 0x08,
// etff_MatchTextCase = 0x10,
// etff_ReplaceLBWithSpaces = 0x20,
//};
formatting["Flags"].v = 0x01; //eTitleFormattingFlags
Inst.AsyncDoAndWaitForFinish(Op);
}
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);
}
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);
}
private void BookmarksToTOC(PDFXEdit.IPXC_Document Doc, PDFXEdit.IPXV_Inst Inst)
{
int nID = Inst.Str2ID("op.bookmarks.toTOC", false);
PDFXEdit.IOperation Op = Inst.CreateOp(nID);
var input = Op.Params.Root["Input"];
input.Add().v = Doc;
PDFXEdit.ICabNode options = Op.Params.Root["Options"];
//enum eTOCFlags
//{
// etoc_Default = 0x000000,
// etoc_UseLastPage = 0x000001,
// etoc_SkipInvalidBookmarks = 0x000002,
// etoc_UseAllBookmarkLevels = 0x000004,
// etoc_AddHyperlinksToTOC = 0x000008,
// etoc_PNAsPageLabels = 0x000010,
// etoc_PNAsBatesNumbers = 0x000020,
// etoc_StyleUnderline = 0x000100,
// etoc_StyleSpaces = 0x000200,
// etoc_TrimSpaces = 0x000400,
// etoc_UseCustomSeparatorStyle = 0x001000,
// etoc_UseCustomNumberStyle = 0x002000,
//};
options["Flags"].v = 0x000002;
options["Title"].v = "My Table of Contents";
options["PageNumber"].v = 1;
options["Margins.top"].v = 50;
options["Margins.bottom"].v = 50;
options["Margins.left"].v = 50;
options["Margins.right"].v = 50;
options["StartingLevel"].v = 1;
options["EndingLevel"].v = 2;
//Page Properties
options["PaperType"].v = 1;
options["Landscape"].v = false;
options["StdPaperIndex"].v = -1;
options["Width"].v = 595.3;
options["Height"].v = 841.9;
//Levels
PDFXEdit.ICabNode title = options["Levels"].Add();
title["Index"].v = 0;
title["Indent"].v = 0;
//Font Params
title["Name"].v = "Arial-BoldMT";
title["Size"].v = 16.0;
title["Underline"].v = 0;
title["StrikeOut"].v = 0;
title["FColor"].v = "rgbd(0,0,0)";
title["SColor"].v = "N";
title["StrokeWidth"].v = 0.0;
title["HScale"].v = 100.0;
title["TextRise"].v = 0.0;
PDFXEdit.ICabNode firstLevel = options["Levels"].Add();
firstLevel["Index"].v = 1;
firstLevel["Indent"].v = 0;
//Font Params
firstLevel["Name"].v = "Arial-BoldMT";
firstLevel["Size"].v = 12.0;
firstLevel["Underline"].v = 0;
firstLevel["StrikeOut"].v = 0;
firstLevel["FColor"].v = "rgbd(0,0,0)";
firstLevel["SColor"].v = "N";
firstLevel["StrokeWidth"].v = 0.0;
firstLevel["HScale"].v = 100.0;
firstLevel["TextRise"].v = 0.0;
PDFXEdit.ICabNode secondLevel = options["Levels"].Add();
secondLevel["Index"].v = 2;
secondLevel["Indent"].v = 36;
//Font Params
secondLevel["Name"].v = "Arial-BoldMT";
secondLevel["Size"].v = 10.0;
secondLevel["Underline"].v = 0;
secondLevel["StrikeOut"].v = 0;
secondLevel["FColor"].v = "rgbd(0,0,0)";
secondLevel["SColor"].v = "N";
secondLevel["StrokeWidth"].v = 0.0;
secondLevel["HScale"].v = 100.0;
secondLevel["TextRise"].v = 0.0;
Inst.AsyncDoAndWaitForFinish(Op);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment