I am developing a web application and I wanted to print PDF files on the server printer such that I would like to control the printer settings. For that I created a component and is getting the following error:
Object reference not set to an instance of an object
My code in the component looks like this:
The logic was to create bitmap file for each page and print these pages.Code:public string PrintPDF(Acrobat.CAcroPDPage pdPage, int numPg) { Type AcrobatRect = Type.GetTypeFromCLSID(new System.Guid("{6D12C400-4E34-101B-9CA8-9240CE2738AE}")); Acrobat.CAcroRect rect; int x, y; const int ZOOMFACTOR = 150; Bitmap pdfBitmap = null; string fname = "C:\\Inetpub\\wwwroot\\ASPApp\\PDF\\btmap" + numPg.ToString() + ".bmp"; try { rect = (Acrobat.CAcroRect) Activator.CreateInstance(AcrobatRect); Acrobat.CAcroPoint oPoint = (Acrobat.CAcroPoint)pdPage.GetSize(); y = oPoint.y*ZOOMFACTOR/100; rect.Top = 0; x = oPoint.x*ZOOMFACTOR/100; rect.bottom = (short)y; rect.Left = 0; rect.right = (short)x; pdPage.CopyToClipboard(rect,0,0,ZOOMFACTOR); IDataObject clipboardData = Clipboard.GetDataObject(); pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap); pdfBitmap.Save(fname); pdfBitmap.Dispose(); } catch (Exception ex) { } return fname;
The above error I am getting is at the line:
pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
Any help is appreciated




Reply With Quote