c# - Unable to check if PDF file is created correctly -


I am unable to open my PDF file, it says that some other process is using it. However, I stopped stopping my program. Am I doing something wrong?

My button runs process , stores it in the data table

  Secure zero btnPrint_Click (object sender, EventArgs e) {Connection Con = New Connection (); SqlDataAdapter da; Datatelle DS; Con.con = New SqlConnection (con.str); Con.cmd.CommandText = "Select a process"; Con.cmd.CommandType = CommandType.StoredProcedure; da = new SqlDataAdapter (); Da.SelectCommand = con.cmd; DS = new datatable (); Try {con.con.Open (); Da.Fill (DS); } Hold (Exception Pre) {} Finally {con.con.close (); Con.con.Dispose (); ExportToPdf (DS); }}   

I'm printing data table here:

  Public Zero ExportToPdf (DataTable dt) {string pdfFilePath = @ "D: / myPdf .pdf "; Document Doctor = New Document (iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35); PDFDriver wri = PDF Writer. Get instant (doctor, new filestream (PDF file path, filemod. Creat)); Doc.Open (); If (dt! = Null) {// Crate pdf Example of table and set the number of columns in that table PdfPTable PdfTable = new PdfPTable (dt.Columns.Count); PDFPCL PDFPCL = Faucet; Font font 8 = fontfacture Getfont ("Ariel", 7); // Add PDF header header PDFPCL = new PDFPCL (new phrase (new segment ("id", font 8)); PdfTable.AddCell (PdfPCell); PDFPCL = new PDFPCL (new phrase (new chakra ("name", font 8)); PdfTable.AddCell (PdfPCell); How does data for data table (int rows = 0; rows & lt; dt.rows.count; rows ++) from datletr to PDF table {{(column for column column = 0; column & lt; dt. Column.Count; Column ++) {PDFPCL = New PDFPCL (new phrase (new segment (dt.ro [rows] [column]. Ostring (), font 8))); PdfTable.AddCell (PdfPCell); }} PdfTable.SpacingBefore = 15f; // Give some space after the text or it can overlap the table Article paragraph = New paragraph ("How do I create a simple table in PDF document using iTunesThope?"); Doc.Add (paragraph); // Add article in document doc.ed (PDFTable); // Add a PDF table to the document    

Do you close the document after adding paragraphs Given and so? In ITextSharp, the sample code says:

  pdfDoc.Open (); // Some content has been added between pdfDoc.Close ();   

I do not know that you have closed it, because it is not in your sample. Sometimes, while working with files, if you do not stop them, they become corrupt and are unable to open. This may be a problem.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -