How can I rasterize the selection in a notebook, preserving In/Out labels when appropriate?
- To: mathgroup at smc.vnet.net
- Subject: [mg123957] How can I rasterize the selection in a notebook, preserving In/Out labels when appropriate?
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Mon, 2 Jan 2012 02:46:36 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Dear MathGroup, How can I rasterize the selection in a notebook, preserving In/Out labels when appropriate? I already asked about this here: http://stackoverflow.com/questions/8353838/controlling-the-rasterize-width-for-notebook-related-expressions , but the question is not completely solved. A summary of what I have so far (you can skip to point 3 for the main question). 1. Applying Rasterize to the result of NotebookRead[] will reformat everything using the width of the evaluation notebook. If it's called from a palette, this is unusably narrow. So Rasterize at NotebookRead[...] is not usable here. 2. One method is using the the Edit -> Copy As -> Bitmap menu item. This is callable from a program like this: FrontEndToken[FrontEnd`SelectedNotebook[], "CopySpecial", "MGF"]] This works nicely but is unfortunately Windows-only, and also destroys the clipboard contents. 3. The best method is copying everything to a new notebook and Rasterizing the whole notebook expression, like so: CreatePalette@Button["Preview", Module[{target}, target = CreateDocument[{}, WindowSelected -> False, Visible -> False]; NotebookWrite[target, NotebookRead[SelectedNotebook[]]]; CreateDialog[{Rasterize[target], DefaultButton[]}]; NotebookClose[target] ] ] The problem (sometimes advantage, sometimes problem :) with this is that the In/Out labels are not included in the rasterization. Test it by creating a palette using the above code, selecting a few input/output cells, and pressing the palette button. So the question could be rephrased as: is there a way to rasterize a whole notebook so that In/Out labels are preserved? I need this to work for any selection, not only when complete cells are selected. When only part of the text or a graphic is selected, of course there shouldn't be any In/Out labels. However, when one or more input/output cells are selected using the cell brackets, the labels should be preserved. -- Szabolcs Horv=E1t Mma QA site proposal: http://area51.stackexchange.com/proposals/37304