Error Invalid / Unknown / Unsupported format

0

I have the following line of code:

new PrintPDF(ConfigurationManager.AppSettings["Comprovante"]);

What is stated in app.config :

<add key="Comprovante" value="C:\Client\Resp\Comprovante.txt" />

That goes to the PrintPDF method, however when it arrives at the doc.LoadFromFile(arquivo) line it returns me the error:

  

Invalid / Unknown / Unsupported format

But I do not know what's causing this exception

Method:

public PrintPDF(string arquivo)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(arquivo);

            //Use the default printer to print all the pages 
            //doc.PrintDocument.Print(); 

            //Set the printer and select the pages you want to print 

            PrintDialog dialogPrint = new PrintDialog
            {
                AllowPrintToFile = true,
                AllowSomePages = true
            };
            dialogPrint.PrinterSettings.MinimumPage = 1;
            dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
            dialogPrint.PrinterSettings.FromPage = 1;
            dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

            if (dialogPrint.ShowDialog() == DialogResult.OK)
            {
                //Set the pagenumber which you choose as the start page to print 
                doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
                //Set the pagenumber which you choose as the final page to print 
                doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
                //Set the name of the printer which is to print the PDF 
                doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

                PrintDocument printDoc = doc.PrintDocument;
                dialogPrint.Document = printDoc;

                printDoc.Print();


               }
    
asked by anonymous 21.12.2017 / 19:42

0 answers