This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Combining PDF files

Dear Community Members, 

I have one question regarding the PDF combination in M-Files. I would like to combine 2 or 3 PDF files from the same class and make it one PDF file in M-Files. Is there any possibilities for doing that? Thank you. 

Best regards, 

Baigal

Parents
  • I'm having a very simple Solution in mind (right click -> combine) but I need help downloading the selected files and reuploading the combined PDF via JS.. If someone could offer me a little help..

    Currently I'm trying to combine the files without downloading but having problems with special characters in file names as the PDF library I'm using for combine (PDFTK) has problems with certain characters.. But I already wrote to the dev if he can fix it.. If this would work than we just need the code for reuploading the output doc and boom Slight smile Another variant would be to direct the output straight to a monitored folder so M-Files pulls the file..

Reply
  • I'm having a very simple Solution in mind (right click -> combine) but I need help downloading the selected files and reuploading the combined PDF via JS.. If someone could offer me a little help..

    Currently I'm trying to combine the files without downloading but having problems with special characters in file names as the PDF library I'm using for combine (PDFTK) has problems with certain characters.. But I already wrote to the dev if he can fix it.. If this would work than we just need the code for reuploading the output doc and boom Slight smile Another variant would be to direct the output straight to a monitored folder so M-Files pulls the file..

Children
  • Combining is an easy task, here's an example for a custom command button with Foxit Quick PDF Library, unfortunately this is paid software but I'm still looking for a free solution.. There are hundrets of PDF Functions you can call this way..

    The first quote is the part for combining the pdf, second is the full code.. You have to enter a Serial Number (can also be a trial) to make it work.. I have an older Version of this PDF Library I think it is called Foxit SDK now..

    			if( command == commandShow1 ) {
    				var Vault = shellFrame.ShellUI.Vault;
    				var QP = new ActiveXObject("DebenuPDFLibrary64AX1811.PDFLibrary");
    				if (QP.UnlockKey("ENTER YOUR UNLOCK KEY HERE") == 1)
    				{
    				var selectedItems = shellFrame.ActiveListing.CurrentSelection;
    				for (var i = 1; i <= selectedItems.ObjectVersions.Count; i++) {
    					var objectversion = selectedItems.ObjectVersions.Item( i );
    					var selectedpath = Vault.ObjectFileOperations.GetPathInDefaultView( objectversion.ObjVer.ObjID, -1, -1, -1 );
    					QP.AddToFileList("FilesToMerge", selectedpath);
    				}
    				QP.MergeFileList("FilesToMerge", "E:\merged_file_list.pdf");
    				}
    			}

    "use strict";
    
    function OnNewShellUI( shellUI ) {
    	/// <summary>The entry point of ShellUI module.</summary>
    	/// <param name="shellUI" type="MFiles.ShellUI">The new shell UI object.</param>
    
    	// Register to listen new shell frame creation event.
    	shellUI.Events.Register( Event_NewNormalShellFrame, newShellFrameHandler );
    }
    
    function newShellFrameHandler( shellFrame ) {
    	/// <summary>Handles the OnNewShellFrame event.</summary>
    	/// <param name="shellFrame" type="MFiles.ShellFrame">The new shell frame object.</param>
    
    	// Register to listen the started event.
    	shellFrame.Events.Register( Event_Started, getShellFrameStartedHandler( shellFrame ) );
    }
    
    function getShellFrameStartedHandler( shellFrame ) {
    	/// <summary>Gets a function to handle the Started event for shell frame.</summary>
    	/// <param name="shellFrame" type="MFiles.ShellFrame">The current shell frame object.</param>
    	/// <returns type="MFiles.Events.OnStarted">The event handler.</returns>
    
    	// Return the handler function for Started event.
    	return function() {
    	
    		// Shell frame object is now started.
    		
    		// Create a command group
    		// ref: www.m-files.com/.../index.html
    		var commandGroupId = shellFrame.TaskPane.CreateGroup( "PDF", 100 );
    		
    		// Create some commands.
    		var commandShow1 = shellFrame.Commands.CreateCustomCommand( "Combine PDF" );
    
    		// Set command icons.
    		shellFrame.Commands.SetIconFromPath( commandShow1, "png/pdf.ico" );
    		
    		// Add a command to the context menu.
    		shellFrame.Commands.AddCustomCommandToMenu( commandShow1, MenuLocation_ContextMenu_Bottom, 0 );
    		
    		// Add a commands to the task pane.
    		shellFrame.TaskPane.AddCustomCommandToGroup( commandShow1, commandGroupId, 1 );
    		
    		// Hide the command.
    		shellFrame.Commands.SetCommandState( commandShow1, CommandLocation_All, CommandState_Hidden );
    		
    		// Register to listen to when new shell listings are created.
    		shellFrame.Events.Register(
    			Event_NewShellListing,
    			getNewShellListingHandler( shellFrame, commandShow1 ) );
    
    		// Is there already a listing?  If so then we need to hook into it as well.
    		if (null != shellFrame.Listing)
    		{
    			getNewShellListingHandler( shellFrame, commandShow1 )( shellFrame.Listing );
    		}
    		
    		// Set the command handler function.
    		shellFrame.Commands.Events.Register( Event_CustomCommand, function( command ) {
    		
    			// Branch by command.
    			
    			if( command == commandShow1 ) {
    				var Vault = shellFrame.ShellUI.Vault;
    				var QP = new ActiveXObject("DebenuPDFLibrary64AX1811.PDFLibrary");
    				if (QP.UnlockKey("ENTER YOUR UNLOCK KEY HERE") == 1)
    				{
    				var selectedItems = shellFrame.ActiveListing.CurrentSelection;
    				for (var i = 1; i <= selectedItems.ObjectVersions.Count; i++) {
    					var objectversion = selectedItems.ObjectVersions.Item( i );
    					var selectedpath = Vault.ObjectFileOperations.GetPathInDefaultView( objectversion.ObjVer.ObjID, -1, -1, -1 );
    					QP.AddToFileList("FilesToMerge", selectedpath);
    				}
    				QP.MergeFileList("FilesToMerge", "E:\merged_file_list.pdf");
    				}
    			}
    		} );
    	};
    }
    
    function getNewShellListingHandler(shellFrame, commandId)
    {
    	/// <summary>Gets a function to handle the NewShellListing event for shell frame.</summary>
    	/// <param name="shellFrame" type="MFiles.ShellFrame">The current shell frame object.</param>
    	/// <returns type="MFiles.Events.OnNewShellListing">The event handler.</returns>
    
    	// Return the handler function for NewShellListing event.
    	return function(shellListing)
    	{
    		// Listen for selection change events on the listing.
    		shellListing.Events.Register(
    			Event_SelectionChanged,
    			function(selectedItems)
    			{
    				// Sanity.
    				if (false == shellListing.IsActive)
    				{
    					return false;
    				}
    
    				// Has the user got any object versions selected?
    			
    				if (selectedItems.ObjectVersions.Count == 0)
    				{
    					// Hide the menu item - there's nothing selected.
    					shellFrame.Commands.SetCommandState( commandId, CommandLocation_All, CommandState_Hidden );
    					return false;
    				}
    
    				//Get vault object
    				var Vault = shellFrame.ShellUI.Vault;
    
    				//Get select items
    				var selectedItems = shellFrame.ActiveListing.CurrentSelection;
    				var objectversion = selectedItems.ObjectVersions.Item( 1 );
    				var selectedpath = Vault.ObjectFileOperations.GetPathInDefaultView( objectversion.ObjVer.ObjID, -1, -1, -1 );
    				var fileext = selectedpath.split('.').pop().toUpperCase();
    
    				if (fileext == "PDF")
    				{
    					// Show the menu item.
    					shellFrame.Commands.SetCommandState( commandId, CommandLocation_All, CommandState_Active );
    					// We succeeded; return true.
    					return true;
    					} else {
    					shellFrame.Commands.SetCommandState( commandId, CommandLocation_All, CommandState_Hidden );
    					return false;
    				}
    
    			} );
    	};
    }