anchor.diff:  %% Note page 1 is already created  by default and  current page set 
   %% to it after creation of PDF context.
   new_page(PID)->
  -    PID ! {page, {new, self()}},
  -    receive
  -	{page,PageNo}->
  -	    PageNo;
  -	{'EXIT', PID, Reason} ->
  -	    exit(Reason)
  +   case gen_server:call( PID, {get_new_page}, infinity) of
  +    	{page,PageNo}->
  +    	    PageNo;
  +    	{'EXIT', PID, Reason} ->
  +    	    exit(Reason)
       end.
   
  +
  +
   page_script(PID, Script) ->
  -    PID ! {page_script, Script}.
  +    gen_server:cast(PID, {page_script, Script}).
  +
   
   %% Go to a page already created.    
   set_page(PID, PageNo)->
  -    PID ! {page,{set, PageNo}}.
  +    gen_server:cast(PID, {page,{set, PageNo}}).
   
   %% Useful for page numbering functions etc.
   get_page_no(PID)->
  -    PID ! {page, {get_no, self()}},
  -    receive
  -	{page,PageNo}->
  -	    PageNo;
  -	{'EXIT', PID, Reason} ->
  -	    exit(Reason)
  +   case gen_server:call( PID, {get_page_no}, infinity) of
  +    	{page,PageNo}->
  +    	    PageNo;
  +    	{'EXIT', PID, Reason} ->
  +    	    exit(Reason)
       end.
       
   %% --- Info -----
   
   set_author(PID,Author)->
  -    PID ! {info,{author, Author}}.
  +      gen_server:call(PID, {info, {author, Author}}, infinity).
   
   set_title(PID,Title)->
  -    PID ! {info,{title, Title}}.
  +    gen_server:call(PID, {info, {title, Title}}, infinity).
   
   set_subject(PID,Subject)->
  -    PID ! {info,{subject, Subject}}.
  -
  +    gen_server:call(PID, {info, {subject, Subject}}, infinity).
  +    
   set_date(PID,Year,Month,Day)->
  -    PID ! {info,{date, {Year,Month,Day}}}.
  -
  +    gen_server:call(PID, {date, {Year,Month,Day}}, infinity).
  +    
   set_keywords(PID, Keywords)->
  -    PID ! {info,{keywords, Keywords}}.
  +    gen_server:call(PID, {keywords, Keywords}, infinity).
  +
   
   
   %% --- Page ---
  
positive.code: %% Export to PDF file format 
  %% return: {PDFDoc::binary(), PageNo::integer()} | exit(Reason)
  export(PID)->
      PID ! {export, self()},
      receive
  	{export, PDFDoc, PageNo}->
  	    {PDFDoc, PageNo};
  	{'EXIT', PID, Reason} ->
  	    exit(Reason)
      end.
  
  %% clear up - delete pdf building process
  delete(PID)->
      PID ! delete,
      done.
  
  
  
negative.code: %%                                      {stop, Reason, State}
  %% Description: Handling call messages
  %%--------------------------------------------------------------------
      	
  handle_call({get_page_no}, _From, [PDFC, Stream]) ->	        
  	    {reply, {page, PDFC#pdfContext.currentpage}, [PDFC, Stream]};
  	    
  handle_call({info,Info}, _From, [PDFC, Stream]) ->	      
  	    NewInfo = pdf_handle_info(PDFC#pdfContext.info, Info),
  	    {reply, ok, [PDFC#pdfContext{info=NewInfo}, Stream]};
  	    
  handle_call({get_new_page}, _From, [PDFC, Stream]) ->	      
  	    {Add, PageNo} = 
      		handle_newpage(PDFC#pdfContext.pages,
      			       PDFC#pdfContext.currentpage,
      			       [Stream]),
      {reply, {page, PageNo}, [PDFC#pdfContext{pages=Add, currentpage=PageNo}, <<>>]};
  	        
  handle_call({export,PID}, _From, [PDFC, Stream]) ->	
  	    %% add last page if necessary before exporting
  	    PDF = case Stream of 
        		      <<>> ->		    
        			  PageNo = PDFC#pdfContext.pages,
        			  handle_export(PDFC);
        		      _ ->
        			  {Add, PageNo} = handle_newpage(
        					    PDFC#pdfContext.pages,
        					    PDFC#pdfContext.currentpage,
        					    [Stream]),
        			  handle_export(PDFC#pdfContext{pages=Add})
        	    end,
  	    {reply, {export, PDF, PageNo}, [PDFC, Stream]}.
  
  
  %%--------------------------------------------------------------------
  %% Function: handle_cast(Msg, State) -> {noreply, State} |
  %%                                      {noreply, State, Timeout} |
  %%                                      {stop, Reason, State}
  %% Description: Handling cast messages
  %%--------------------------------------------------------------------
  	    	    
  handle_cast({mediabox, Mediabox},  [PDFC, Stream]) ->	
  	    {reply, ok, [PDFC#pdfContext{mediabox=Mediabox}, Stream]};
  	    
  handle_cast({font, {set, Fontname, Size}}, [PDFC, Stream]) ->	
        {F,Alias,Fhand} = handle_setfont(PDFC#pdfContext.fonts, Fontname),
        S = list_to_binary(eg_pdf_op:set_font_by_alias(Alias, Size)),
        Binary = <<Stream/binary, S/binary>>,
        {reply, ok, [PDFC#pdfContext{fonts=F,font_handler=Fhand}, Binary]};
        
  handle_cast({stream, {append, String}}, [PDFC, Stream]) ->	    
  	    B = list_to_binary(convert(PDFC#pdfContext.font_handler, String)),
  	    Binary = <<Stream/binary, B/binary, <<" ">>/binary>>,
  	    {reply, ok, [PDFC, Binary]};
  	     
  handle_cast({image, FilePath, Size}, [PDFC, Stream]) ->	    
  	    {I,IMG,{W,H},ProcSet} = handle_image(PDFC#pdfContext.images, 
  						 FilePath, Size, 
  						 PDFC#pdfContext.procset),
  	    S = list_to_binary(eg_pdf_op:set_image(W,H, IMG)),
  	    Binary = <<Stream/binary, S/binary>>,
  	    {reply, ok, [PDFC#pdfContext{images=I,procset=ProcSet}, Binary]};	    
      
  handle_cast({page_script, Script}, [PDFC, Stream]) ->	
  	    %% io:format("New script ~p\n", [Script]),
  	    NewScript = handle_pagescript(PDFC#pdfContext.scripts,
  					  PDFC#pdfContext.currentpage,
  					  Script),
  	    {reply, ok, [PDFC#pdfContext{scripts=NewScript}, Stream]};
  
  handle_cast({page,{set,PageNo}}, [PDFC, Stream]) ->	
  	    {NewPages,[NewStream]} = handle_setpage(PDFC#pdfContext.pages,PageNo,
  						  PDFC#pdfContext.currentpage, 
  						  [Stream]),
  	    {reply, ok, [PDFC#pdfContext{pages=NewPages,currentpage=PageNo}, NewStream]};	    
    
  handle_cast({ensure_font, Fontname}, [PDFC, Stream]) ->	      
  	    F = ensure_font( eg_font_map:handler(Fontname), PDFC#pdfContext.fonts),
  	    {reply, ok, [PDFC#pdfContext{fonts=F}, Stream]}.
  %%--------------------------------------------------------------------
  %% Function: handle_info(Info, State) -> {noreply, State} |
  %%                                       {noreply, State, Timeout} |
  