I want to print a PDF in VS with C # without running ADOBE READER that only prints directly

0

I load the pdf in a GRID and print the documents that come out (If the query brings 2 = print those 2 PDFs) the problem is that it generates a lot of load in the server since it runs adobe to print each PDF and then I can not close the program I have to close by Task Manager. I use this DLL PdfPrintingNet.dll

public class imprimirmanifiesto
{
    public void imprimir(string dobleslash)
    {
        Process p = new Process();
        p.StartInfo = new ProcessStartInfo()
        {
            CreateNoWindow = true,

            Verb = "print",

            FileName = "C:\Users\bodega\Documents\Manifiestos\" + dobleslash + ".pdf"
        };
        p.Start();

    }
}

FOR THE PRINT BUTTON

private void button2_Click_1(object sender, EventArgs e)
    {
        r = new imprimirmanifiesto();
        int pos = 0;
        bool a = true;
        while (a == true)
        {
            try
            {
                if (string.IsNullOrEmpty(dataGridView1.Rows[pos].Cells[0].Value.ToString()))
                {
                    a = false;
                }
                else
                {
                    a = true;
                }
                r.imprimir(dataGridView1.Rows[pos].Cells[1].Value.ToString());
                pos++;
            }
            catch (Exception q)
            {

            }
        }
    }

CONSULTATION

public bool consultar(DataGridView grillita, Decimal factura, String tipo)
    {
        bool resultado = true;
        try
        {
            String consulta;
            OracleConnection con = new OracleConnection();
            OracleCommand comando;
            OracleDataReader lector;
            int cuenta = 1;
            int fila = 0;
            grillita.Rows.Clear();
            //con.ConnectionString = "Data Source = Duna02; User Id = DUNA; Password = duna; Unicode = true;";
            con.ConnectionString = "Data Source = QWERTY; User Id = DUNA; Password = QWERTY1; Unicode = true;";
            con.Open();
            consulta = "select DISTINCT ULTIMA_IMPORT, MI_ARTIC_FABRICA from CRM_MANIFIESTOS_02 join TIMOVIMIENTODETALLE on CRM_MANIFIESTOS_02.CODIGO = TIMOVIMIENTODETALLE.MV2_ARTIC where TIMOVIMIENTODETALLE.MV2_NUM ='" + factura + "' AND CRM_MANIFIESTOS_02.CODIGO = MV2_ARTIC AND MV2_TIPO ='" + tipo + "' order by CRM_MANIFIESTOS_02.ULTIMA_IMPORT asc";
            comando = new OracleCommand(consulta, con);
            lector = comando.ExecuteReader();
            while (lector.Read())
            {
                grillita.Rows.Add();
                grillita.Rows[fila].Cells[2].Value = lector.GetDecimal(0);
                grillita.Rows[fila].Cells[1].Value = "Manifiesto " + lector.GetDecimal(0) + "-" + lector.GetString(1);
                grillita.Rows[fila].Cells[0].Value = cuenta;
                fila++;
                cuenta++;
            }
            con.Close();
        }
        catch (Exception abc)
        {
            MessageBox.Show("Verifique número de importación y seleccione un tipo");
        }
        return resultado;
    }
    
asked by Saul Salazar 30.07.2018 в 17:52
source

1 answer

0

I made some changes to your code. First of all you need to know which executable run to adobe to run and print the file you want and then pass that same file between its parameters, the first route may vary so just adapt it to your conditions.

class Program
{
    static void Main(string[] args)
    {
        //Llamo el metodo estaticamente para imprimir el pdf que paso por parametro
        imprimirmanifiesto.imprimir(@"D:\Cursos\Neural_Networks_Using_C_Sharp_Succinctly.pdf");
    }
}

public class imprimirmanifiesto
{
    //Constante que representa la ubicación del ejecutable de AdobeReader en este caso es la carpeta
    public const string RUTA_ADOBE = @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader";
    //Hice la función estatica para no instanciarla, puedes removerlo y dejarlo a tu gusto
    public static void imprimir(string archivo)
    {
        Process p = new Process();
        p.StartInfo = new ProcessStartInfo()
        {
            CreateNoWindow = true,
            //Le paso el parametro /p para imprimir y posteriormente la ruta del archivo que va a imprimir
            Arguments = string.Format("/p \"{0}\"", archivo),
            //Nombre del ejecutable de Adobe Reader
            FileName = "AcroRd32.exe"
        };
        p.Start();
    }
}

Well, I do not expect anything to work for you, P

    
answered by 30.07.2018 / 18:41
source