c# - iTextSharp Input string was not in a correct format css error -


I am trying to get my MVC application to create a PDF file based on MVC views. I got this work with simple HTML But I would also like to introduce my CSS files which I am using for the browser. Now some of them work, but with one I get the following error:

One type of exception was 'System.FormatException' in mscorlib.dll but it did not handle it in user code Was

Additional information: The input string was not in the correct format.

I am using the following code:

  var data = GetHtml (new index model context), "~ \\ View \\ Home \ \ Index.cshtml "," "); (Var document = new iTextSharp.text.Document ()) {// defined output control HTML var memStream = new MemoryStream (); TextReader xmlString = New stringreader (data); PdfWriter Author = PdfWriter.GetInstance (Document, New FileStream ("c: \\ tmp \\ my.pdf", FileMode.OpenOrCreate)); // Open Doc Document open (); // Register all the fonts in existing computer FontFactory.RegisterDirectories (); // set factory var htmlContext = new HTMLPlineContact (empty); HtmlContext.SetTagFactory (Tags.GetHtmlTagProcessorFactory ()); // Set CSS ICSS Resolver CSS Resolver = XMLWorkerGet Instance (). GetDefaultCssResolver (wrong); CssResolver.AddCssFile (HttpContext.Server.MapPath ("~ / content / elements.css", is true); CssResolver.AddCssFile (HttpContext.Server.MapPath ("~ / content / style.css"), is true); CssResolver.AddCssFile (HttpContext.Server.MapPath ("~ / content / jquery-ui.css", is true); // Export IPPline Pipeline = New CSSRSOLVPLline (CSSRSOllover, new HTMLPlineline (HTML Contains, New PDFRPPPPline (Document, Author)); Var worker = new XMLWorker (pipeline, true); Var xmlParse = New XMLParser (true, worker); XmlParse.Parse (xmlString); XmlParse.Flush (); Document.Close (); }   

The string "data" is correct and there is no problem, the problem is with AddCssFile (). If i do everything without pdf and css files, but css creates errors including files.

Support will be highly appreciated.

I do not know the correct answer, but seeing the error you are getting back, let me know I will try different ways.

  1. Go to

    cssResolver.AddCssFile (HttpContext.Server.MapPath ("~ / content / elements.css", is true) ; To do something like

    var csspath = HttpContext.Server.MapPath ("~ / content / elements.css"), true); CssResolver.AddCssFile (cssPath);

    Then set a breakpoint and see the value returned for CSSPath. Make sure they are correct and there is no strange letter in it.

    The second approach ... if everything fails, then try to provide a full URL for the CSS resource, instead of the file system path

    if those two appellices Anyone can help you, then you can use it to determine the real problem and after that you can re-apply your heart's content.

    UPDATE ----- ------------------------------------- ------------- ----------- & gt; According to the documentation, you need a complete URL for the file, so Server.MapPath will not work. ADCSSFile throws zero addCssFile (string href, boolean ezententant) CSSRSolver expands throws a parameters: link to href-css file (a full ury) is americi- true if added css should not be removed at the call to remove throws : CSSRSolar Expression - If something goes wrong, then it is thrown

    In that situation, I will try to do something like this:

      public string essence content (string contentPath) {var path = Url.Content (contentPath); Var url = new uri (httcqt.qrt; request. Url, path); Return url.AbsoluteUri; }   

    and use it like this:

      var csspath = AbsoluteContent ("~ / content / embeddedcss / yourcssfile.css");    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -