Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have written a code to print the PDF document Directly. During this ADOBE is opening. Can any one tell me how to print the PDF without opening adobe.I found some articles but not worked for me...Here is my code

C#
private void SendToDirectPrint(string filename)
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.Verb = "print";
            info.FileName = filename;
            info.CreateNoWindow = true;

            info.WindowStyle = ProcessWindowStyle.Hidden;

            Process p = new Process();
            p.StartInfo = info;
            p.Start();

            if (p.HasExited == false)
            {
                p.WaitForExit(10000);
            }

            p.WaitForInputIdle();
            if (false == p.CloseMainWindow())
                p.Kill();
        }
Posted

 
Share this answer
 
You can use this code for aspx
----------------------------------------------------------------------------------

 <script type="text/javascript" language="javascript">

        function fnPrint() {
            var a = window.open('', '', 'left =' + screen.width - 100 + ',top=' + screen.height - 10 + ',width=0,height=0,toolbar=0,scrollbars=0,status=0');
            a.document.write(document.getElementById('receipt').innerHTML);
            a.document.close();
            a.focus();
            //call print
            a.print();
            a.close();

        }
      
    </script>
 
Share this answer
 
v2
For Extjs :

-----------------------------------------------------------------------------------
   text: '' + printReceipt_lbl + '',
                 handler: function () {
                     var txthidenAmountToPay = Ext.getCmp('txtAmountToPay').getValue();
                     var Credit = Ext.getCmp('txtCredit').getValue();
                     var OsAmount = Ext.getCmp('txtOsAmount').getValue();
                     var RecNo = TrimString(Ext.getCmp('txtRecNo').getValue());
                     window.open('../Certificates/BillReceipt.aspx?BillNo=' + RecNo + '&AmountToPay=' + txthidenAmountToPay +
                 '&Credit=' + Credit + '&OsAmount=' + OsAmount, 'name', 'height=800,width=700,scrollbars=1');

                 }
 
Share this answer
 
v3
function fnPrint(Quotation_project) {
            // window.print();
            var txtOrg_id = Ext.getCmp('txtOrg_id').getValue();
      var txtQuotation_no = Ext.getCmp('txtQuotation_no').getValue();
      var DtDate = (Ext.Date.format(Ext.getCmp('dtDate').getValue(), 'd/m/Y'));
      var txtAddress = Ext.getCmp('txtAddress').getValue();
      var cmbHeadInvoice=Ext.getCmp('cmbHeadInvoice').getValue();
      var txtFinancial_year = Ext.getCmp('txtFinancial_year').getValue();
      var txtInvoice_number = Ext.getCmp('txtInvoice_number').getValue();
      var txtQuotation_amount = Ext.getCmp('txtQuotation_amount').getValue();
     
      var txtInvoice_amount= Ext.getCmp('txtInvoice_amount').getValue();
      var txtStatus= Ext.getCmp('txtStatus').getValue();
      var txtPending_amount= Ext.getCmp('txtPending_amount').getValue();
      var txtCustomer_name= Ext.getCmp('txtCustomer_name').getValue();
      var txtContact_person= Ext.getCmp('txtContact_person').getValue();
     
      var txtEmail= Ext.getCmp('txtEmail').getValue();
    
    //  alert(Tproduct);
          var htmlMarkup=[
''+
'<html xmlns="http://www.w3.org/1999/xhtml">'+
'<head>'+
''+
'body {'+
'	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;'+
'	margin: 0;'+
'	padding: 0;'+	
'}'+
'h1, h2, h3, h4, h5, h6, p {'+
'	margin-top: 0;	'+
'	padding-right: 15px;'+
'	padding-left: 15px;'+ 
'}'+
'.container {'+
'	width: 80%;'+
'	max-width: 1260px;'+
'	min-width: 780px;'+
'	background: #FFF;'+
'	margin: 0 auto;'+
'}'+
'</head>'+
'<body>'+
''+
 ' '+
  '   '+
   '  INVOICE      '+
    ' Solutions Private Limited.                                                   Date : '+DtDate+' '+
    '  #21,  1st Floor, Rajashree Mansion                                                      Invoice No:'+txtInvoice_number+''+
     ' ABC  Nagar'+
      ' Main Road'+
      ' 7th Phase,'+
      'Bangalore  512121'+
      ' Ph:  +91 80 1124554'+
'Delivery  Address:'+
''+txtCustomer_name+''+
''+txtAddress+' '+
''+
'Comments or special  instructions:'+
''+
  ''+
   ''+
    ''+
    ''+
   
    ''+
  ''+
  ''+
    ''+
    ''+
    ''+
    ''+
  ''+
'Quotation NumberProduct NmeQuotation AmountInvoice Amount'+txtQuotation_no+''+Quotation_project+''+txtQuotation_amount+''+txtInvoice_amount+'    '+
   '      '+
    'Make all cheques payable to  Solutions Private Limited.'+
    'If you have any questions  concerning this invoice, contact ['+txtContact_person+' '+txtEmail+']'+
    ' '+
    ' THANK YOU FOR YOUR BUSINESS!'+
    ''+
     ' '+
    ''+
    'For  Solutions Pvt Ltd'+
    'Pad'+
    'Managing Director'+
  ''+
'</body>'+
'</html>'
  ];
            var a = window.open('', '', 'left =' + screen.width + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=1,status=0');
  a.document.write(htmlMarkup);
            a.document.close();
            a.focus();
            //call print
            a.print();
}
 
Share this answer
 
Your code will print the pdf to a printer attached to the SERVER where your ASP.NET website is hosted. Is that what you want? I mean, or do you want to print to the client printer?
If printing to the server printer then install FoxIt Reader instead of using Adobe Reader. FoxIt will not open when printing from command line.
 
Share this answer
 
Comments
Pambala 3-Dec-14 0:52am    
Thank you.yeah i tested on FoxIt Reader its works on it.but they didn't like to go FoxIt Reader that the problem. thank you again your answer.
register to http://pdfcrowd.com/
protected void img_Click(object sender, ImageClickEventArgs e)
    {
System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
     try
       {
        var Date = Request.QueryString["Date"].ToString();
        var Org_name = Request.QueryString["Org_name"].ToString();
        var Org_Address = Request.QueryString["Org_Address"].ToString();
        ------------ 
        ------------


// create an API client instance
            pdfcrowd.Client client = new pdfcrowd.Client("username", "password");
//username & password should be given when registration and there are only 150 //converstion is free

            // convert a web page and write the generated PDF to a memory stream
            MemoryStream Stream = new MemoryStream();

            // string sunil = Request.QueryString["test1"].ToString();
            //  string html = "<head></head><body>My HTML Layout" + Request.QueryString["Date"] + "</body>";
            string html = @"

<head>
----------------
---------------

</head>

</body>
</html>


";
client.convertHtml(html, Stream);



            // set HTTP response headers
            Response.Clear();
            Response.AddHeader("Content-Type", "application/pdf");
            Response.AddHeader("Cache-Control", "max-age=0");
            Response.AddHeader("Accept-Ranges", "none");
            Response.AddHeader("Content-Disposition", "attachment; filename=Sample_Letter.pdf");

            // send the generated PDF
            Stream.WriteTo(Response.OutputStream);
            Stream.Close();
            Response.Flush();
            Response.End();
 }
        catch (pdfcrowd.Error why)
        {
            Response.Write(why.ToString());
        }
    }
 
Share this answer
 
v5
For VB .Net I found this:

VB
Private Sub PrintTestPages()
        Dim oProcess As New System.Diagnostics.Process
        With oProcess.StartInfo
            .CreateNoWindow = True
            .WindowStyle = ProcessWindowStyle.Hidden
            .Verb = "print"
            .Arguments = "Actual Size"
            .UseShellExecute = True
            .FileName = "c:\mydocumentfolder\test.pdf"
        End With
        oProcess.Start()
    End Sub


Originally from: [FAQ's: OD] How do I print a document without opening it?-VBForums[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900