We have a legacy system that spits out text files that used to be printed on a 132-column printer. Some files have even longer lines, such as 169 characters. For whatever reason, the .DOC file extension is attached, so that the files open up in Microsoft Word even though they are not Word documents and simply plain text.

Apparently there was a Word macro on peoples' machines at some point that reformatted the document so that it would fit on a page - as far as I can tell, selecting all the text and bumping the font size down to 6pt accomplishes this with Courier New or Consolas fonts.

I hate to force something like this for ALL plain text files that are opened in Word, and the ideal solution would be to convert these files to PDF (which also solves the problem of viewing them as an email attachment on the iPhone) but I'm running out of ideas.

Any suggestions?

DATE 02-15-14                                          LISTING OF HIRED AND TERMINATED EMPLOYEES FOR 01/01/14 - 01/31/14                                          PAGE 1

EMPNO.....    AGENT NAME..........    Employee Name............    HIRE DATE    TERM DT.    LOGIN ID............    EMAIL NAME..............................

30594         ABC-NEWYORK            JOE SMITH               01/06/14                NEWYORK.JOE             JOE SMITH

I took your file, and made a macro for you:

Sub LongWidth()
' LongWidth Macro
    With Selection.PageSetup
        .Orientation = wdOrientLandscape
        .TopMargin = InchesToPoints(0.5)
        .BottomMargin = InchesToPoints(0.5)
        .LeftMargin = InchesToPoints(0.5)
        .RightMargin = InchesToPoints(0.5)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.5)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
        .GutterPos = wdGutterPosLeft
    End With
    Selection.Font.Size = 7
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        "C:\Path\To\Folder\foo.pdf", ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
        wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
        IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
        wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
        True, UseISO19005_1:=False
End Sub

So what this does is first sets the page to landscape mode with narrow margins. Then I selected all the text and set the font to 7. Then I exported the document as a PDF.

If you have users looking to view this on an iPhone or something, I would look into automating Word to convert all these files into a PDF in an automated process. Joel Spolsky wrote an article long ago on this process. A lot has changed, but these concepts are still valid.

  • Last year I worked out a command line using some software called 'verypdf' which did what we wanted. C:\Program Files (x86)\Text2PDF v1.5>txt2pdf "CLMTOT.txt" "clmtot.pdf" "-pfs10" "-plm16" "-prm16" "-ptm16" "-pbm16" "-pol0" "-pps43" "-width850" "-height600" – Bert Feb 17 '14 at 14:32
  • I'm going to mark this as accepted because it's similar to the macro we use now - the real issue is the system is spitting out lines longer than 132 characters and that's not expected. – Bert Feb 17 '14 at 14:36

For converting to PDF I found http://www.adultpdf.com/products/txttopdf/ to be excellent. It gave me a PDF file that kept the line breaks perfectly. It also provides a command line interface which supports selecting different font types and would enable you to convert all files in a folder. A command to do this for all files in current folder is:

@echo off
for /r %%F in (*) do TXTtoPDF "%%~nF"

Replace TXTtoPDF with the location of the TXTtoPDF.exe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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