# How to export notebook in colored PDF form [duplicate]

Possible Duplicate:
Saving a notebook as PDF, preserving syntax highlighting

I would like to export my notebook code in a colored PDF form. What I do is select the brace in the right side of the lines I'd like to export and then from "File->Save Selection As" I export it as pdf. The thing is that there aren't any colors.

Is there a way to export in PDF while adopting all colors?

EDIT: I also tried "Print Selection" instead of "Save selection As" but I faced to problems: The is a lot of empty space, which means that I will not be able to include it in my tex code and secondly there aren't any colors in my input code, while the output graphic really adopts color. My output is

-

## marked as duplicate by acl, image_doctor, Ajasja, rm -rf♦Nov 30 '12 at 21:42

Your question is not entirely clear (to me) but are you wanting the syntax colouring to appear in your input code in the PDF? If so this is controlled via stylesheeting which by default has this switched off for printing. If you confirm that is what you are wanting to achieve I'll post a solution. ...but it may not be until tomorrow. –  Mike Honeychurch Nov 30 '12 at 8:24
@MikeHoneychurch: This is exactly what I am trying to do!!! I try to find something by myself;you just gave a path to walk! But any help from an expert is always vital!!! Thank you! –  Thanos Nov 30 '12 at 8:26
ok I just posted the explanation and answer. –  Mike Honeychurch Nov 30 '12 at 8:49

What is happening here is that when you print (or make a PDF) the default printing style has the sytnax colouring switched off. You can see this by editing your stylesheet then clicking on "default.nb" and then when that notebook opens clicking on "Core.nb" and have a look at the printout style:

So when you highlight some input and save as PDF, or Export a notebook to PDF etc. you see stuff like this:

So the way to fix this is via the stylesheet is to go to Format>Edit Stylesheet and add this style cell to your notebooks stylesheet:

Cell[StyleData[All, "Printout"],
ShowSyntaxStyles->True]


To fix this "permanently" you probably want to install the style stylesheet so you can use the installed stylesheet regularly rather than have to do this every time. Here is what it the new PDF looks like:

The way to fix this via the option inspector is to switch to printout style environment and then change the option setting.

Before:

After:

-
Yeah!!! It is working like a charm!!!Thank you so much!!! –  Thanos Dec 2 '12 at 11:47

(not an answer, can't put this in the comment)

Which version are you using? using V9 I have no problem seeing color in the PDF generated file. Here. May be your print env. is messed up? Mine is set to printout. Window 7

-
How can I check my print environment? I also tried "Print Selection As" instead of "Save selection As" but I faced to problems(Check my edited answer for the output): The is a lot of empty space, which means that I will not be able to include it in my tex code and secondly there aren't any colors in my input code, while the output graphic really adopts color. –  Thanos Nov 30 '12 at 7:49
I am using V9 in Vista –  Thanos Nov 30 '12 at 7:52
I checked my print env and mine is set to "printout" as well... –  Thanos Nov 30 '12 at 7:53
This is unusual behaviour unless the default printout style has been changed in V9. –  Mike Honeychurch Nov 30 '12 at 8:51

Your saved PDF supports color. It's just that the FrontEnd's code coloring isn't encoded into the cell expression from which the PDF is made. It's just something the FrontEnd's code editor adds when it displays the code on your screen.

Edit: This is misleading because, as Mike Honeychurch's answer states, there is an option for the printing environment that will preserve code coloring.

-
Thank you very much for your answer! But I checked Nasser M. Abbasi's answer and his PDF output is colored... –  Thanos Nov 30 '12 at 7:55