In the C# project that I'm working on, when I click on a button the code create a PDF where I load a graph previously created with datas from source code. I used ScottPlot Library, but this library create a png file, saved and then load it on the PDF (this one created with iText7 library), but the quality is kinda blurry.
Is there a way to direclty create a graph on a PDF with better graphic quality? Even with a different library (for the graph and pdf).
This is my code where I create and load the graph on the PDF:
/******** GRAPH ********/
var plt = new ScottPlot.Plot(600, 400);
// create sample data
double[] values = { 26, 20, 23, 7, 16 };
// add a bar graph to the plot
plt.AddBar(values);
// adjust axis limits so there is no padding below the bar graph
plt.SetAxisLimits(yMin: 0);
//ADD GRAPH TO PDF
Add_Graph(plt, "bar_quickstart.png", doc);
Funzione Add_Graph:
private void Add_Graph(ScottPlot.Plot plt, string png, Document doc)
{
plt.SaveFig(png);
// Aggiungi il grafico alla posizione desiderata
var image = new iText.Layout.Element.Image(ImageDataFactory.Create(png));
image.SetFixedPosition(doc.GetLeftMargin() + 152, doc.GetBottomMargin(), 615);
doc.Add(image);
}
doc in this last function is how I create the PDF:
string pdfPath = "dataGraphic.pdf";
var pdfDocument = new PdfDocument(new PdfWriter(pdfPath));
var document = new Document(pdfDocument, PageSize.A4.Rotate(), false);