Meridian 2010

UniqueInputPrefix

// Copyright (c) 2017 ActivePDF, Inc.
// ActivePDF Meridian 2010
// Example generated 10/23/17 

using System;

// Make sure to add the ActivePDF product .NET DLL(s) to your application.
// .NET DLL(s) are typically found in the products 'bin' folder.

class Examples
{
  public static void Example()
  {
    string strPath;
    int intStartPrinting;
    int intWait;
    
    strPath = System.AppDomain.CurrentDomain.BaseDirectory;

    // Instantiate Object
    APMeridian.Meridian oMER = new APMeridian.Meridian();
    
    // Specify the IP address and Port to use to reach the Meridian Server
    oMER.StartRemoteClient("192.168.1.100", 54545);
    
    // Must use either SetUniuqeInput or SetProcessAndThread
    // Call SetUniqueInput with the full path to the input
    // it is best to use a unique filename to avoid potential
    // name collisions, if the filename is unique set the second
    // parameter to true
    oMER.SetUniqueInput(strPath + "Word.doc", true);
    
    // Here we are using SetUniqueInput, as the print job is
    // from Microsoft Word, Word will add 'Microsoft Word - '
    // to the print job so we need to let meridian know using
    // UniqueInputPrefix
    oMER.UniqueInputPrefix = "Microsoft Word - ";
    
    // Path and filename of the created PDF
    oMER.OutputDirectory = strPath;
    oMER.NewDocumentName = "Word.pdf";
    
    // Set the ModelPrinter to the remote Meridian printer
    // This printer must be added locally to the remote system
    oMER.ModelPrinter = "\\\\192.168.1.100\\Meridian";
    
    // Prepare to start the printing process
    intStartPrinting = oMER.StartPrinting();
    if (intStartPrinting != 0)
    {
      ErrorHandler("StartPrinting", intStartPrinting);
    }
    
    // Automate Word to print a document to Meridian
    // NOTE: You must add the 'Microsoft.Office.Interop.Word' reference
    Microsoft.Office.Interop.Word._Application oWORD = new Microsoft.Office.Interop.Word.Application();
    oWORD.ActivePrinter = oMER.ModelPrinter;
    oWORD.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
    oWORD.Visible = false;
    Microsoft.Office.Interop.Word.Document oDOC = oWORD.Documents.Open(strPath + "Word.doc");
    oDOC.Activate();
    oWORD.PrintOut();
    oWORD.Documents.Close();
    oWORD.Quit();
    oDOC = null;
    oWORD = null;
    
    // End the printing process
    oMER.StopPrinting();
    
    // Wait(seconds) for job to complete
    intWait = oMER.Wait(30);
    if (intWait != 0)
    {
      ErrorHandler("Wait", intWait);
    }
    
    // Release Object
    oMER = null;
    
    // Process Complete
    WriteResults("Done!");
  }
  
  // Error Handling
  public static void ErrorHandler(string strMethod, object rtnCode)
  {
    WriteResults(strMethod + " error:  " + rtnCode.ToString());
  }
  
  // Write output data
  public static void WriteResults(string content)
  {
    // Choose where to write out results
  
    // Debug output
    //System.Diagnostics.Debug.WriteLine("ActivePDF: * " + content);
  
    // Console
    Console.WriteLine(content);
  
    // Log file
    //using (System.IO.TextWriter writer = new System.IO.StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + "application.log", true))
    //{
    //    writer.WriteLine("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "]: => " + content);
    //}
  }
}

Copyright © 2017 ActivePDF, Inc