The event PrintPageEvent is fired before each page is printed; this allows the calling application to:
Display the printing progress.
Cancel printing on error, user action.
Print only a specified range of pages.
Change the printer’s input bin or duplex mode.
The PrintPageEvent event is NOT fired when doing page by page printing. For instance, using the StartPrint, PrintPage or EndPrint Methods.
This is because the code is already in exact control of the printing process.
pageNumber
PageNumber is the one based index of the page to be printed.
continue
Set this parameter to 0 to skip, 1 to print, -1 to cancel.
Public Class Form1 Friend WithEvents AxPDFCreactiveX1 As AxACPDFCREACTIVEX.AxPDFCreactiveX = New AxACPDFCREACTIVEX.AxPDFCreactiveX() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Size = New System.Drawing.Size(400, 500) ' AxPDFCreactiveX1 AxPDFCreactiveX1.Enabled = True AxPDFCreactiveX1.Location = New System.Drawing.Point(20, 20) AxPDFCreactiveX1.Name = "AxPDFCreactiveX1" AxPDFCreactiveX1.Parent = Me AxPDFCreactiveX1.Size = New System.Drawing.Size(360, 400) AxPDFCreactiveX1.TabIndex = 0 ' Constants for Activation codes Const strLicenseTo As String = "Amyuni PDF Creator Evaluation" Const strActivationCode As String = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC" ' Set license key AxPDFCreactiveX1.SetLicenseKey(strLicenseTo, strActivationCode) ' Create 4 additional pages For page = 2 To 5 AxPDFCreactiveX1.AddPage(page) Next ' Create object in each Page For page = 1 To 5 ' Set the current page AxPDFCreactiveX1.CurrentPage = page ' Create a Text in the current Page AxPDFCreactiveX1.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypeText, "Text" + page.ToString) Dim oText As ACPDFCREACTIVEX.IacObject = AxPDFCreactiveX1.GetObjectByName("Text" + page.ToString) oText("Left") = 1000 oText("Right") = 5000 oText("Top") = 0 oText("Bottom") = 4000 oText("BorderColor") = &HFF00FF oText("BorderWidth") = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthDouble oText("Text") = "Amyuni Technologies " + page.ToString Next ' Print all the document Dim PrinterName As String = "" ' Default printer Dim Prompt As Integer = 0 AxPDFCreactiveX1.Print(PrinterName, Prompt) End Sub Private Sub AxPDFCreactiveX1_PrintPageEvent(sender As Object, e As AxACPDFCREACTIVEX._IPDFCreactiveXEvents_PrintPageEvent) Handles AxPDFCreactiveX1.PrintPageEvent ' The following example will allow the control to save only the first 4 pages of the current document. MessageBox.Show("PrintPage event") If e.pageNumber < 5 Then e.continue = 1 Else e.continue = 0 End If End Sub End Class
public partial class Form1 : Form { AxACPDFCREACTIVEX.AxPDFCreactiveX axPDFCreactiveX1 = new AxACPDFCREACTIVEX.AxPDFCreactiveX(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Size = new System.Drawing.Size(400, 500); // axPDFCreactiveX1 axPDFCreactiveX1.Enabled = true; axPDFCreactiveX1.Location = new System.Drawing.Point(20, 20); axPDFCreactiveX1.Name = "axPDFCreactiveX1"; axPDFCreactiveX1.Parent = this; axPDFCreactiveX1.Size = new System.Drawing.Size(360, 400); axPDFCreactiveX1.TabIndex = 0; // Events axPDFCreactiveX1.PrintPageEvent += new AxACPDFCREACTIVEX._IPDFCreactiveXEvents_PrintPageEventHandler(axPDFCreactiveX1_PrintPageEvent); // Constants for Activation codes const string strLicenseTo = "Amyuni PDF Creator Evaluation"; const string strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"; // Set license key axPDFCreactiveX1.SetLicenseKey(strLicenseTo, strActivationCode); // Create 4 additional pages for (int page = 2; page < 6; page++) { axPDFCreactiveX1.AddPage(page); } // Create object in each Page for (int page = 1; page < 6; page++) { // Set the current page axPDFCreactiveX1.CurrentPage = page; // Create a Text in the current Page axPDFCreactiveX1.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypeText, "Text" + page.ToString()); ACPDFCREACTIVEX.IacObject oText = axPDFCreactiveX1.GetObjectByName("Text" + page.ToString()); oText["Left"] = 1000; oText["Right"] = 5000; oText["Top"] = 0; oText["Bottom"] = 4000; oText["BorderColor"] = 0xFF00FF; oText["BorderWidth"] = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthDouble; oText["Text"] = "Amyuni Technologies " + page.ToString(); } // Print all the document string PrinterName = ""; // Default printer int Prompt = 0; axPDFCreactiveX1.Print(PrinterName, Prompt); } private void axPDFCreactiveX1_PrintPageEvent(object sender, AxACPDFCREACTIVEX._IPDFCreactiveXEvents_PrintPageEvent e) { // The following example will allow the control to save only the first 4 pages of the current document. MessageBox.Show("PrintPage event"); if (e.pageNumber < 5) { e.@continue = 1; } else { e.@continue = 0; } } }
#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace using namespace std; void CRedrawRect_CppDlg::OnBnClickedOk() { IPDFCreactiveXPtr m_PDF; // TODO: Add extra initialization here m_PDF = GetDlgItem(IDC_PDFCREACTIVEX1)->GetControlUnknown(); // Constants for Activation codes bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation"; bstr_t strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"; // set license key m_PDF->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode)); // Create 4 additional pages for (int page = 2; page < 6; page++) { m_PDF->AddPage(page); } // Create object in each Page for (int page = 1; page < 6; page++) { // Set the current page m_PDF->CurrentPage = page; // Set-up variables for attributes _variant_t varAttribute; varAttribute.vt = VT_I4; // integers // Create a text in the current Page m_PDF->CreateObject(acObjectTypeText, "Text" + bstr_t(page)); IacObjectPtr oText = pdf->GetObjectByName("Text" + bstr_t(page)); oText->Attribute["Left"] = 1000; oText->Attribute["Right"] = 5000; oText->Attribute["Top"] = 0; oText->Attribute["Bottom"] = 4000; varAttribute.lVal = 0xFF00FF; oText->Attribute["BorderColor"] = varAttribute; varAttribute.lVal = acBorderWidthDouble; oText->Attribute["BorderWidth"] = varAttribute; oText->Attribute["Text"] = "Amyuni Technologies" + bstr_t(page); } // Print all the document bstr_t PrinterName = ""; // Default printer long Prompt = 0; m_PDF->Print(PrinterName, Prompt); } BEGIN_EVENTSINK_MAP(CRedrawRect_CppDlg, CDialogEx) ON_EVENT(CRedrawRect_CppDlg, IDC_PDFCREACTIVEX1, 2, CRedrawRect_CppDlg::PrintPagePdfcreactivex1, VTS_I4 VTS_PI4) END_EVENTSINK_MAP() void CRedrawRect_CppDlg::PrintPagePdfcreactivex1(long PageNumber, long* Continue) { // The following example will allow the control to save only the first 4 pages of the current document. MessageBox(_T("PrintPage event"), _T(""), MB_YESNO); if (PageNumber < 5) { *Continue = 1; } else { *Continue = 0; } }