Wednesday, April 15, 2009

Linux: Install a virtual PDF printer on CUPS

I have been always looking for a virtual PDF printer solution.  The only solution I know is windows PDF printer driver on Internet that need to pay.  I never know CUPS can do the job and it is free.

Service Installation

# yum install cups-pdf

After finish install, you may check if the PDF printer is installed and configured from CUPS web interface (e.g: http://cups-printer:631/)

You may configure where to keep PDF output in /etc/cups/cups-pdf.conf.  Look for “Out ${HOME}/Desktop” string in the file.

Windows Client Installation

  1. Make sure you have or know where is the printer driver files
  2. Click Start | Control Panel | Printers and Faxes
  3. Click Add a Printer
  4. Choose "A network printer, or a printer attached to another computer"
  5. Choose "Connect to a printer on the Internet or on a home or office network".  Type the printer URL (e.g: http://cups-printer:631/printers/cups-printer).
  6. Click Next and select appropriate PostScript (PS) printer driver (e.g: HP Color LaserJet 9500 PS)

Enjoy a new virtual PDF printer on your network.  You may start print document from windows workstation to this printer and collect the PDF output files from your Linux home account.

Reference:

  1. CUPS – PDF Printer

Wednesday, April 08, 2009

Delphi: Using TWebBrowser to display content from stream rather than URL

TWebBrowser is a wrapper for Internet Explorer COM interface.  The most common way to use TWebBrowser is using Navigate method that accept a URL string.  However, this is not convenient for user who already has a rendered HTML string or stream.  One workaround solution for this is save the string or stream to a temporary file and use supply a local file URL to TWebBrowser.Navigate.

Here is a solution for supplying a HTML stream to TWebBrowser:

uses ActiveX;

const IID_IPersistStreamInit : TGUID = '{7FD52380-4E07-101B-AE2D-08002B2EC713}';

procedure TForm19.Button1Click(Sender: TObject);
var S: TStream;
    o: IPersistStreamInit;
begin
  S := TStringStream.Create('<html><body>this is a test</body></html>');
  try
    WebBrowser1.Navigate('about:blank');
    while WebBrowser1.ReadyState <> Shdocvw.READYSTATE_COMPLETE do
      Application.ProcessMessages;

    if Supports(WebBrowser1.Document, IID_IPersistStreamInit, o) then
      o.Load(TStreamAdapter.Create(S));
  finally
    S.Free;
  end;
end;

Reference:

  1. Component to display HTML read from a stream rather than fetched from a URL. Author: Antonio Estevez. URL: https://forums.codegear.com/thread.jspa?threadID=15004&tstart=0