Print alv report directly to spool  from a badi method

Hallo !
I am trying to save a log in spool on converting process
I am doing on Idoc data in Method of Badi implementation
(badi : HRALE00OUTBOUND_IDOC).
The spool request is created but the list there contains
no data.
Here is the code I put in the badi method :
DATA: LS_PRINT      TYPE  SLIS_PRINT_ALV,
      LV_REPID      LIKE SY-REPID,
      LS_LAYOUT     TYPE SLIS_LAYOUT_ALV,
      LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      LS_FIELDCAT LIKE LINE OF LT_FIELDCAT.
  LV_REPID  = SY-REPID.
SET LS_LAYOUT :
  CLEAR LS_LAYOUT.
SET LS_PRINT :
  CLEAR LS_PRINT.
  LS_PRINT-PRINT = 'N'.
SET LT_FIELDCAT :
  REFRESH LT_FIELDCAT.
  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-FIELDNAME = 'MESSAGE'.
  LS_FIELDCAT-SELTEXT_L = 'MES'.
  APPEND LS_FIELDCAT TO LT_FIELDCAT.
CREATE LOG IN SPOOL :
  SY-BATCH = 'X'.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM      = LV_REPID
      IS_LAYOUT               = LS_LAYOUT
      IT_FIELDCAT            = LT_FIELDCAT[]
      I_DEFAULT                    = 'X'
      I_SAVE                       = 'X'
      IS_PRINT                = LS_PRINT
    TABLES
      T_OUTTAB                = PT_LOG[]
    EXCEPTIONS
      PROGRAM_ERROR           = 1
      OTHERS                  = 2.
  IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
I have to remark that when I call this code in
an ABAP-PI function the log is created successfully in spool.
But here I call it from a method of IDOC Badi exit -
and the list is empty ....
The two cases are in processes that run in batch ...
Maybe ALV function can't be called from a method ?
Maybe I should use Object-Oriented ALV ?
Or maybe I fill the ALV function parameters in a wrong way  ?
I really appreciate your help ,
Thanks in advance -
  Nitzan S.

Hey,
I am not sure if from the ALV list the SPOOL will be created properly. You said the spool is created but the spool is empty.
A Work around could be create a classical report with WRITE statements and then SUBMIT that report exporting the list into memory or you can even read the spool then.
Regards,
Ravi
Note :Please mark the helpful answers

Similar Messages

  • Print ALV report Directly - without the Print Parameter POPUP

    Hai All,
    I want to print a ALV directly to the printer without the Print Paramter POPUP.
    I passed on IS_PRINT parameters in the FM 'REUSE_ALV_LIST_DISPLAY'.
    But still i am getting the popup.
    How to do this.
    It is urgent .
    Kindly help me solving this.
    Vikki.

    Hi,
    i have passed IS_Print-Print = 'X'.
    But even after that i am getting the print parameter popup.
    IS there any other way to handle this. TO SUPPRESS THE PRINT PARAMETER POPUP.
    Please guide me.
    Waiting for ur replies.
    Vikki.

  • How to send a report directly to spool..?

    Hi guyz !
       How do i send a normal report directly to spools at execution.
       Please advise .
    Thanks in adv.
    jahan

    hi,
    The easiest way of printing a list while creating it, is for the user to choose Execute + print on the report's selection screen. The user can choose between displaying the list on the screen (choosing Execute) or printing it directly without displaying it (choosing Execute + print).
    use this function module <b>SET_PRINT_PARAMETERS'</b> to send a report directly to spool.
    <b>sample program.</b>
    REPORT SAPMZTST NO STANDARD PAGE HEADING LINE-COUNT 0(2).
    PARAMETERS P TYPE I.
    INITIALIZATION.
      CALL FUNCTION 'SET_PRINT_PARAMETERS'
           EXPORTING
                ARCHIVE_MODE   = '3'
                COPIES         = '5'
                DEPARTMENT     = 'BASIS'
                DESTINATION    = 'LT50'
                EXPIRATION     = ' '
                IMMEDIATELY    = 'X'
                LAYOUT         = 'X_65_132'
                LINE_COUNT     = 54
                LINE_SIZE      = 20
                LIST_NAME      = 'Test'
                LIST_TEXT      = 'Test for User''s Guide'
                NEW_LIST_ID    = 'X'
                RECEIVER       = 'KELLERH'
                RELEASE        = ' '
                SAP_COVER_PAGE = 'X'.
    START-OF-SELECTION.
      DO P TIMES.
        WRITE / SY-INDEX.
      ENDDO.
    TOP-OF-PAGE.
      WRITE: 'Page', SY-PAGNO.
      ULINE.
    END-OF-PAGE.
      ULINE.
      WRITE: 'End of', SY-PAGNO.
    <b>or</b>
    Printing Lists
    You can send a list from a called program directly to the spool system instead of displaying it on the screen. To do this, use the TO SAP-SPOOL addition in the SUBMIT statement:
    <b>SUBMIT... TO SAP-SPOOL print-parameters.</b>
    <b>follow this link for more information.</b>
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dba54635c111d1829f0000e829fbfe/content.htm
    regards,
    Ashokreddy.

  • Print RDLC Report Directly to Printer with SubReports!

    I am currently printing a report directly to the default printer using the code from this link. 
    http://msdn.AddHandler
    ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubreportProcessingEventHandler
    and this code:
    Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
    Dim zrpt = e.ReportPath
    Select Case zrpt
    Case "WOPartsSubReport"
    Dim ds1 As New WOPartsSubReportDataSet
    Dim da1 As New WOPartsSubReportDataSetTableAdapters.wopartsTableAdapter
    da1.Fill(ds1.woparts)
    e.DataSources.Add(New ReportDataSource("DataSet1", ds1.Tables("woparts")))
    Case "WOLaborSubReport"
    Dim ds2 As New WOLaborSubReportDataSet
    Dim da2 As New WOLaborSubReportDataSetTableAdapters.wolaborTableAdapter
    da2.Fill(ds2.wolabor)
    e.DataSources.Add(New ReportDataSource("DataSet1", ds2.Tables("wolabor")))
    Case "WOLockoutSubReport"
    Dim ds As New WOLockOutSubReportDataSet
    Dim da As New WOLockOutSubReportDataSetTableAdapters.wolockTableAdapter
    da.Fill(ds.wolock)
    e.DataSources.Add(New ReportDataSource("DataSet1", ds.Tables("wolock")))
    End Select
    End Sub
    But now that I am NOT using a reportviewer how can I still get the subreports to work and still print directly to the printer?  Where would I put the code to do that?
    Thanks,
    Stacy

    Hi Stacy,
    Sorry for the delay.
    It’s Christian that I have involved to help on this issue. Maybe the issue requires a more in-depth level of support. Alternatively, you could contact Microsoft Customer Support Services (CSS) via telephone so that a dedicated Support Professional can assist
    you in a more efficient manner. Please understand that contacting phone support will be a charged call, but it will be free if this is a product issue. To obtain the phone numbers for specific technology request please take a look at the web site listed below:
    http://support.microsoft.com/default.aspx?scid=fh;EN-US;PHONENUMBERS
    Another option would be creating a thread on our Connect site:
    http://connect.microsoft.com/sql.
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Can't print the report directly on the printer?

    Dear All,
    My client encounter a problem of printing a report directly to the printer. He is using developer 6i with OAS. His application is going to deploy on the web. He wants the report printed out directly on the "HP Laser Jet Printer" after the user has made the selection and clicked the "Print" button from the forms 6i. However, he got the error saying that
    "Oracle Report Server OWS Cartridge - Report Job has terminated with error
    Report Server Replies:
    Rep-0713: invalid printer name 'HP4050' specified by parameters DESNAME."
    And here is the parameter string passing into the report server:
    http://epmsdevs2.eway:9002/rwows/rwows60?report=epms1271.rdf+userid=epmsdev/epmsdev@dev+desformat=landscape+destype=printer+desname=HP4050+server=RepServer
    Is there anyone can show me some light on it?!
    Any help and idea is appreciated in advance!!!
    sheeta

    Hi!
    If reports are run in web env. then
    you can print reports directly on
    printer defined on m/c where report server
    is running, not on client m/c. If you want
    to print on client m/c then define that
    printer on report sever m/c and make sure
    report server can access that printer.
    Nirali

  • Printing a report directly to an printer via the printer's IP Address.

    I am looking for how to print a report (either text or pdf) from a PL/SQL procedure, directly to a known IP Address of a printer.
    We have a report that is generated through forms as a pdf. The user can then obviously read it and print it to a printer from their machine.
    We are trying to implement a Stored procedure that will print that report directly to a know printer's IP Address.
    How can this be done?

    Check out the orarrp utility (Oracle Reports Remote Printing Utility) on Metalink, note 277431.1.
    It may be easier in the end to set up printers on the OAS. I guess that client PC's are using network printers, or are the really using printers connected directly to the PC?

  • ALV report truncated in Spool

    Hi All,
    When i run the program in background, there will be a spool request generated. However the ALV report in this spool is truncated which all not fully display with the column i needed. ( approximated 600 chars)
    I have defined the line-size to 1000 in my program and create the new printer format type to X_65_1000, but it still unsuccesfully to display fully. Can anyone advise on this and what are the max size of width in the spool? 1023?

    Hi,
    Check the following link:
    /people/prashant.patil12/blog/2007/02/20/displaying-alv-grid-in-background-job
    Regards,
    Bhaskar

  • Printing ALV report

    Hi everyone,
    I have a report that was created with ALV, everything works fine until we print.
    When we print the report, it is printed in one page and that's ok, but the size is reduced, I mean the size is very small, any idea why we have this issue?.
    Thanks
    Eduardo Campos.

    HI Hduardo Campos,
    For printing ALV report or Normal report we need separte format while printing.
    Please fallow the fallowing steps to achieve your requirement.
    Steps:
    1. You have to create your own page format.
    SPAD-> Full Administration -> Device Types -> Page Formats -> Define the respective Page formats
    2. You have to define your own format type and attach the newly created page format to that.
    3. while creating the format type using existing script code from other formats.
    ( Here while wrting the script just test the font & font size as per your requirement)
    4. While ALV report printing select the Format option and enter your newly created format name( If you are not seeing report format option then select the properties option then select the report format then enter the required format name)
    fallow the above steps, so that you will able to print ALV report successfully.
    Still if you are facing any problem, let me know i will send you the detailed screen shots for the same.
    Right now in my current project i am using the same procedure and succesfuuly achieved the results.
    Regards,
    Rajani

  • Print BW report directly

    Hi Experts,
    we want to print a Report directly after clicking on print version. We don't want to first open the pdf file and then click another time on print. Is there any solution?
    The best solution would be, that we print automatically the report on our local printer after confirming the filter variables.
    Thanks for your help
    Sebastian

    There should be a javascript command, something like window.print, which you could put in the onLoad function of the page.
    The problem here is that it doesn't print in the nice PDF version.
    Cheers,
    Andrew

  • Print a report directly to the printer

    I need to print a report directly to the printer in Oracle Forms and Report 11g without a preview in the browser

    Hello,
    <p>You can use this Java Bean</p>
    Francois

  • Error - Printing a report directly to printer

    Hi,
    i'm using oracle forms 9i and i'm trying to print a report directly to printer. I using the code above:
    SET_REPORT_OBJECT_PROPERTY(ReportId,REPORT_DESFORMAT,'PDF');
    SET_REPORT_OBJECT_PROPERTY(ReportId,REPORT_SERVER,GetReportTnsName);
    IF ReportDesType = 'CACHE' THEN
    SET_REPORT_OBJECT_PROPERTY(ReportId,REPORT_DESTYPE,CACHE);
    ReportServerJob:=RUN_REPORT_OBJECT(ReportId, PList);
    rep_status := report_object_status(ReportServerJob);
    IF rep_status=’FINISHED’ THEN
    JobId := substr(ReportServerJob,length(GetReportTnsName)+2,length(ReportServerJob));
    WEB.SHOW_DOCUMENT ('/reports/rwservlet/getjobid'||JobId||'?server='||GetReportTnsName,'_blank');
    ELSE
    message ('Error’);
    END IF;
    -- logic for sending report directly to printer
    ELSIF ReportDesType = 'PRINTER' then
    SET_REPORT_OBJECT_PROPERTY(ReportId,REPORT_DESTYPE,PRINTER);
    SET_REPORT_OBJECT_PROPERTY(ReportId,REPORT_DESNAME,:parameter.p_print);
    ReportServerJob:=RUN_REPORT_OBJECT(ReportId, PList);
    rep_status := report_object_status(ReportServerJob);
    IF rep_status=’FINISHED’ THEN
    message ('Report sent to printer successfully');
    ELSE
    --handle errors
    message ('Error’);
    END IF;
    end if ;
    i get this error :
    REP-50157: Erro no envio do ficheiro para a impressora lp65. Sair com o código de erro 64
    NEED HELP !!
    Regards,

    The printer has to be known on the server where the Reports service runs.
    Also, the user who runs the Reports service has to have access to that printer. If you are running on Windows, Reports Service runs as Local system by default. Change that to a real (domain) user, who has access to the printer.

  • How to print a report directly on to a printer on the client machine

    Hi,
    Could anyone let me know how to print a report directly on to the clients default printer in oracle forms 10g with OAS?.
    Regards,
    Prasad.

    Hello,
    <p>You can use this Java Bean</p>
    Francois

  • Not able to take print a report directly to the printer

    Hi All,
    Can anyone help me to print a report directly to the printer?. Currently, I am viewing the reports in the screen and then taking print of that report. If anyone knows the solution for this, please give me the feedback immediately. It is very urgent.

    HI ALL
    i have the same problem plz tel me som solution 4 it
    thanx in advance

  • How to print the report directly without previewing (report viewer) using c# windows application

    Hi,
    Currently, we are using crystal report to all of our reporting applications, but since I/users have encountered some issues about CR's speed to load only a simple report, maybe it is now time for us to adopt a new reporting environment in which I think SSRS
    can fill this problem.
    To start with, I have here a sample code, that uses the crystal report to print the report directly without previewing:
    csCashInvoiceCal csCashCal; --Crystal report name .rpt
    dsCsReceipt dsCs; --created dataset
    DataTable u;
    DataRow s;
    private System.Drawing.Printing.PrintDocument printDocument1;
    private System.Windows.Forms.PrintDialog printDialog1;
    ParameterValues paramValue;
    ParameterDiscreteValue discreteValue;
    ParameterFieldDefinition fieldDefinition;
    private void btnPrint_Click(object sender, EventArgs e)
    this.Cursor = Cursors.WaitCursor;
    loadReceipt2();
    print2();
    csCashCal.Close();
    this.Cursor = Cursors.Default;
    private void loadReceipt2()
    dsCs = new dsCsReceipt(); --created dataset
    u = dsCs.Tables.Add("DtCsReceipt");
    u.Columns.Add("Qty", Type.GetType("System.String"));
    u.Columns.Add("UOM", Type.GetType("System.String"));
    u.Columns.Add("Description", Type.GetType("System.String"));
    u.Columns.Add("UnitPrice", Type.GetType("System.String"));
    u.Columns.Add("Discount", Type.GetType("System.String"));
    u.Columns.Add("Amount", Type.GetType("System.String"));
    try
    for (int i = 0; i < dgvDesc.Rows.Count - 1; i++)
    s = u.NewRow(); double.TryParse(dgvDesc.Rows[i].Cells[Discount2.Name].Value.ToString(), out discount);
    s["Qty"] = double.Parse(dgvDesc.Rows[i].Cells[Qty.Name].Value.ToString());
    s["UOM"] = dgvDesc.Rows[i].Cells[Uom2.Name].Value.ToString();
    s["Description"] = invcode + dgvDesc.Rows[i].Cells[Description.Name].Value.ToString();
    s["UnitPrice"] = dgvDesc.Rows[i].Cells[UnitPrice.Name].Value.ToString();
    if (discount != 0)
    s["Discount"] = "(" + string.Format("{0:0.##}", discount) + "%)";
    else
    s["Discount"] = "";
    s["Amount"] = dgvDesc.Rows[i].Cells[Amount2.Name].Value.ToString();
    u.Rows.Add(s);
    catch (Exception) { }
    csCashCal = new csCashInvoiceCal();
    csCashCal.SetDataSource(dsCs.Tables[1]);
    //csCashCal.Refresh();
    loadParameter2();
    private void loadParameter2()
    ParameterFieldDefinitions paramFieldDefinitions;
    paramValue = new ParameterValues();
    discreteValue = new ParameterDiscreteValue();
    paramFieldDefinitions = csCashCal.DataDefinition.ParameterFields;
    discreteValue.Value = date;
    fieldDefinition = paramFieldDefinitions["Date"];
    commonParam();
    discreteValue.Value = txtcsno.Text;
    fieldDefinition = paramFieldDefinitions["InvoiceNo"];
    commonParam();
    discreteValue.Value = txtNameTo.Text;
    fieldDefinition = paramFieldDefinitions["CustomerName"];
    commonParam();
    discreteValue.Value = txtAdd.Text;
    fieldDefinition = paramFieldDefinitions["CustomerAddress"];
    commonParam();
    ------other parameters----
    private void commonParam()
    paramValue.Clear();
    paramValue.Add(discreteValue);
    fieldDefinition.ApplyCurrentValues(paramValue);
    private void print2()
    using (printDocument1 = new System.Drawing.Printing.PrintDocument())
    using (this.printDialog1 = new PrintDialog())
    //this.printDialog1.UseEXDialog = true;
    this.printDialog1.Document = this.printDocument1;
    DialogResult dr = this.printDialog1.ShowDialog();
    if (dr == DialogResult.OK)
    int nCopy = this.printDocument1.PrinterSettings.Copies;
    int sPage = this.printDocument1.PrinterSettings.FromPage;
    int ePage = this.printDocument1.PrinterSettings.ToPage;
    string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
    try
    csCashCal.PrintOptions.PrinterName = PrinterName;
    csCashCal.PrintToPrinter(nCopy, false, sPage, ePage);
    printcount++;
    //saveCountPrint();
    catch (Exception err)
    MessageBox.Show(err.ToString());
    This is only a simple sales receipt application that uses dgv and textboxes to push its data to dataset to the crystal report, a simple one but there are instances that it is very slow.
    But I'm having trouble implementing this using SSRS, since I'm only new to this one, wherein I created the report using report wizard, with two button options inside the form for print preview or direct print selection. Actually, it is very easy to implement
    with print preview because it uses reportviewer. My problem is that how can I print the report directly without using a reportviewer?
    So here is my code so far which I don't know what's next:
    private void button2_Click(object sender, EventArgs e)
    this.Cursor = Cursors.WaitCursor;
    loadReceipt3();
    //print3();
    this.Cursor = Cursors.Default;
    ReportParameter[] parameter = new ReportParameter[11];
    private void loadParameter3()
    parameter[0] = new ReportParameter("InvoiceNo", txtcsno.Text);
    parameter[1] = new ReportParameter("Date", date);
    parameter[2] = new ReportParameter("CustomerTin", txtTin.Text);
    parameter[3] = new ReportParameter("CustomerName", txtNameTo.Text);
    parameter[4] = new ReportParameter("CustomerAddress", txtAdd.Text);
    parameter[5] = new ReportParameter("Agent", agent);
    parameter[6] = new ReportParameter("Discount", "Discount: ");
    parameter[7] = new ReportParameter("TotalDiscount", lblDiscount.Text + "%");
    parameter[8] = new ReportParameter("TotalSales", rdtotal);
    parameter[9] = new ReportParameter("Tax", rdtax);
    parameter[10] = new ReportParameter("TotalAmount", rdnet);
    private void loadReceipt3()
    DataSet dsrs = new DataSet();
    DataTable dtrs = new DataTable();
    DataRow drs;
    dtrs.Columns.Add("Qty", Type.GetType("System.String"));
    dtrs.Columns.Add("UOM", Type.GetType("System.String"));
    dtrs.Columns.Add("Description", Type.GetType("System.String"));
    dtrs.Columns.Add("UnitPrice", Type.GetType("System.String"));
    dtrs.Columns.Add("Discount", Type.GetType("System.String"));
    dtrs.Columns.Add("Amount", Type.GetType("System.String"));
    try
    for (int i = 0; i < dgvDesc.Rows.Count - 1; i++)
    drs = dtrs.NewRow();
    drs["Qty"] = double.Parse(dgvDesc.Rows[i].Cells[Qty.Name].Value.ToString());
    drs["UOM"] = dgvDesc.Rows[i].Cells[Uom2.Name].Value.ToString();
    drs["Description"] = invcode + dgvDesc.Rows[i].Cells[Description.Name].Value.ToString();
    drs["UnitPrice"] = dgvDesc.Rows[i].Cells[UnitPrice.Name].Value.ToString();
    if (discount != 0)
    drs["Discount"] = "(" + string.Format("{0:0.##}", discount) + "%)";
    else
    drs["Discount"] = "";
    drs["Amount"] = dgvDesc.Rows[i].Cells[Amount2.Name].Value.ToString();
    dtrs.Rows.Add(s);
    catch (Exception) { }
    int addtlRow = 7;
    if (addtlRow > (count - 1))
    addtlRow = addtlRow - (count - 1);
    for (int i = 0; i < addtlRow; i++)
    dtrs.Rows.Add();
    loadParameter3();
    LocalReport localreport = new LocalReport();
    localreport.SetParameters(parameter);
    localreport.DataSources.Clear();
    localreport.DataSources.Add(new ReportDataSource("dsSalesReceiptSsrs", dtrs));
    localreport.Refresh();
    //what's next....
    So what's next after local..refresh()? Actually, I have googled a lot but I didn't found the exact solution that I'm looking for which confuses me a lot.
    Anyway I'm using VS 2010 with sql server 2012 express.
    You're help will be greatly appreciated.
    Thank you,
    Hardz

    After some further studies with ReportViewer controls and with the use of this tutorial @ : http://msdn.microsoft.com/en-us/library/ms252091.aspx, which helps me a lot on how to print a report without using a report viewer, I found out what is missing
    with my code above and helps solve my question.
    Here's the continuation of the code above:
    private void loadReceipt3()
    loadParameter3();
    LocalReport localreport = new LocalReport();
    localreport.ReportPath = @"..\..\SsrsCashReceipt.rdlc";
    localreport.SetParameters(parameter);
    localreport.DataSources.Clear();
    localreport.DataSources.Add(new ReportDataSource("dsSalesReceiptSsrs", dtrs));
    Export(localreport);
    print4();
    private IList<Stream> m_streams;
    private int m_currentPageIndex;
    private void Export(LocalReport report)
    string deviceInfo =
    @"<DeviceInfo>
    <OutputFormat>EMF</OutputFormat>
    <PageWidth>8.5in</PageWidth>
    <PageHeight>11in</PageHeight>
    <MarginTop>0.25in</MarginTop>
    <MarginLeft>0.25in</MarginLeft>
    <MarginRight>0.25in</MarginRight>
    <MarginBottom>0.25in</MarginBottom>
    </DeviceInfo>";
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("Image", deviceInfo, CreateStream,
    out warnings);
    foreach (Stream stream in m_streams)
    stream.Position = 0;
    private void print4()
    if (m_streams == null || m_streams.Count == 0)
    throw new Exception("Error: no stream to print.");
    PrintDocument printDoc = new PrintDocument();
    PrintDialog printDlg = new PrintDialog();
    printDlg.Document = printDoc;
    DialogResult dr = printDlg.ShowDialog();
    if (dr == DialogResult.OK)
    if (!printDoc.PrinterSettings.IsValid)
    throw new Exception("Error: cannot find the default printer.");
    else
    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
    m_currentPageIndex = 0;
    printDoc.Print();
    Dispose();
    public void Dispose()
    if (m_streams != null)
    foreach (Stream stream in m_streams)
    stream.Close();
    m_streams = null;
    private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
    Stream stream = new FileStream(name + "." + fileNameExtension,
    FileMode.Create);
    m_streams.Add(stream);
    return stream;
    private void PrintPage(object sender, PrintPageEventArgs ev)
    Metafile pageImage = new
    Metafile(m_streams[m_currentPageIndex]);
    // Adjust rectangular area with printer margins.
    Rectangle adjustedRect = new Rectangle(
    ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
    ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY,
    ev.PageBounds.Width,
    ev.PageBounds.Height);
    // Draw a white background for the report
    ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
    // Draw the report content
    ev.Graphics.DrawImage(pageImage, adjustedRect);
    // Prepare for the next page. Make sure we haven't hit the end.
    m_currentPageIndex++;
    ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
    Thank you very much for this wonderful tutorial. :)

  • Print Crystal Report directly from C# without using Report Viewer

    Hello All,
    I need to print a crystal report directly to the printer without using ReportViewer in C#. I've a CrystalReport2(belowCode) which requires a query (Select * from JobHeader where JobNumber='J012345') to display all the data. I'm stuck with database connection
    and putting all the data to DataAdapter in C# (Below Code). I also have 8 subreports in my CrystalReport2. Can somebody please give me hand on this? I'm struggling with it. Thanks.
    Regards
    using CrystalDecisions.CrystalReports.Engine;
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlClient;
    namespace csharp_win_printtoprinter
    /// <summary>
    /// Summary description for Form1
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    //CR Variables
    ReportDocument crReportDocument;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.PrintDialog printDialog1;
    private System.Windows.Forms.Button button2;
    private System.Drawing.Printing.PrintDocument printDocument1;
    private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
    private CrystalReport1 CrystalReport11;
    private Chart Chart1;
    /// <summary>
    /// Required designer variable
    /// </summary>
    private System.ComponentModel.Container components = null;
    public Form1()
    // Required for Windows Form Designer support
    InitializeComponent();
    // TODO: Add any constructor code after InitializeComponent call
    /// <summary>
    /// Clean up any resources being used
    /// </summary>
    protected override void Dispose( bool disposing )
    if( disposing )
    if (components != null)
    components.Dispose();
    base.Dispose( disposing );
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor
    /// </summary>
    private void InitializeComponent()
    this.button1 = new System.Windows.Forms.Button();
    this.printDialog1 = new System.Windows.Forms.PrintDialog();
    this.button2 = new System.Windows.Forms.Button();
    this.printDocument1 = new System.Drawing.Printing.PrintDocument();
    this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
    this.Chart1 = new csharp_win_printtoprinter.Chart();
    this.CrystalReport11 = new csharp_win_printtoprinter.CrystalReport1();
    this.SuspendLayout();
    // button1
    this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.button1.Location = new System.Drawing.Point(32, 56);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(160, 104);
    this.button1.TabIndex = 0;
    this.button1.Text = "Print Report No Choose Printer";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // button2
    this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.button2.Location = new System.Drawing.Point(272, 56);
    this.button2.Name = "button2";
    this.button2.Size = new System.Drawing.Size(160, 104);
    this.button2.TabIndex = 1;
    this.button2.Text = "Choose Printer";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // crystalReportViewer1
    this.crystalReportViewer1.ActiveViewIndex = 0;
    this.crystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.crystalReportViewer1.Cursor = System.Windows.Forms.Cursors.Default;
    this.crystalReportViewer1.Location = new System.Drawing.Point(47, 188);
    this.crystalReportViewer1.Name = "crystalReportViewer1";
    this.crystalReportViewer1.ReportSource = this.CrystalReport11;
    this.crystalReportViewer1.Size = new System.Drawing.Size(903, 296);
    this.crystalReportViewer1.TabIndex = 2;
    // Form1
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(1164, 505);
    this.Controls.Add(this.crystalReportViewer1);
    this.Controls.Add(this.button2);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false);
    #endregion
    /// <summary>
    /// The main entry point for the application
    /// </summary>
    [STAThread]
    static void Main()
    Application.Run(new Form1());
    private void button1_Click(object sender, System.EventArgs e)
    crReportDocument = new ReportDocument();
    //Create an instance of a report
    crReportDocument = new CrystalReport2();
    //Use error handling in case an error occurs
    try
    //Set the printer name to print the report to. By default the sample
    //report does not have a defult printer specified. This will tell the
    //engine to use the specified printer to print the report. Print out
    //a test page (from Printer properties) to get the correct value.
    System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
    crReportDocument.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
    //Start the printing process. Provide details of the print job
    //using the arguments.
    crReportDocument.PrintToPrinter(0 ,true , 1, 1);
    //Let the user know that the print job is completed
    MessageBox.Show("Report finished printing!");
    catch(Exception err)
    MessageBox.Show(err.ToString(), "Unexpected exception");
    private void Form1_Load(object sender, System.EventArgs e)
    private void button2_Click(object sender, System.EventArgs e)
    //Open the PrintDialog
    this.printDialog1.Document = this.printDocument1;
    DialogResult dr = this.printDialog1.ShowDialog();
    if(dr == DialogResult.OK)
    //Get the Copy times
    int nCopy = this.printDocument1.PrinterSettings.Copies;
    //Get the number of Start Page
    int sPage = this.printDocument1.PrinterSettings.FromPage;
    //Get the number of End Page
    int ePage = this.printDocument1.PrinterSettings.ToPage;
    string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
    crReportDocument = new ReportDocument();
    //Create an instance of a report
    crReportDocument = new Chart();
    try
    //Set the printer name to print the report to. By default the sample
    //report does not have a defult printer specified. This will tell the
    //engine to use the specified printer to print the report. Print out
    //a test page (from Printer properties) to get the correct value.
    crReportDocument.PrintOptions.PrinterName = PrinterName;
    //Start the printing process. Provide details of the print job
    //using the arguments.
    crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);
    //Let the user know that the print job is completed
    MessageBox.Show("Report finished printing!");
    catch(Exception err)
    MessageBox.Show(err.ToString());

    1. This is a VB.Net forum not a Visual C# forum. For Visual C# questions try this forum.
    Visual C#
    2. Crystal Reports are not supported by Microsoft. Therefore, unless somebody responding in the Visual C# forum has experience with whichever version of Crystal Reports you are using, you will probably not receive an answer in the Visual C# forum. SAP has
    their own assistance for Crystal Reports using Visual Studio. You can try to find an appropriate forum to ask questions in at SAP in the below link.
    SAP Community Network
    La vida loca

Maybe you are looking for

  • How can i control the motor movement of stepper motor using a NI PXI 7330

    Good day to all, i'm a newbie in programming in motion control of NI. I just want to ask if how can i control the clockwise and counter-clockwise rotation of a stepper motor using NI PXI 7330 module. all i can do is the counter-clockwise rotation usi

  • Solaris 8: Error "access exceeded protections" - SEGV

    Hello: I getting this error " access exceeded protections" - SEGV, when I am doing a memset. The structure which is being memset is of 2M size. Code Snipets: abc_t abc; memset((char*)&abc, '\0', sizeof(abc_t)); The abc_t struct consists of many varia

  • How to populate formbean with ONLY updated values?

    Is there a way to populate the formbean with ONLY updated values in Java Struts? Ex: Out of 50 fields displayed on GUI, If lets say user modifies 20 fields, I need to capture only those 20 fields into the form bean. The reason i am looking for such f

  • RAPOST2000 error handling depreciation test run

    I have a problem with the error handling in ECC 6.0 (RAPOST2000). when I run a test run in foreground, the error list is diplayed nicely and i can doble click to see the problem for each asset. But as we have more than 1000 assets we have to run the

  • Does SunONE support Solaris 64 bits?

    Hi, I'm trying to make my app server run on 64bits mode on a Solaris 8 system. I've set the -d64 flag in the jvm options but it seems like it's being ignored. If I dump the system properties from a servlet, I can see sun.arch.data.model is 32. Any ot