3
$\begingroup$

I am trying to export a complete notebook as a single image. I do not want separate pages, just one really long image.

I think I got close to figuring this out in the past, but I forgot what I did.

I am looking for something like how M$oft Edge's "web capture" can save an entire page to a single image file:

enter image description here

$\endgroup$
1

2 Answers 2

5
$\begingroup$

Edit, I found out how to do it, but it is not rendering the notebook style correctly for some reason

:(

Export[FileNameJoin[{NotebookDirectory[], "image.jpg"}], 
 SelectedNotebook[]]

Edit: Andrew Lewis of the Wolfram Technical Support team confirmed the bug and provided me this work-around using WebExecute (tested on WL version 14.0):

:)

(* 1. Export as html *)
exp=NotebookDirectory[];
Export[exp<>"test.html",NotebookObject[style (2).nb]];

(* 2. Open the exported .html using the web browser driver *)
session=StartWebSession["Firefox",Visible->False];
WebExecute[session,"OpenPage"->"file://"<>exp<>"test.html"];

(* 3. Use the web browser driver to take a screenshot *)
width=WebExecute[session,"JavascriptExecute"->"return document.documentElement.scrollWidth"];
height=WebExecute[session,"JavascriptExecute"->"return document.documentElement.scrollHeight"];
WebExecute[session,"SetWindowSize"->{width,height}];
webpageImage=WebExecute[session,"CapturePage"];

(* 4. Save the screenshot *)
Export[exp<>"screenshot.png",webpageImage];
$\endgroup$
0
3
$\begingroup$

This is easy to do on Linux. For windows or mac, you might have to use online tool. There are many of them if you google. I just tried it this on one large notebook I have.

  1. open the notebook and save as PDF. Assume file is saved as A.pdf

  2. open terminal and type

    convert A.pdf -append p%d.png

Done.

convert is basic Linux command that comes with Linux/Unix (if you do not have it, very easy to install).

This will create one single PNG image in same folder which contains all the PDF pages in one image.

It will be hard to see without zooming if you have many pages ofcourse.

To do the same on windows, if you have WSL then you can do the same command. As I said, there are online tools that do this also given a PDF file as input. But I do not like to use online tools.

Ofcourse the image using this, will look like the Mathematica exported PDF file and not like the the notebook itself. So some stylings might be lost.

So it depend on how good Mathematica PDF export is.

Reference: convert-multipage-pdf-to-a-single-image

https://reference.wolfram.com/language/howto/ExportToPDF.html

$\endgroup$
2
  • $\begingroup$ PDF export also does not render custom notebook styles with colored backgrounds correctly. Each page has a white bar across the top :( Also, I think this would make weird margins between pages (unless there is an option for detailed control over exports). $\endgroup$ Feb 12 at 2:49
  • $\begingroup$ @AlecGraves yes, as I said, it is as good as Mathematica PDF export will give so some stylings might be lost. You can try different PDF export option, by changing print settings and so on and see if that helps in preserving more styling from the notebook. Also the notebook style sheet itself might make a difference. $\endgroup$
    – Nasser
    Feb 12 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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