My code prints some reports by giving the data, a printer's device context and a bounding rectangle to a third party library. This library then renders the data into the given device context which I can send to the printer afterwards. I now need to save this exact document so that the user can print it again at a later time. The easiest solution I could think of is to give the device context of an image file to the third party library, let it draw into the image and save the image as a file. However the results are not identical. For example the lines in the image are thicker than the ones send to the printer, increased line spacing between two lines, etc.
The DC I get from the printer obviously has different properties (e.g. higher DPI and thus different dimensions when measuring in pixels). I tried to adjust for that and calculated the dimensions of the image in accordance with the DPI.
What I don't understand is why the image's dimensions are different from the corresponding DC of the image. I create it with
Image.Create(widthAt96Ppi, heightAt96Ppi, 32);
CDC* pDC = CDC::FromHandle(Image.GetDC());
It looks like your bitmap is being created compatible to desktop DC. I think you should create image using
CreateCompatibleBitmap method (or corresponding MFC overload, if it has one) supplying original printer DC and dimensions to it.