Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Estoy creado con PrintDocument un pdf luego lo quiero visionar. código

translated:
I am creating a pdf with PrintDocument then I want to view it. code


C#
private void CrearArchivo()
{
	PrintDocument documento = new PrintDocument();
	documento.PrintPage += Documento_PrintPage;
    documento.PrinterSettings.PrintToFile = true;
    string carpeta = Path.GetTempPath()+ @"\prueba.pdf";
    documento.PrinterSettings.PrintFileName = carpeta;
    documento.Print();
    
    MessageBox.Show("");
	
    axAcroPDF1.src = carpeta;
    axAcroPDF1.Focus();

}

si elimino la linea MessageBox.Show(""); no se puedo visionar el archivo, da error. Pero si la ejecuto puedo visionar el archivo.

translated:
If I remove the line MessageBox.Show(""); I can't view the file, it gives an error. But if I run it I can view the file.


What I have tried:

He probado a realizar la tarea en segundo plano con BackgroundWorker, pero nada, tengo que ejecutar un cuadro de mensaje para que se complete toda la accion.

translated:
I have tried to perform the task in the background with BackgroundWorker, but nothing, I have to execute a message box to complete the entire action.
Posted
Updated 18-Apr-22 4:57am
v2
Comments
Richard MacCutchan 16-Apr-22 13:48pm    
This is an English language site, please translate your question.

1 solution

PrintDocument is an IDisposable.

Try disposing PrintDocument before trying to access the file it creates; e.g.

C#
documento.Print();
documento.Dispose();
...
 
Share this answer
 
Comments
Victor IzqBe 2022 18-Apr-22 13:50pm    
Gracias, pero no me soluciona el problema. Sigo sin poder ver el documento pdf creado si no ejecuto la linea de messageBox

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