简体   繁体   English

Migradoc和SharpPDF

[英]Migradoc & sharpPDF

I have a problem concerning integrating both Migradoc and SharpPDF. 我在集成Migradoc和SharpPDF时遇到问题。

I am creating a pdfpage with text with the pdfpage.add(text) function. 我正在使用pdfpage.add(text)函数创建带有文本的pdfpage。 (SharpPDF) However I also am creating a chart from data using the functionality of MigraDoc. (SharpPDF)但是我也正在使用MigraDoc的功能根据数据创建图表。

So my PDF code (SharpPDF) is as follows: 所以我的PDF代码(SharpPDF)如下:

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: 我的图表代码(MigraDoc)如下:

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? 在调用createPDF函数之前,是否可以使用任何方法或函数将图表插入PDF? (Maybe convert the chart to image and insert perform pdfpage.addImage();?) (也许将图表转换为图像并插入执行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 这给出了以下错误:无法将类型PdfSharp.Pdf.PdfPage隐式转换为SharpPdf.PdfPage

MigraDoc uses PDFsharp to create PDF files, so it's easy to combine MigraDoc and PDFsharp. MigraDoc使用PDFsharp创建PDF文件,因此将MigraDoc和PDFsharp结合起来很容易。

You are using sharpPDF. 您正在使用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. 因此,我想您必须使用MigraDoc创建一个PDF文件(在临时文件中或在MemoryStream中),然后使用sharpPDF打开此PDF文件,以获取SharpPDF格式的PDF页面。

Or use MigraDoc to create the final PDF file - it's easy to add text with MigraDoc. 或使用MigraDoc创建最终的PDF文件-使用MigraDoc轻松添加文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM