I have created a windows service which prints pdf file if the user request for it. When the user clicks the print button using web application, it adds a data entry in the db and the service gets the file name and tries to print it. I am getting "Object reference not set to an instance of an object" error whenever I try to print the pdf file. Here is the code
I am getting the error at the following line:Code:public void pd_PrintPage(object sender, PrintPageEventArgs ev) { Type AcrobatRect = Type.GetTypeFromCLSID(new System.Guid("{6D12C400-4E34-101B-9CA8-9240CE2738AE}")); Pen blackPen = new Pen(Color.Black, 3); CAcroRect rect; CAcroPDPage pdPage; int x1, y1; const int ZOOMFACTOR = 130; if (pageNum >= totalPages) { return; } try { //rectangle coordinates rect = (CAcroRect) Activator.CreateInstance(AcrobatRect); pdPage = (CAcroPDPage)pddoc.AcquirePage(pageNum); Acrobat.CAcroPoint oPoint = (CAcroPoint)pdPage.GetSize(); y1 = oPoint.y*ZOOMFACTOR/100; rect.Top = 0; x1 = oPoint.x*ZOOMFACTOR/100; rect.bottom = (short)y1; rect.Left = 0; rect.right = (short)x1; pdPage.CopyToClipboard(rect,0,0,ZOOMFACTOR); //draw the rectangle on clipboard IDataObject clipboardData = Clipboard.GetDataObject(); //get the data as a bitmap Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap); ev.Graphics.DrawImageUnscaled(pdfBitmap,0, 0); pageNum++; Marshal.ReleaseComObject(pdPage); Marshal.ReleaseComObject(oPoint); Marshal.ReleaseComObject(rect); pdfBitmap.Dispose(); ev.HasMorePages = pageNum >= totalPages ? false : true; } catch (Exception ex) { } }
Thanks for any helpCode:Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);




Reply With Quote