Migradoc & sharpPDF

996 Views Asked by At

I have a problem concerning integrating both Migradoc and SharpPDF.

I am creating a pdfpage with text with the pdfpage.add(text) function. (SharpPDF) However I also am creating a chart from data using the functionality of MigraDoc.

So my PDF code (SharpPDF) is as follows:

pdfDocument myDoc = new pdfDocument("Test", "Test", false);
pdfPage pdfpage = myDoc.addPage();
pdfpage.addText("Bladiebla");
pdfpage.addText("Some more Bladiebla");

myDoc.createPDF(FilePath);

My chart code (MigraDoc) is as follows:

Document document = new Document();
document = startDocument(document, "Chart");

//Create chart functions

document.LastSection.Add(chart);

Is there any way or function that I can use to insert the chart into the PDF before I call the createPDF function? (Maybe convert the chart to image and insert perform pdfpage.addImage();?)

What I have tried thus far is:

PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
pdfPage page2 = myDoc.addPage();
page2 = renderer.PdfDocument.Pages[0];   

This give's the following error: Cannot implicity convert type PdfSharp.Pdf.PdfPage to SharpPdf.PdfPage

1

There are 1 best solutions below

0
On BEST ANSWER

MigraDoc uses PDFsharp to create PDF files, so it's easy to combine MigraDoc and PDFsharp.

You are using sharpPDF. So I presume you have to create a PDF file with MigraDoc (in a temporary file or in a MemoryStream) and then open this PDF file with sharpPDF to get a PDF page in the sharpPDF format.

Or use MigraDoc to create the final PDF file - it's easy to add text with MigraDoc.