Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I highlight some features with a semi transparent color via an ILayerExtensionDraw. When I print the ActiveView of the PageLayoutControl with IPrintAndExport the highlightning is not on the printout.

In the print method I get the printers HDc and save it to a static variable which the LayerExtension reads from.

  System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
  System.Windows.Forms.DialogResult res = printDialog.ShowDialog();
  if (res == System.Windows.Forms.DialogResult.Cancel)
    return false;

  // ... assigning printer settings here...

  System.Drawing.Graphics graphics = printDialog.PrinterSettings.CreateMeasurementGraphics();
  MyLayerExtension.CurrentPrinterHdc = graphics.GetHdc();

  PrintAndExport.Print(docActiveView, docPrinter, _pageLayoutControl.PageLayout.Page, 1, iResampleRatio, null);

  graphics.ReleaseHdc();
  MyLayerExtension.CurrentPrinterHdc = IntPtr.Zero;

The LayerExtension reads the IntPtr and uses it to draw the highlightning to the printer, but it is not shown on the print out.

SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
fillSymbol.Outline = new ESRI.ArcGIS.Display.SimpleLineSymbol();
fillSymbol.Color = Utilities.CreateColor(System.Drawing.Color.Khaki);
pDisplay.Filter = new TransparencyDisplayFilterClass { Transparency = 127 }; 
pDisplay.SetSymbol((ISymbol)fillSymbol);
pDisplay.StartDrawing(pDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
if (CurrentPrinterHdc != IntPtr.Zero)
  pDisplay.StartDrawing(CurrentPrinterHdc.ToInt32(), (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
pDisplay.DrawPolygon(feature.Shape);
pDisplay.FinishDrawing();

The LayerExtension does get called on printing.

What did I miss?

Update As far as I understand the HDc now the drawing on the printers handle would only work, if I use the HDc to print later on again, which is not a real option.

Is there any other way to get the transparent (!) highlightning printed?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You saved a device context identifier, but ArcGIS creates and uses a different device context to print on afterwards. This means that what you draw in the layer extension is not visible in the output document.

You cannot use IPrintAndExport in your case because it does not allow you to reach the device context used when printing and exporting. You will need to use the old-fashioned method of printing which was traditionally used before IPrintAndExport was introduced, i.e. the IPrinter.StartPrinting method (or IExport.StartExporting). These methods return the actual device context which you pass to IActiveView.Draw, but you can also leverage it in your scenario such as drawing any additional content.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.