Printing to a Postscript File from Delphi/C++ Builder

Unfortunately for me, I had to patch some legacy C++ Builder code to output the reports that were sent to a printer to a PDF file. Fortunately, many printers support standard Postscript and converting to a PDF from a Postscript is trivial.

Here are the instructions, assuming Windows XP:
1)Go to Printers/Faxes and Add New Printer
2)When the wizard pops up click “Next”
3)You should be on the screen “Add Printer Wizard”… select “Local Printer Attached”, uncheck “Automatically detect…”
4)Use port “LPT1”
5)Select “Apple” for manufacturer and printers select “Apple LaserWriter 12/640 PS”
6)In printer name I put “Apple PS”
7)For default, you can select “No”
8)No on sharing/or printing test page.

Now we have a Postscript printer installed.

Here is some sample code:

void __fastcall TForm2::Button1Click(TObject *Sender)
{
    TDocInfo di;
 
    int i = Printer()->Printers->IndexOf("Apple PS");
    Printer()->PrinterIndex = i;
 
    Printer()->BeginDoc();
    EndPage(Printer()->Canvas->Handle);
    AbortDoc(Printer()->Canvas->Handle);
 
    memset(&di, sizeof(di), 0);
    di.cbSize = sizeof(di);
    di.lpszDocName = "TEST";
    di.lpszOutput = "C:\\somefile.ps";
    StartDoc(Printer()->Canvas->Handle, &di);
    StartPage(Printer()->Canvas->Handle);
 
    Printer()->Canvas->TextOutA(0,0, "Testing Printer");
    Printer()->EndDoc();
}

Are you a Git user? Let me help you make project management with Git simple. Checkout Gitpilot.

Follow me on Twitter: @jprichardson and read my blog on software entrepreneurship: Techneur

-JP

Disable Sprockets for Rails in Development Mode

Sprockets (is/are)? the technology in Rails 3.1 and up that combines your CSS and Javascript files into one CSS and Javascript file. It remains to be seen if this was a positive change or not. The argument is that the client only has to make one HTTP request instead of many for each file; this is a good thing. However, if you change one line in one of your Javascript files, the client then has to redownload the entire combined file instead of just the one Javascript file that you modified.

Regardless, you may want to disable Sprockets while you’re developing your Rails application. This will aid in debugging.

Change…

<%= stylesheet_include_tag "application" %>
<%= javascript_include_tag "application" %>

to…

<%= stylesheet_include_tag "application", debug: Rails.env.development? %>
<%= javascript_include_tag "application", debug: Rails.env.development? %>

Are you a Git user? Let me help you make project management with Git simple. Checkout Gitpilot.

Follow me on Twitter: @jprichardson and read my blog on software entrepreneurship: Techneur

-JP

Missing DockPanel? Add DockPanel for Silverlight 4 or Silverlight 5

When I first created a demo project for Silverlight 5, I opened the XAML code to start editing. I started typing “DockPanel” but then I noticed that intellisense didn’t show anything. It turns out that DockPanel and some other controls aren’t included in the default installation of Silverlight 4 or Silverlight 5 beta.

Here’s what you need to do:

  1. Download the Silverlight 4 Toolkit. Install it. (Yes, this will work with Silverlight 5 beta)
  2. Add a reference to “System.Windows.Controls.Toolkit”. In Silverlight 5, you will need to navigate to the file:
    %ProgramFiles%\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin\System.Windows.Controls.Toolkit.dll
  3. Add the following attribute to your UserControl: xmlns:tk=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit”
  4. So your code might look like:

    <UserControl x:Class="Project1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
    		<tk:DockPanel>
    			
    		</tk:DockPanel>
        </Grid>
    	
    </UserControl>
    

    Enjoy.

    Advertisement:
    Make Git simple. Let Gitpilot show you the right way to Git things done. Gitpilot will help you write software faster.

    Follow me on Twitter: @jprichardson and read my blog on software entrepreneurship: Techneur

    -JP

Open a New Tab in Terminal.app in the Same Directory on Mac OS X

When working with Rails on my Mac OS X machine, I often find myself opening a lot of terminal tabs. Unfortunately I then need to navigate to the same directory as the other tabs. It’s a big pain. Fortunately superuser.com has a solution.

Create a new file in “/usr/local/bin” named “nt”

#!/bin/bash
osascript -e 'tell application "Terminal"' \
-e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
-e "do script with command \"cd `pwd`;clear\" in selected tab of the front window" \
-e 'end tell' &> /dev/null

Then set its executable bit. “chmod +x /usr/local/bin/nt”

That’s it!

Advertisement:
Make Git simple. Let Gitpilot show you the right way to Git things done. Gitpilot will help you write software faster.
Follow

Get every new post delivered to your Inbox.