Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Change the preset print margins in TextEdit Apps
Because of its Unicode support, TextEdit is my favorite editor, but for months now the inability to change the print margins from their default 25-mm settings had been driving me crazy.

This evening it suddenly dawned on me that the solution was trivial. I opened the TextEdit.pbproj project in the /Developer -> Examples -> Appkit -> TextEdit folder, changed the hard-wired "72" values in Document.m to "36," and hit the run button. Presto! Problem solved!

[robg adds: This worked for me in XCode, though the button is labeled "Build and Go," not "Run."]
    •    
  • Currently 2.20 / 5
  You rated: 2 / 5 (5 votes cast)
 
[32,586 views]  

Change the preset print margins in TextEdit | 15 comments | Create New Account
Click here to return to the 'Change the preset print margins in TextEdit' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change the preset print margins in TextEdit
Authored by: ceesaxp on Apr 30, '04 03:35:10PM

Hmm... what about File/Page Setup (or Command-Shift-P)? Does it not provide page margins settings?



[ Reply to This | # ]
???
Authored by: jiclark on Apr 30, '04 05:44:42PM

Man I hate hints like this that assume a level of knowledge that's just not there in the vast majority of us!!! ;-}

I tried this, but it didn't seem to work. I could only find one set of references to the '72's in the huge amount of text that shows up in Xcode; I changed those to 36, but it still prints with one inch margins.

Any help?



[ Reply to This | # ]
More Details
Authored by: mundie1010 on Apr 30, '04 06:08:23PM

I'm sorry if my original post wasn't clear. Although there are 1,800+ lines of code in Document.m, there are only 6 occurrences of "72" - and the two having to do with tabs aren't relevant. The lines of interest start at line 487:

- (NSPrintInfo *)printInfo {
    if (printInfo == nil) {
        [self setPrintInfo:[NSPrintInfo sharedPrintInfo]];
        [printInfo setHorizontalPagination:NSFitPagination];
        [printInfo setHorizontallyCentered:NO];
        [printInfo setVerticallyCentered:NO];
        [printInfo setLeftMargin:72.0];
        [printInfo setRightMargin:72.0];
        [printInfo setTopMargin:72.0];
        [printInfo setBottomMargin:72.0];
    }
    return printInfo;
}

Change those 72 (pixel) values to whatever you want and rebuild.

By the way, I've discovered that once a document is saved with modified margins, even the official version of TextEdit will open it with those same margins, so you needn't always use the modified version - only when you want to create new templates.



[ Reply to This | # ]
More Details
Authored by: baturjan on Nov 14, '05 08:41:06AM

Thanks for this tip. I know nothing about Xcode, though I have it (1.5) installed. I'm running 10.3.9.

I copied the Document.m file to my desktop to keep a copy of the original.
Then I double clicked on the original Document.m file, which launched Xcode. I replaced the 72 numbers you mentioned with 42.

Then you said to "rebuild". Here's the ignorant, newbie question, how do I rebuild? I tried reading the Xcode help files to no avail.



[ Reply to This | # ]
Further explanation
Authored by: simsamsep on Apr 30, '04 06:24:55PM

When you follow the instructions, a new Text Edit is created in a (also newly created) 'Build' folder in the /Developer -> Examples -> Appkit -> TextEdit folder. If you use that newly built Text Edit, the margins will be as changed in the Document.m file. I changed the 72 values to 57 in order to get my preferred 20mm margins. If you use another language than English, you can copy the .lproj from the original Text Edit to the newly created one. (When you open the application package, inside Text Edit/Contents/Resources/)



[ Reply to This | # ]
Easier method to set TextEdit page margins (no code changes)
Authored by: pc_junk on Apr 30, '04 10:19:51PM

I had the same problem however found it easier to just save a blank RFT document and directly edit the raw RTF data to setup the margins. Once you have setup the margins TextEdit will use these when you open the document. You can also setup the template as a stationary pad to make creating new docs easier.

To edit the raw RFT data you need to use a text editor from the terminal (vi/pico).

The "default" blank document from TextEdit looks like this:

{\rtf1\mac\ansicpg10000\cocoartf102
{\fonttbl}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww12240\viewh14100\viewkind1\viewscale100
}

To set the margins just set \margl & \margw appropriately (1440 is 1") - to set the top/bottom margins you can also set \margt & \margb

My template for a document with 0.5" margins is:

{\rtf1\mac\ansicpg10000\cocoartf102
{\fonttbl}
{\colortbl;\red255\green255\blue255;}
\margt720\margb720\margl720\margr720\vieww9920\viewh8000\viewkind0
}



[ Reply to This | # ]
Easier method to set TextEdit page margins (no code changes)
Authored by: tinb on May 01, '04 02:09:27AM
You don't need to use a text editor like vi or pico to edit rtf files this way. Just choose open from TextEdit and switch Ignore rich text commands on the open panel.

[ Reply to This | # ]
Easier method to set TextEdit page margins (no code changes)
Authored by: epkesdotcom on Jun 08, '04 05:40:59AM

Nice solution. But to further simplify this solution try this.

Open .RTF file in BBedit Lite (free) or similar raw text app.
* For .RTFD document CNTRL select file - SHOW PACKAGE CONTENTS... Then open .RTF in raw text editor.

On line 5 you will see this:
margl1440\margr1440\vieww9920\viewh8000\viewkind0

"marg" stands for margin and the l & r stands for left and right

Conversions: .25 = 360 .5 = 720 .75 = 1080 1" = 1440

Also t & b stands for top and bottom.

So if you change the fifth column to this...
\margt720\margb720\margl1080\margr1080\vieww9920\viewh8000\viewkind0

You will have margins Top: .5 Bottom: .5 Left: .75 Right: .75

The vieww and viewh open the document to the preferred dimensions.

Wouldn't it be amazing if something like this were actually a part of a text edit app? Hmm... Apple?

Hope this helps. - Epkes



[ Reply to This | # ]
Easier method to set TextEdit page margins (no code changes)
Authored by: epkesdotcom on Jun 08, '04 05:46:51AM

Actually tinb's comment:
"Just choose OPEN from TextEdit and switch Ignore rich text commands on the open panel" is probable better then using BBEdit. Much faster.



[ Reply to This | # ]
Easier method to set TextEdit page margins (no code changes)
Authored by: epkesdotcom on Jun 08, '04 05:53:28AM

Although tinb's idea doesn't apply to RTFD documents. You need to open its package contents in BBEdit or set Text Edit's prefs to "Ignore rich text commands" temporarily for editing and then turn them back on when done.



[ Reply to This | # ]
Easier method to set TextEdit page margins (no code changes)
Authored by: epkesdotcom on Jun 08, '04 05:56:10AM
I meant to say: So if you change the fifth ROW to this... \margt720\margb720\margl1080\margr1080\vieww9920\viewh8000\viewkind0

[ Reply to This | # ]
Change the preset print margins in TextEdit
Authored by: Cameroon on May 02, '04 10:21:57AM

Ok, for anyone savvy enough to do a little leg-work with XCode and Interface Builder, I've built a version of TextEdit that provides a "Page Margins" sheet that lets you set the margins.

Here's the catch, I'm not about to distribute a binary of Apple's application. However, I will distribute the instructions on how to build the modified version of TextEdit as well as a nib file I created that is required and an AppleScript to perform the actual build (selects the right build style and copies the result to your desktop).

Note: The same procedures should work with Project Builder, but the AppleScript will not.

The archive containing the instructions, the AppleScript and the nib file is located at http://homepage.mac.com/cjbehm/files/textedit_mod.zip

My e-mail is in the instructions for those who try and have difficulties.



[ Reply to This | # ]
Change the preset print margins in TextEdit
Authored by: rscrane on Aug 13, '04 02:03:43PM

Thanks much -- works just great. Highly recommended.



[ Reply to This | # ]
Change the preset print margins in TextEdit
Authored by: crucial on Mar 25, '06 12:51:20PM

I have been trying to follow the instructions provided, but they don't seem to work with Xcode 2.2. Anybody know how to update / modify them ?



[ Reply to This | # ]
Change the preset print margins in TextEdit
Authored by: fimwat on Mar 08, '08 10:23:57PM
Or, you could download a better Text Edit alternative, like Bean or iText Express.

[ Reply to This | # ]