I have a Crystal Reports 2008 report that has one of the fields using a MICR truetype font. If I export to PDF within Crystal Reports the field shows properly. If I export the report to PDF using the COM interface my PHP application uses the field does not show using the MICR font.

I've been using Crystal Reports 2008 w/ PHP for a while now with great success. Using the info from the php COM manual pages I can create Crystal Reports objects and call their functions from within PHP. (Source code below)

If I go to the PDF properties with adobe reader:
-The one generated using crystal reports application has the MICR font listed in the 'fonts used by the document' list
-The one generated using the COM interface does not show that font.

If I try other fonts: If the server has the font it shows up properly. If the server doesnt have the font then i experience the same issue as with the MICR font. The confusing thing is that I know the server and the client have the same MICR true type font (I installed them both). The font also can be verified to be operational on the server from within the Crystal Reports Application.

The code sample shows a call to my generateReport method, which uses COM to create the PDF from the RPT and then return it to the user.

<?php

generateReport(array(1=>"1234567890"),getcwd()."/reports/check.rpt");		
function generateReport($vals,$reportName){	  
set_time_limit(300); //------ Variables ------ $output_pdf = "C:\\temp\\temp.pdf"; if(file_exists($output_pdf)) if(!unlink($output_pdf)) return "Failed to clear temp. please try again"; try{ $crapp = new COM("CrystalRunTime.Application"); if($crapp==null) return "Failed to access Crystal Reports"; $creport = $crapp->OpenReport($reportName, 1); $creport->EnableParameterPrompting = 0; $creport->DiscardSavedData; $creport->ReadRecords(); for($i=1;$i<=count($vals);$i++){ $field=$creport->ParameterFields($i); $res=@$field->SetCurrentValue($vals[$i]); if($res==0){ //success setting parameter value }else{ return "Failed to create report. Failed to set parameter $i with value ".$vals[$i]; } } $creport->ExportOptions->DiskFileName=$output_pdf; $creport->ExportOptions->FormatType=31;//constant for PDF export $creport->ExportOptions->DestinationType=1; $creport->Export(false); if(file_exists($output_pdf)){ $pdf=file_get_contents($output_pdf); if(strlen($pdf)!=filesize($output_pdf)) return "Error: filesize=".filesize($output_pdf)." strlen=".strlen($pdf); header("Pragma: "); header("Cache-Control: "); header("Content-type: application/pdf"); header("Content-Disposition: attachment;filename=".extractName($reportName).".pdf"); // For IE echo($pdf); exit(); }else return "Failed to export"; }catch(Exception $e){ return "Failed to connect to Crystal Reports 2008: $e"; } } ?>

PS: Sorry for the longwinded question.

    One other note: If I change the FormatType and DiskFileName and export it as a microsoft word document the MICR font comes across fine. Unfortunatly I specced it out as created a PDF

      a year later
      benreisner;10908267 wrote:

      I have a Crystal Reports 2008 report that has one of the fields using a MICR truetype font. If I export to PDF within Crystal Reports the field shows properly. If I export the report to PDF using the COM interface my PHP application uses the field does not show using the MICR font.

      I've been using Crystal Reports 2008 w/ PHP for a while now with great success. Using the info from the php COM manual pages I can create Crystal Reports objects and call their functions from within PHP. (Source code below)

      If I go to the PDF properties with adobe reader:
      -The one generated using crystal reports application has the MICR font listed in the 'fonts used by the document' list
      -The one generated using the COM interface does not show that font.

      If I try other fonts: If the server has the font it shows up properly. If the server doesnt have the font then i experience the same issue as with the MICR font. The confusing thing is that I know the server and the client have the same MICR true type font (I installed them both). The font also can be verified to be operational on the server from within the Crystal Reports Application.

      The code sample shows a call to my generateReport method, which uses COM to create the PDF from the RPT and then return it to the user.

      <?php
      
      generateReport(array(1=>"1234567890"),getcwd()."/reports/check.rpt");		
      function generateReport($vals,$reportName){	  
      set_time_limit(300); //------ Variables ------ $output_pdf = "C:\\temp\\temp.pdf"; if(file_exists($output_pdf)) if(!unlink($output_pdf)) return "Failed to clear temp. please try again"; try{ $crapp = new COM("CrystalRunTime.Application"); if($crapp==null) return "Failed to access Crystal Reports"; $creport = $crapp->OpenReport($reportName, 1); $creport->EnableParameterPrompting = 0; $creport->DiscardSavedData; $creport->ReadRecords(); for($i=1;$i<=count($vals);$i++){ $field=$creport->ParameterFields($i); $res=@$field->SetCurrentValue($vals[$i]); if($res==0){ //success setting parameter value }else{ return "Failed to create report. Failed to set parameter $i with value ".$vals[$i]; } } $creport->ExportOptions->DiskFileName=$output_pdf; $creport->ExportOptions->FormatType=31;//constant for PDF export $creport->ExportOptions->DestinationType=1; $creport->Export(false); if(file_exists($output_pdf)){ $pdf=file_get_contents($output_pdf); if(strlen($pdf)!=filesize($output_pdf)) return "Error: filesize=".filesize($output_pdf)." strlen=".strlen($pdf); header("Pragma: "); header("Cache-Control: "); header("Content-type: application/pdf"); header("Content-Disposition: attachment;filename=".extractName($reportName).".pdf"); // For IE echo($pdf); exit(); }else return "Failed to export"; }catch(Exception $e){ return "Failed to connect to Crystal Reports 2008: $e"; } } ?>

      PS: Sorry for the longwinded question.

      Well dear,
      I have used this code to open the report but it is not working.
      I have called this function onsubmit event of the button.
      What should i do??
      Please guide me step by step that how this function should i use.
      Thanx

        2 years later

        How are you using CR2008? COM was phased out of Crystal after XIR2. I'm trying to use CR2008 but can't get COM to work and I don't want to switch to XIr2.

          Write a Reply...