PDF Generation using C#.NET [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I am trying to create a PDF generator using C#.NET but having some major difficulties. I have an xml files with the data and an xslt file for the template of the pdf. I tried many different libraries out there but can't seem to get this working properly. Can anyone suggest an example I can use that shows how to do this.
Any help would be much appreciated. Thanks

I found a solution using the excellent TransformXMLToHTML method by Marc Gravell to transform XML + XSLT to HTML.
The HTML can then be transformed to PDF.
This approach may have been slower than editing a PDF as binary. But it was stable and gave me full control over content quality.
Step 1 - transform XML + XSLT to HTML
I needed to add Nugets including:
https://www.nuget.org/packages/System.Xml.ReaderWriter/
using System.Xml;
using System.Xml.Xls;
using System.IO;
public static string TransformXMLToHTML(string inputXml, string xsltString)
{
XslCompiledTransform transform = new XslCompiledTransform();
using(XmlReader reader = XmlReader.Create(new StringReader(xsltString))) {
transform.Load(reader);
}
StringWriter results = new StringWriter();
using(XmlReader reader = XmlReader.Create(new StringReader(inputXml))) {
transform.Transform(reader, null, results);
}
return results.ToString();
}
Step 2 - Transform HTML to PDF
I tried:
https://github.com/rdvojmoc/DinkToPdf
IronPdf which was non free to deploy but the free trial was quite successful (https://ironpdf.com/examples/using-html-to-create-a-pdf/)
https://github.com/ArthurHub/HTML-Renderer
All worked and had their weaknesses and strengths.
[Lets not get into a debate about the best C# HTML to PDF converter.]

Related

Hello I'm very new to xml and c#, I'm basically trying to create a bot through xml and using xml text reader [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
If anybody could give me a few tips and an example in both XML and c# on how it actually works, I learn a lot better by playing about with the codes myself but actually creating them at the moment is driving me crazy. I just want to type hello and get a few responces like, hi, you okay, good day etc.. Any help will be much appreciated thanks in advance guys
You haven't been very specific in your question but this is the only piece of C# XML code I have to hand:
xmlWriter.WriteStartElement("");
xmlWriter.WriteAttributeString("", "");
xmlWriter.WriteValue(10);
xmlWriter.WriteEndElement();
You may also want to look at the XML Serizalizer. Below is a code sample in regards to this:
try
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
StringWriter writer = new StringWriter();
serializer.Serialize(writer, myClass);
StringBuilder sb = new StringBuilder(writer.ToString());
return sb.ToString();
}
catch (Exception ex)
{
throw new System.Exception("" + ex.Message);
}

save a JPEG in progressive format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
A similar question has already been asked on this thread:
Save JPG in progressive format
However, the answer marked is basically saying that it can't be done. However, considering it is done using other software, it definitely is something which C# can do.
Is there any way this can be done?
Magick.NET can do it with a code like this
using (MagickImage image = new MagickImage("input.png"))
{
// Set the format and write to a stream so ImageMagick won't detect the file type.
image.Format = MagickFormat.Pjpeg;
using (FileStream fs = new FileStream("output.jpg", FileMode.Create))
{
image.Write(fs);
}
// Write to .jpg file
image.Write("PJEG:output.jpg");
// Or to a .pjpeg file
image.Write("output.pjpg");
}
You can find more details here.

Reading 2D Barcode from Images [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I need a library to read 2D barcode (datamatrix) from images on C# project (windows Forms).
I tried using some SDKs, but the SDKs I tried are not free.
Is there any free SDK for reading 2d Barcode from images?
There's an example available:
using DataMatrix.net; // Add ref to DataMatrix.net.dll
using System.Drawing; // Add ref to System.Drawing.
[...]
// ---------------------------------------------------------------
// Date 180310
// Purpose Get text from a DataMatrix image.
// Entry sFileName - Name of the barcode file (PNG, + path).
// Return The text.
// Comments See source, project DataMatrixTest, Program.cs.
// ---------------------------------------------------------------
private string DecodeText(string sFileName)
{
DmtxImageDecoder decoder = new DmtxImageDecoder();
System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(sFileName);
List<string> oList = decoder.DecodeImage(oBitmap);
StringBuilder sb = new StringBuilder();
sb.Length = 0;
foreach (string s in oList)
{
sb.Append(s);
}
return sb.ToString();
}
You'll need DataMatrix.net!
Best free Datamatrix coder\decoder that i've used is libdmtx: http://www.libdmtx.org/ . It has c# wrapper, so feel free to use it. I can't write sample code right now, but if you won't be able to handle it yourself, i'll help you a bit later with that.
EDIT:
libdmtx comes with console utils - if you will be able to read your barcodes with console app, you surely will read it using code.
EDIT2:
Here's code samples: http://libdmtx.wikidot.com/libdmtx-net-wrapper
I wonder if you have pictures containing some other info, except the barcode. The thing is - i don't know any free\open source lib to handle finding barcode on a picture, containing any other data properly.
And here's the link to other datamatrix implementations: http://www.libdmtx.org/resources.php

How to draw candle charts in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
How can I draw candle charts in C#? Does anybody has any examples with a nice interface?
I've used the MSChart and found it to be pretty good. It supports candlestick charts. I've used ZedGraph as well but found a few graphical anomalies showed up on my charts but they were otherwise good as well.
I use this for stock data but its in VB
With Chart1.ChartAreas("myarea")
.AxisY.Maximum = (Math.Ceiling((HighValue * 100)) / 100)
.AxisY.Minimum = (Math.Floor((LowValue * 100)) / 100)
.AxisY.LabelStyle.Format = "{0.00}"
End With
Dim s1 As New Series
With s1
.ChartArea = "myarea"
.ChartType = SeriesChartType.Candlestick
.XValueType = ChartValueType.String
.YValueType = ChartValueType.Single
.YValuesPerPoint = 4
.CustomProperties = "PriceDownColor=Red, PriceUpColor=Green"
End With
For i = Globals.GraphColumns - 1 To 0 Step -1
OutData = Data_Array.Item(i)
s1.Points.AddXY(OutData.thedate, OutData.high, OutData.low, OutData.close, OutData.open)
Next
Chart1.Series.Add(s1)
Me.Controls.Add(Chart1)
ZedGraph is a very easy-to-use LGPLed charting library that can handle candlestick charts.
If you need to save an image to disk, it can do that. If you need to display an interactive graph that supports zooming/panning, it can do that as well with the excellent ZedGraphControl control.
I'm using the .netCharting library for this and it's pretty good. It supports all sorts of charts - candle included. One thing to watch out for is that with the current version (5.3) you have to reverse the high and low price - a pretty ugly and obvious bug. It's a commercial product, but reasonably priced, so could be worth it, depending on your project.
Maybe ChartDirector can be a good solution
http://www.advsofteng.com/doc/cdcomdoc/candlestick.htm
Try xamChart Control Trial version from Infragistics.
Here is another sample at CodeProject

Anyone translate a X12 271 Healthcare response [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I'm looking for C# code that translates a 271 health care eligibility benefit response to a more usable format so I can display certain segments and values into a datagridview. I'm looking for code that I can use to break this thing apart as it's not really difficult, just very tedious and was wondering if anybody else has done this and is willing to share.
Thanks!!
There is an open source X12 parser (OopFactory X12 Parser: https://x12parser.codeplex.com) that does this for you.
To convert any X12 document to Xml:
FileStream fstream = new FileStream("Sample1.txt", FileMode.Open, FileAccess.Read);
var parser = new X12Parser();
Interchange interchange = parser.Parse(fstream);
string xml = interchange.Serialize();
To convert any X12 document to Html:
var htmlService = new X12HtmlTransformationService(new X12EdiParsingService(suppressComments: false));
Stream ediFile = new FileStream("Sample.txt", FileMode.Open, FileAccess.Read);
string html = htmlService.Transform(new StreamReader(ediFile).ReadToEnd());
More details here: https://x12parser.codeplex.com/wikipage?title=Parsing%20an%20837%20Transaction&referringTitle=Documentation
To load an X12 271 response into a .Net object, you can use:
FileStream fstream = new FileStream("Sample1.txt", FileMode.Open, FileAccess.Read);
var service = new EligibilityTransformationService();
EligibilityBenefitDocument eligibilityBenefitDocument = service.Transform271ToBenefitResponse(fstream);
DataDirect Technologies sells a converter that will translate it into XML.
I recommend perl or python for protoyping. once you have behavior you want, you can:
compile the whole thing
have a programmer write C(whatever flavor you need) for the parts that are too slow.
use the prototype as the spec for development in whatever language you need.

Categories

Resources