The GetDocumentTitle method returns the title of the document that is currently being printed. This function should be called in the message handling loop and will return invalid results as soon as the document finishes printing.
BSTR GetDocumentTitle(long JobID)
void GetDocumentTitle(HANDLE hPrinter, long JobID, LPSTR buf, long MaxBuf)
JobID
Job ID as retrieved by the PDF message handling function.
hPrinter
Handle to printer returned by any of the DriverInit function calls.
Buf
[out] Address of buffer that will contain the document title.
MaxBuf
This is the Size of the Buf buffer. The document title will be truncated if it is larger than the input buffer.
This method returns the title of the document that is currently being printed.
This function should be called from a PDF message handling function before the EndDocPost message is sent.
<Flags()> Public Enum acFileNameOptions As Integer ' Please check FileNameOptions for the complete flags version NoPrompt = &H1 UseFileName = &H2 Concatenate = &H4 DisableCompression = &H8 EmbedFonts = &H10 BroadcastMessages = &H20 PrintWatermark = &H40 End Enum ' Define the ActiveX PDF Object Friend WithEvents PDF1 As New AxCDIntfEx.AxCDIntfEx Public Sub ActiveXEventHandling() ' Define parent form to the ActiveX Objet PDF1.Parent = Me ' Constants for Activation codes Const strLicenseTo As String = "Amyuni PDF Converter Evaluation" Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA" Const AMYUNIPRINTERNAME As String = "Amyuni PDF Converter" ' Get a reference to the installed printer. ' This will fail if the printer name passed to the DriverInit method is ' not found in the printer’s folder PDF1.DriverInit(AMYUNIPRINTERNAME) ' Start Capture of Events PDF1.CaptureEvents(True) ' The SetDefaultPrinter function sets the system default printer to the one ' initialized by the DriverInit functions. PDF1.SetDefaultPrinter() ' The EnablePrinter()method needs to be called right before each print job. ' and before the configuration ' Calling the EnablePrinter()method will start a 20 second time-out value PDF1.EnablePrinter(strLicenseTo, strActivationCode) ' Resulting PDF document stored here PDF1.DefaultDirectory = "C:\Temp" ' Set Printer options, it needs to have BroadcastMessages option PDF1.FileNameOptionsEx = acFileNameOptions.NoPrompt Or acFileNameOptions.BroadcastMessages ' The BatchConvert method converts a number of files to PDF. PDF1.BatchConvert("C:\Temp\*.docx") ' The RestoreDefaultPrinter function resets the system default printer ' to the printer that was the default before the call to SetDefaultPrinter. PDF1.RestoreDefaultPrinter() ' Stop Capture of Events PDF1.CaptureEvents(False) ' Close Printer PDF1.DriverEnd() ' Destroy PDF object PDF = Nothing End Sub Public Sub PDF1_StartDocPre(sender As Object, e As EventArgs) Handles PDF1.StartDocPre Dim filename As String = sender.GetGeneratedFilename() MsgBox("Starting Document Preprocess" & Environment.NewLine & "Filename= " & filename) End Sub Public Sub PDF1_StartDocPost(sender As Object, e As AxCDIntfEx._DCDIntfEvents_StartDocPostEvent) Handles PDF1.StartDocPost Dim title As String = sender.GetDocumentTitle(e.jobID) MsgBox("Starting Document Postprocess" & Environment.NewLine & "Title= " & title) End Sub Public Sub PDF1_EndDocPre(sender As Object, e As AxCDIntfEx._DCDIntfEvents_EndDocPreEvent) Handles PDF1.EndDocPre Dim title As String = sender.GetDocumentTitle(e.jobID) MsgBox("Ending Document Preprocess" & Environment.NewLine & "Title= " & title) End Sub Public Sub PDF1_EndDocPost(sender As Object, e As AxCDIntfEx._DCDIntfEvents_EndDocPostEvent) Handles PDF1.EndDocPost MsgBox("Ending Document Postprocess") End Sub Public Sub PDF1_StartPage(sender As Object, e As AxCDIntfEx._DCDIntfEvents_StartPageEvent) Handles PDF1.StartPage Dim title As String = sender.GetDocumentTitle(e.jobID) MsgBox("Starting Page" & Environment.NewLine & "Title= " & title) End Sub Public Sub PDF1_EndPage(sender As Object, e As AxCDIntfEx._DCDIntfEvents_EndPageEvent) Handles PDF1.EndPage Dim title As String = sender.GetDocumentTitle(e.jobID) MsgBox("Ending Page" & Environment.NewLine & "Title= " & title) End Sub Public Sub PDF1_EnabledPre(sender As Object, e As EventArgs) Handles PDF1.EnabledPre MsgBox("Enabling Printer") End Sub
[Flags] public enum acFileNameOptions { NoPrompt = 0x00000001, UseFileName = 0x00000002, Concatenate = 0x00000004, DisableCompression = 0x00000008, EmbedFonts = 0x00000010, BroadcastMessages = 0x00000020, PrintWatermark = 0x00000040, } // Define the ActiveX PDF Object public AxCDIntfEx.AxCDIntfEx PDF1; public void ActiveXEventHandling() { // Define ActiveX Objet this.PDF1 = new AxCDIntfEx.AxCDIntfEx(); ((System.ComponentModel.ISupportInitialize)(this.PDF1)).BeginInit(); this.PDF1.StartDocPre += new System.EventHandler(this.StartDocPre); this.PDF1.StartDocPost += new AxCDIntfEx._DCDIntfEvents_StartDocPostEventHandler(this.StartDocPost); this.PDF1.EndDocPre += new AxCDIntfEx._DCDIntfEvents_EndDocPreEventHandler(this.EndDocPre); this.PDF1.EndDocPost += new AxCDIntfEx._DCDIntfEvents_EndDocPostEventHandler(this.EndDocPost); this.PDF1.StartPage += new AxCDIntfEx._DCDIntfEvents_StartPageEventHandler(this.StartPage); this.PDF1.EndPage += new AxCDIntfEx._DCDIntfEvents_EndPageEventHandler(this.EndPage); this.PDF1.EnabledPre += new System.EventHandler(this.EnabledPre); this.Controls.Add(this.PDF1); ((System.ComponentModel.ISupportInitialize)(this.PDF1)).EndInit(); // Constants for Activation codes const string strLicenseTo = "Amyuni PDF Converter Evaluation"; const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"; const string AMYUNIPRINTERNAME = "Amyuni PDF Converter"; // Get a reference to the installed printer. // This will fail if the printer name passed to the DriverInit method is // not found in the printer’s folder PDF1.DriverInit(AMYUNIPRINTERNAME); // Start Capture of Events PDF1.CaptureEvents(Convert.ToSByte(true)); // The SetDefaultPrinter function sets the system default printer to the one // initialized by the DriverInit functions. PDF1.SetDefaultPrinter(); // The EnablePrinter()method needs to be called right before each print job. // and before the configuration // Calling the EnablePrinter()method will start a 20 second time-out value PDF1.EnablePrinter(strLicenseTo, strActivationCode); // Resulting PDF document stored here PDF1.DefaultDirectory = "c:\\Temp"; // Set Printer options, it needs to have BroadcastMessages option PDF1.FileNameOptionsEx = (int)(acFileNameOptions.NoPrompt | acFileNameOptions.BroadcastMessages); // The BatchConvert method converts a number of files to PDF. PDF1.BatchConvert("c:\\Temp\\*.docx"); // The RestoreDefaultPrinter function resets the system default printer // to the printer that was the default before the call to SetDefaultPrinter. PDF1.RestoreDefaultPrinter(); // Stop Capture of Events PDF1.CaptureEvents(Convert.ToSByte(false)); // Close Printer PDF1.DriverEnd(); } public void StartDocPre(object sender, EventArgs e) { String filename = PDF1.GetGeneratedFilename(); MessageBox.Show("Starting Document Preprocess" + Environment.NewLine + "Filename= " + filename); } public void StartDocPost(object sender, AxCDIntfEx._DCDIntfEvents_StartDocPostEvent e) { String title = PDF1.GetDocumentTitle(e.jobID); MessageBox.Show("Starting Document Postprocess" + Environment.NewLine + "Title= " + title); } public void EndDocPre(object sender, AxCDIntfEx._DCDIntfEvents_EndDocPreEvent e) { String title = PDF1.GetDocumentTitle(e.jobID); MessageBox.Show("Ending Document Preprocess" + Environment.NewLine + "Title= " + title); } public void EndDocPost(object sender, AxCDIntfEx._DCDIntfEvents_EndDocPostEvent e) { MessageBox.Show("Ending Document Postprocess"); } public void StartPage(object sender, AxCDIntfEx._DCDIntfEvents_StartPageEvent e) { String title = PDF1.GetDocumentTitle(e.jobID); MessageBox.Show("Starting Page" + Environment.NewLine + "Title= " + title); } public void EndPage(object sender, AxCDIntfEx._DCDIntfEvents_EndPageEvent e) { String title = PDF1.GetDocumentTitle(e.jobID); MessageBox.Show("Ending Page" + Environment.NewLine + "Title= " + title); } public void EnabledPre(object sender, EventArgs e) { MessageBox.Show("Enabling Printer"); }