FO.NET XSL-FO Capabilities - c#

I'm going to try to ask a very broad question here, not related to any specific code, but rather to an expected outcome. This is to see if anyone can answer with some certainity that FO.NET will be able to produce this outcome for me.
My goal: to port a service generating a PDF based on an XML document from Java (Using Apache FOP) to C#. This is to make it easier in a setup with only using IIS as a host.
Where I'm at: I have a working wcf service that gets the XML document and transforms it to xsl-fo and returns to the browser a PDF. What's left to do is to fix the styling so that it matches the previous PDF generated by Java Apache FOP. I'm currently using FO.NET and I'm hoping I don't have to redo everything but if that's the case then so be it.
The XSL Stylesheet is using SVG for creating figures, importing images etc and I know that this is not supported in FO.NET but maybe there is a workaround. The images can be converted to another file format but the shapes might be trickier.
Expected outcome (as it is with the current service): http://imgur.com/INkzvdo
Current outcome: http://imgur.com/Y5dbb3X
Question: Can this be done using FO.NET? If not, Is there any other Open Source Lib that I can use that is better suited or do I have to solve this in another way?
The reason I'm trying to use XSL-FO is that we already have three stylesheets defining the output PDF (There will be three different PDF Outputs) and it would be nice not having to redo everything using for instance CSS.

I'm going to answer this myself, partly based on the response I recieved, partly on my own experience with using FO.NET. I Don't recommend using C# for PDF's if xsl-fo is used for styling. If C# is a requirement I would investigate CSS for this purpose instead. If C# is not a requirement, I would recommend using Java and Apache FOP and host it here. If you, as in my case, need to host multiple services on the same outgoing port, you can use Application Request Routing in IIS (Addon I think) to serve as a reverse proxy for your Java Servlet. Thanks for your feedback #mzjn!

Related

iframe resource interpreted as document but transferred with mime type application/vnd.ms-excel

I am developing asp.net mvc 5 web application using c#. I am trying to display excel file in iframe
<iframe src="../../Data/ExcelSheets/ProjectExpenditureDetails/20170917184328709.xls" width="100%" height="500"></iframe>
When page loading always download the excel file and it is not displaying on the iframe.
Web developer tool says: resource interpreted as document, but transferred with mime type application/vnd.ms-excel
I don't know my approach is correct or not. If it's correct how to solve my problem. If it's wrong what is the best way to display excel file in web page.
I don't believe there is a way to do this natively in a browser. There are likely plugins that would allow it, but on a web site you can't guarantee someone will have that installed. I believe third party services are able to provide a some javascript that allows you to open a document. Google docs does something like this.
Think about flash applications (that used to be a thing). They contained proprietary code that wouldn't run in a browser without a plugin installed. XLS files are similar. There are some exceptions, but mostly a browser can only be expected to understand html, css, javascript, and a number of image formats. Even PDFs require a plugin to view, you just don't see it very often because many browsers make that fairly seamless now.
Unfortunately if you want to do this through a web site that needs to be secure I believe the route to go is actually replacing the shared sheet with application based functionality. Your clients may feel more comfortable about moving to google docs based sheets, which can be shared, but mine wouldn't touch it with a 10 foot pole. I'm not sure it is warranted, but that is how they feel.

Server Side HTML to PDF

I'm trying to find a C# library that will allow me to "Print" one of my HTML pages to a PDF file. I can't seem to find out if one currently exists that will allow you to do this. I've found several that will let you build a page, but haven't noticed if one would generate the pdf only based off of HTML.
EDIT: I'm not allowed a budget on this at work so it will need to be an open source/free product. If not I'm aware of iTextSharp and will have to generate the pdf programmatically (which is what I'm hoping to avoid :) )
I've had a lot of luck with ActivePDF WebGrabber. It's kind of odd to use compared to standard managed libraries (ActivePDF is unmanaged), but it gets the job done.
iTextSharp comes with a little companion : XML Worker
For a demo, have a look here
Even though the documentation refers to the Java API, the adaptation to C# should be straightforward.
I've experimented with itextsharp and it works for basic conversion, but gets complicated when you get into styles and formatting. I've also heard wkhtmltopdf is out there as another option.

Programmatically Generate PDF Report with design

The background right now is that I coded website for the client and as part of the website I have a service calling a webpage every 5-10 minutes to generate some PDFS that become available on the website. The PDFs just contain a data dump of a table that is displayed on the website.
The new requirements are to add a cover page and apply a color scheme to the PDF report which replicates the view on the website.
I'm unsure how to go about this using C# and VS2008 with the backend database being MySQL. I originally thought about creating a report and then somehow programmatically rendering and saving it as a PDF, but because we are using MySQL that throws out the possibility of using Sql Server Reporting Services. Is there any other open source and/or free solution that will allow me to create and design the report and then programmatically create and save as a pdf without any user interaction?
Your best bet is iText here. It supports creating pdf programmatically in java or C#. We use it where I work to do just this thing (also using MySQL on the backend). I also recommend buying the book. It has lots of good examples, and if you purchase the book, you get a pdf version of the book.
Try TCPDF. Though written in PHP, it has no external dependencies, has plenty of options and examples included. Works fast and reliable, no problems with fonts, etc.
jsreport supports exactly this kind of pdf generation. You first create a report layout and dynamic structure using html, css and javascript templating engines. Then you just send the data and invoke the rendering using c# classes.
This blog post should give you more info how to do it.
Disclaimer: I am the author of jsreport.

Batch conversion of docx to clean HTML

I'm starting to wonder if this is even possible. I've searched for solutions on Google and come up with nothing that works exactly how I'd like it to.
I think it'd benefit to explain what that entails. I work for database group at my university's IT department. My main job is to take specs of a report in a docx file, copy that over to dreamweaver, fix some formatting, and put it onto their website. My issue is that it's ridiculously tedious to do this over and over. I figured, hey, I haven't written anything in C# for some time now, perhaps I could write an application to grab a docx file, convert it to HTML, fix the CSS, stick the header, and footer from the webpage on there, and save the result. I originally planned to have it do one by one, but it probably wouldn't be difficult to have it input a list of files and batch convert.
I've found these relevant topics on how to accomplish this, but they don't fit my needs well enough.
http://www.techrepublic.com/blog/howdoi/how-do-i-modify-word-documents-using-c/190
This is probably fine for a few documents, but since it's just automating an instance of Word, I feel like it'd be slow and memory intensive. I'd prefer to avoid opening and closing an instance of Word 50+ times.
http://openxmldeveloper.org/articles/333.aspx
This is what I started using. XSLT had the benefit of not needing word to be installed nor ran for each file. After some searching I got a proof of concept working. It takes in a docx file, decompresses it, grabs the document.xml from that, and uses the DocX2Html.xsl file I scavenged from OpenXML viewer. I believe that was originally provided by MS for sharepoint servers to provide the ability to render word documents in a browser. Or something along those lines.
After adjusting that code to fit my needs, and having issues with the objXSLT.Load () method, I ended up using IlMerge to make the XSL into a DLL. No idea why I kept getting a compile error when using the plain old XSL file, but the DLL worked fine, so I was satisfied. Here (http://pastebin.com/a5HBAakJ) is my current code. It does the job of converting docx to HTML just fine (other than random spaces between some words), but the result file has ridiculously ugly HTML syntax. An example of this monstrosity can be found here (http://pastebin.com/b8sPGmFE).
Does anyone know how I could remedy this? I'm thinking perhaps I need to make a new XSL file, as the one MS provided is what's responsible for sticking all those tags and extra code in there. My issue with that is that I don't know anything about how to do that. Perhaps there's an alternative version already out there. All I'd need is one that will preserve tables and text formatting. Images aren't needed.
This looks like just what you need: http://msdn.microsoft.com/en-us/library/ff628051(v=office.14).aspx
The author Eric White blogged about his experiences developing that tool. You can see that list of posts on his blog here: http://blogs.msdn.com/b/ericwhite/archive/2008/10/20/eric-white-s-blog-s-table-of-contents.aspx#Open_XML_to_XHtml
Since I'm a big fan of Aspose.Words, a commercial library to create/process Word documents, I would do something like:
Open the Word document with Aspose.Words.
Save the Word document as HTML.
Use something like SgmlReader or HTML Agility Pack (or even Regular Expressions if it is suitable) to remove unwanted HTML tags/attributes.
Since you wrote you work at an university, I'm not sure whether commercial packages are an option, though.
Hi not sure what the rules are on promoting your own solutions, so do let me know if I am out of line.
I am a web developer who had the same issues, so I created my own tool:
http://www.convertwordtohtml.com
We are also working on a new version that will have even better conversion quality and one click conversion eg you can right click on a word file and it will be directly converted to html and the code placed into the clipboard. The current version also supports command line access and the new version will have a server version to.
There is a free trial version downloadable from the site , and if you have any questions do contact me any time.

Generating a Word Document with C#

Given a list of mailing addresses, I need to open an existing Word document, which is formatted for printing labels, and then insert each address into a different cell of the table. The current solution opens the Word application and moves the cursor to insert the text. However, after reading about the security issues and problems associated with opening the newer versions of Word from a web application, I have decided that I need to use another method.
I have looked into using Office Open XML, but I have not found any good resources that provide concrete information on exactly how to use it. Also, someone suggested that I use SQL reporting services, but searching for information on how to use them, lead me nowhere.
Which method do you think is the most appropriate for my problem?
Code samples and links to good tutorials would be extremely helpful.
Thanks for all the answers, but I really did not want to pay for a plugin and using Word automation was out of the question. So I kept searching and eventually, through some trial and error, found some answers.
After throughly searching through Microsoft's site, I found some newer articles on the Office Open XML SDK. I downloaded the new tools and just started going through each them.
I then found the Document Reflector, which creates a class to generate XML code based off an existing Word Document (.docx). Using my Label Template Document and the code this tool generated, I went through and added a loop that appends table cells for each address. It actually proved to be fairly simple and way faster than using Word automation.
So, if you're still using Word automation check out the Office Open XML tools. Their surprisingly extensive for a free download from Microsoft.
Office Open XML SDK 2.0 Download
I use the Words plugin from Aspose.com to do mail merges (programming guide).
You can take a look show 137 and 138 on dnrTV (www.dnrtv.com). In these video's Beth Massi shows how to do some editing and mail merging with OpenXML. She does this by using the Open XML SDK and xml literals in VB. It requires no third party components. Also it doesn't require MS Office to be installed on the machine.
This video inspired me as a C# developed (and no VB experience) to do some XML manipulation in a separate dll in VB. I call into this dll from my C# application.
It is worth a try.
We have the product Aspose that tvanfosson has mentioned. The edition that we purchased works with SQL Reporting Services so it can be used with the scheduler for creating output. It is really a great product and we used in a system that needed to support Korean characters in the final document. It works great and was under $1K with support. Not bad.
The advantage of using a product like this is that you can continue to manage your data and the skill set required to produce the documents is at a level where a variety of developers can support its use.
Vanstee,
If you really want to do this in code, check out this post I just found on Google
http://kellychronicles.spaces.live.com/blog/cns!A0D71E1614E8DBF8!1364.entry
If you are using reporting services cant you just move the information in the word doc into a database table and read it from there, taking word out of the equation?

Categories

Resources