Crystal Report Custom Paper Size and Custom Paper Source Problem (Urgent)

Locked Crystal Report Custom Paper Size and Custom Paper Source Problem (Urgent)

  • Thursday, June 28, 2007 2:12 AM
     
     

    Hi,

     

    I'm doing some letter 2 up repot using visual studio .net 2005 with crystal report.

    I'm using c# language to do the report.

     

     

    I have set the custom paper size with 8.5x5.5 inch in the client pc in the server propertise in the printer section.

     

    as the report size i'm doing is half page of letter and i can't find the paper name in the papersize collection in the crystal report library file.

     

    PrintDocument printDoc = new PrintDocument();

    PaperSize pkSize = new PaperSize();

    int rawKind = 0;

    for (int a = 0; a < printDoc.PrinterSettings.PaperSizes.Count; a++)

    {

    if (printDoc.PrinterSettings.PaperSizesAngel.PaperName == "8.5x5.5")

    {

    rawKind = (int)printDoc.PrinterSettings.PaperSizesAngel.GetType().GetField("kind", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(printDoc.PrinterSettings.PaperSizesAngel);

    }

    }

    oRpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;

     

    i didn't not define the printer name in my souce code. when i run this code, system will get default printer to get the paper size collection to get the custom paper size i want.

    when i get the custom paper size ID then i fix the ID in the crystal report.

     

    i can ge the correct paper size when i preview the report.

    but when i click the print button after preview the report, the printer use letter size to print out the report instead of using the custom size i define.

     

    i did do some testing in the client pc. If i set the default paper size to the custom paper name i define in the client pc and the paper source to manual feed paper. when i use dirent printtoprinter. it works fine to print out in half page report.

    but if i preview the report and go to print, it will print out in the letter size paper instead of the half page letter size.

     

     

    anyone can help me to solve this poblem ??? i'm already headache with this and got no idea on how to solve it .

     

All Replies

  • Monday, October 08, 2007 1:30 AM
     
     

    I am stuck on this exact same problem.. please HELP!

  • Tuesday, April 15, 2008 11:00 AM
     
     

    I was also facing the same problem...... But now i got the solution.

     

    The above stated sample is very true except one line.... please follow this step. It may help u.

     

     

    System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
                for (int a11 = 0; a11 < pd.PrinterSettings.PaperSizes.Count; a11++)
                {
                    if (pd.PrinterSettings.PaperSizes[a11].PaperName == "Invoice")  // Invoice is your paper name that you created
                    {
                        InvoiceRawKind = (int)pd.PrinterSettings.PaperSizes[a11].RawKind;
                        break;
                    }
                    else
                        InvoiceRawKind = 0;
                }

     

    after this set the paper size of report document with this Invoicerawkind object using cast.

  • Wednesday, April 16, 2008 1:04 AM
     
     

     

    which line you mention miss out from the sample code above ?

     

  • Wednesday, April 16, 2008 4:08 AM
     
     

    Dear fongye,

     

    This is the line....
    {
    rawKind = (int)printDoc.PrinterSettings.PaperSizes.GetType().GetField("kind", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(printDoc.PrinterSettings.PaperSizes);

    }

    try this... that i had mention in my prev. thread

      InvoiceRawKind = (int)pd.PrinterSettings.PaperSizes[a11].RawKind;
                        break;

     

  • Thursday, April 17, 2008 2:49 AM
     
     

     

    My code as below

     

    oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

    PrintDocument printDoc = new PrintDocument();

    PaperSize pkSize = new PaperSize();

    int rawKind = 0;

    for (int a = 0; a < printDoc.PrinterSettings.PaperSizes.Count; a++)

    {

    if (printDoc.PrinterSettings.PaperSizesAngel.PaperName == "8.5x5.5")

    {

    rawKind = (int)printDoc.PrinterSettings.PaperSizesAngel.RawKind;

    break;

    }

    }

    oRpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;

     

    oRpt.SetDataSource(dtBatchRep);

    oRpt.PrintToPrinter(1, true, 1, 99);

     

     

    this is the complete code that i have in my system. when i deploy my program in another pc. i need to go to the Printer and Fax setting in the Server Propertise there, add in a new form with the size i want 8.5 Inch x 5.5 Inch with the file name "8.5x5.5".

     

    I try to run the program in debug mood. The system able to search for the customize paper size i set in the server propertise.

     

    I'm able to preview the report with the correct file size i want.

    but if i send direct to printer with the code

     

    oRpt.PrintToPrinter(1, true, 1, 99);

     

    then the printer will print the report as letter size, it will not print as 2 up paper size as what i want.

     

    can tell me more details of how you make it ?

    any setting that i need to do for it ?

     

  • Thursday, April 17, 2008 11:25 AM
     
     

    Dear fongye,

     

    I got your point. There is nothing wrong with your code. This code is absolutly true but you are trying to print directly on the printer.


    Whenever you use default setting of printer with reports it works fine but if you try to overide some or one of the printer settings in report you have to specify the same setting for printing too.

    In case you override Printer setting for report.then you have to specify same setting for printing too. You your case (above specify code) you have change one printer setting for report only but not for printing. If You want to test this thing comment below line

    // oRpt.PrintToPrinter(1, true, 1, 99);


    and print the report from the report viewer you will see whatever you have set the default settings for the printer it's get override and comes the papersize to "Leter".

    To win this situation you have to use copyfrom method which is reportdocument.Printoption object. With this u can set the printer setting and papersize.

    System.Drawing.Printing.PrinterSettings ps =new System.Drawing.Printing.PrinterSettings();
    System.Drawing.Printing.PaperSize psize =new System.Drawing.Printing.PaperSize();

    // specify all the necessary properties

    and then call rpt.Printoption.CopyFrom(ps,psize)

    This will copy all the settings from ps & psize to report printing option and then go for oRpt.PrintToPrinter(1, true, 1, 99);

    Note:

    If you specify and user define paper size from server properties in printers and create your own paper size then this will not work.

    I will suggest you to check your paper size in below two enum objects. You can use nearly equal to paper size

    CrystalDecisions.Shared.PaperSize.Paper10x14; --- this contains some paper size
    System.Drawing.Printing.PaperKind.A5Rotated;  --- this contains more then prev. one

     

    I got this one for 8.5" x 6"

    rpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)System.Drawing.Printing.PaperKind.A5Rotated;

     

     

  • Friday, April 18, 2008 2:07 AM
     
     

    Hi,

    Thanks for your reply.

    I have do some testing, and i found that the crystal report will only accept those report pre-define in the CrystalDecisions.Shared.PaperSize object.

     

    Those paper size define in the object System.Drawing.Printing.PaperKind is unable to cast as one of the paper size in crystal report.

     

    The above code is able to help me to get the correct size when preview the report in using crystal report.

     

    but if i send direct to printer or click the print button after preview the report. both action i cannot get the correct paper size and send to printer.

     

    actually after add in the customize paper size in the server propertise, i'm able to select the paper size in those printer propertise > advance setting > paper size combo box.

     

    Is that any way that i can select those paper size and overwrite the default paper size setting in the printer when send direct print to the printer or click the print button after preview the report.

     

    I think this is the answer most of the ppl looking forward.

     

    cause user is lasy to select the correct paper size in the printer propertise each time when they print the report.

     

  • Friday, April 18, 2008 4:11 AM
     
     

    Hi Dear,

     

    you are absolutly true those paper size define in the object System.Drawing.Printing.PaperKind is able to cast as one of the paper size in crystal report. but used only in preview of report not for the printer.

     

    but if you would like to send directly to printer you have to use printdialog class which will invoke printer dialog and then further assign printerdialog.printersettings to printersetting object.

     

    PrintDialog pDialog =new PrintDialog();

    PrinterSettings pSettings =new PrinterSettings();

    pDialog.ShowDialog();

    pSettings = pDialog.PrinterSettings; // apply all the settings to pSettings as per user specified like printer,papersize,etc

    PageSettings pSize= PageSettigns(pSettings); // (not sure weather PageSetting / PageSize u just check it)

     

    with the hellp of above code you will get printersettings and papersizes

     

    Now call the rpt Object.

     

    rpt.PrintOptions.CopyFrom(pSettings,pSize);

     

    this line will help u to copy all the printer settings and paper size from to rpt object printing purpose only. you just try this and take those paper size which is predefine it will work but when u take ur own paper size created through server properties it won't be able to change the paper size it comes to default form ( default paper)

     

    You can see this with the help of watch window  (rpt.PrintOptions --- see details)

    or more closer look at

     

    http://technicalsupport.businessobjects.com/cs/forums/thread/831.aspx

     

    If you got any solution for direct printing then please help me too....

     

    If you think my suggestion was helpfull to you then please quote me.

     

  • Thursday, April 24, 2008 6:33 AM
     
     

     

    Hi MSDN  ,

    I am having bitmap's with sizes according to papersizes (A4,A3,B4,B3 ,Executive,....) .Now i want the particular bitmap to print on the paper.The type of paper will choose instantly according to bitmap Size .

     

    Only for the first time if i give it to printer (Acrobat Distiller ) is printing according to paper type i.e., different papers with sizes  . From the next time it is taking the default one i.e, Letter .for the printpreview and printer . I am getting the pages according to orientation .

     

    For this i wrote in this way ...

    I am setting the page orientation , papersize in the Querypagesettings Event .

     

    Code Snippet

    If GetPageDetails(0) = 0 Then

    GetPageDetails(1) is having the PaperName

    e.PageSettings.Landscape = False

    PageSetupDialog1.PageSettings.PaperSize.RawKind = Cint(PageKind(GetPageDetails(1)))  ' Here it will get teh paperkind

    PrintDocument1.DefaultPageSettings.PaperSize.RawKind =PageSetupDialog1.PageSettings.PaperSize.RawKind

     

    ElseIf GetPageDetails(0) = 1 Then

     

    e.PageSettings.Landscape = True

    PageSetupDialog1.PageSettings.Landscape = True

    PageSetupDialog1.PageSettings.PaperSize.RawKind = Cint(PageKind(GetPageDetails(1)))

    PrintDocument1.DefaultPageSettings.PaperSize.RawKind = PageSetupDialog1.PageSettings.PaperSize.RawKind

    End If

     

     

    Private Function PageKind(ByVal PageName As String) As Drawing.Printing.PaperKind

    this function returns pagekind .i.e., (A4,A3,B4,B3 ,Executive,....)  and i am converting that to integer value and assinging to it . But it is not printing with paper kind . that is the problem i am facing ................it is taking the default ' Letter ' to print to printpreview or printer.

     

     

    in PrintPageEvent ....

    Code Snippet
    e.Graphics.DrawImage(bm(iImagePerPage), 0, 0, e.MarginBounds.Width, e.MarginBounds.Height)

     

     

    1) How can i set the papersize according to paper Kind ??

     

    2) How can i set the margins according to paper size (A4,A3,B4,B3 ,Executive,....) in the print ??so that my bitmap fit exactly to that paper ??????????

     

    Thanks & Regards ,

     

  • Tuesday, April 29, 2008 6:55 AM
     
     
    Hi there Ppls,

    Sorry to bother in, but I got the same problem when trying to implement a customer paper size.

    Here is the problem, I'm developing a POS system for my thesis but my professor wants to generating a report or invoice sale report using a contunues paper. I don't know know to implement this by try to make the length of the pape dynamic.

    My Prof. told me that when ever you shop at a dept. store it would generate a receipt. The receipt contains the items you bought. I followed all the step that
    ManishChourasia said, but i cannot implement the method that would generate a report with dynamic paper Length.

    Can some one help me with this?

    thanks alot..








  • Tuesday, April 29, 2008 10:32 AM
     
     

     

    Hi itanacious

     

    What do u mean "invoice sale report using a contunues paper" elobrate ur problem

     

    Manish

  • Saturday, May 17, 2008 2:46 PM
     
     
    lm using a Epson LX 300 printer and using a

    Continues paper, when ever I generate invoice Report.


    Now I have a hard time on how to set my Paper Size to Width = 4 and the Length to be a dynamic.

    Meaning If the Data of the Invoice Report can fill up a Lenght 15 inches then the Custom paper size will be
    4 X 15. and  If the Data of the Invoice Report can fill up only to the length of 4 inches then the Custom paper size will be
    4 X 4.

    So is there anyway possible to set the Length of the Paper Size to be Dynamic.
    and by the way the LX 300 can print to a paper with minimum size of 4 X 4 to the maximum paper size 11 X 22






  • Friday, July 04, 2008 8:30 AM
     
     
     I use vs2003 and crystal report XI R1, this code is work

    PrintDocument printDoc = new  System.Drawing.Printing.PrintDocument();

    int i;
    int rawKind = 0;
       
    for (i= 0; i<printDoc.PrinterSettings.PaperSizes.Count; i++)
    {
      if (printDoc.PrinterSettings.PaperSizes[i].PaperName =="5 x 5.5")
      {
       rawKind = (int) GetField(printDoc.PrinterSettings.PaperSizes [i],"kind");

      }
    }
    crReportDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
    crReportDoc.PrintToPrinter(1,true,1,999);


    private  object GetField(Object obj,String fieldName )
    {          
     System.Reflection.FieldInfo  fi  = obj.GetType().GetField(fieldName,BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     return fi.GetValue(obj);



    I get many idea from many people in this forum
    thank you

  • Thursday, January 29, 2009 4:08 AM
     
     
     lm using a Epson u220 printer and need to print Continues paper, when ever I generate invoice Report.

    Now I have a hard time on how to set my Paper Size to Width = 5 and the Length to be a dynamic.

    Meaning If the Data of the Invoice Report can fill up a Lenght 25 inches then the Custom paper size will be
    5 X 25. and  If the Data of the Invoice Report can fill up only to the length of 10 inches then the Custom paper size will be
    5 X 10.

    So is there anyway possible to set the Length of the Paper Size to be Dynamic.
  • Friday, January 30, 2009 6:07 AM
     
     

    yes i got the solution. if you use Epson U220, you can select User Defined paper size. it you give 9998 as page width it should work fine.

    Note you have to chage layout in gentral tab & advanced tab. As well dont forget to select paper conservation is "bottom". other wise it will print long page with out cut.

    Thanks

  • Thursday, September 10, 2009 6:04 AM
     
     
    lm using a Epson LX 300 printer and using a

    Continues paper, when ever I generate invoice Report.


    Now I have a hard time on how to set my Paper Size to Width = 4 and the Length to be a dynamic.

    Meaning If the Data of the Invoice Report can fill up a Lenght 15 inches then the Custom paper size will be
    4 X 15. and  If the Data of the Invoice Report can fill up only to the length of 4 inches then the Custom paper size will be
    4 X 4.

    So is there anyway possible to set the Length of the Paper Size to be Dynamic.
    and by the way the LX 300 can print to a paper with minimum size of 4 X 4 to the maximum paper size 11 X 22







    Hi !

    I am also using same printer.But I do not get Custom Paper size Option.Can You help how to print my Invoice in half of A4 paper size.

    Pankaj
  • Tuesday, March 16, 2010 6:33 AM
     
     

    Hi,

    Thanks for your reply.

    I have do some testing, and i found that the crystal report will only accept those report pre-define in the CrystalDecisions.Shared.PaperSize object.

     

    Those paper size define in the object System.Drawing.Printing.PaperKind is unable to cast as one of the paper size in crystal report.

     

    The above code is able to help me to get the correct size when preview the report in using crystal report.

     

    but if i send direct to printer or click the print button after preview the report. both action i cannot get the correct paper size and send to printer.

     

    actually after add in the customize paper size in the server propertise, i'm able to select the paper size in those printer propertise > advance setting > paper size combo box.

     

    Is that any way that i can select those paper size and overwrite the default paper size setting in the printer when send direct print to the printer or click the print button after preview the report.

     

    I think this is the answer most of the ppl looking forward.

     

    cause user is lasy to select the correct paper size in the printer propertise each time when they print the report.

     

    Is there any solution to this problem pointed by Fongye as abolve?

    I am having the same problem.  
  • Wednesday, April 14, 2010 3:26 AM
     
     

    Yes, I just find the solution.

    Dim

     

    printSettings As System.Drawing.Printing.PrinterSettings = PrintDialog1.PrinterSettings.Clone

    MonRapport.PrintOptions.PaperSize = PrintSettings.DefaultPageSettings.PaperSize.Rawkind

     

    or

     

    Dim printSettings As System.Drawing.Printing.PrinterSettings = PrintDialog1.PrinterSettings.Clone

    MonRapport.PrintOptions.PaperSize = PrintSettings.DefaultPageSettings.PaperSize.Rawkind

    MonRapport.FormatEngine.PrintOptions.PaperSize = PrintSettings.DefaultPageSettings.PaperSize.Rawkind

     

    I don't know why, when I'm not on debuger mode the line (MonRapport.PrintOptions.PaperSize = PrintSettings.DefaultPageSettings.PaperSize.Rawkind)  the data doesn't update., it's why I add the other to.

     

    Good luck.

     

    Frank,