Invalid/Unknown/Unsupported format error

Asked

Viewed 90 times

0

I have the following line of code:

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

Which I declare in app config.:

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

That goes all the way to the method PrintPDF, but when it comes to the line doc.LoadFromFile(arquivo) returning me the error:

Invalid/Unknown/Unsupported format

But I don’t 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();


               }
  • You are probably not passing the output file format. But not knowledge of this method to tell you how to specify this format in the code.

  • 1

    The method wants a path to upload a pdf, and you are passing a txt, simple.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.