C# 无法使用Doc/PDFsharp打印
我将NuGet包添加到我的项目中: PDFsharp+Doc 版本:1.50.4790-beta5a预发布 增加了参考文献: MigraDoc.DocumentObjectModel 文档渲染 弗雷德博士 PdfSharp PdfSharp.制图 我正在使用VS2013,目标是.NET Framework 4.5 没有MigraDocPrintDocument类/命名空间,也没有Printing.MigraDocPrintDocument 此外,我还尝试将PagePreview控件添加到表单中。我正在开发一个Windows.Forms应用程序,但没有此类控件,也无法从DLL/软件包中将此类项添加到工具箱中 我已经把PDF文档做得非常简单,但是现在我被最后一步卡住了,我看不见光。需要打印到热敏打印机上 我的代码的一小段:C# 无法使用Doc/PDFsharp打印,c#,visual-studio,pdf,migradoc,C#,Visual Studio,Pdf,Migradoc,我将NuGet包添加到我的项目中: PDFsharp+Doc 版本:1.50.4790-beta5a预发布 增加了参考文献: MigraDoc.DocumentObjectModel 文档渲染 弗雷德博士 PdfSharp PdfSharp.制图 我正在使用VS2013,目标是.NET Framework 4.5 没有MigraDocPrintDocument类/命名空间,也没有Printing.MigraDocPrintDocument 此外,我还尝试将PagePreview控件添加到表单中。
public void PrintMigraDoc(Bitmap ImagenBMP, string nombre, string apellido, string documento, string nacimiento, string nacionalidad, string grupo)
{
//Save image in greyscale
Bitmap bmp = GrayScale(ImagenBMP);
bmp.Save("foto_grey.bmp");
//Create document
Document document = new Document();
//Custom Normal Style
Style style = document.Styles["Normal"];
style.Font.Name = "Calibri";
style.Font.Size = 6;
//Sections & Page Properties
Section section = document.AddSection();
Unit width, height;
width = Unit.FromMillimeter(60);
height = Unit.FromMillimeter(100);
section.PageSetup.PageWidth = width;
section.PageSetup.PageHeight = height;
section.PageSetup.LeftMargin = 5;
section.PageSetup.RightMargin = 5;
section.PageSetup.TopMargin = 5;
//Fecha
Paragraph paragraph = section.AddParagraph(DateTime.Today.ToString("dddd") + ", " + DateTime.Today.ToString("dd MMMM yyyy"));
//Foto
paragraph = section.AddParagraph();
MigraDoc.DocumentObjectModel.Shapes.Image imagen = section.AddImage("foto_grey.bmp");
imagen.Width = "2.5cm";
imagen.LockAspectRatio = true;
imagen.Left = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Center;
paragraph = section.AddParagraph();
//Datos en Tabla
this.table = section.AddTable();
this.table.Borders.Width = 0.25;
this.table.Borders.Left.Width = 0.5;
this.table.Borders.Right.Width = 0.5;
this.table.Rows.LeftIndent = 0;
this.table.RightPadding = 0;
//Columnas
MigraDoc.DocumentObjectModel.Tables.Column column = this.table.AddColumn();
column = this.table.AddColumn();
//Filas
MigraDoc.DocumentObjectModel.Tables.Row row = table.AddRow();
//Nombre
paragraph = row.Cells[0].AddParagraph("Name: ");
paragraph.AddFormattedText(nombre, TextFormat.Bold);
row.Cells[0].MergeRight = 1;
//Apellido
row = table.AddRow();
paragraph = row.Cells[0].AddParagraph("Surename: ");
paragraph.AddFormattedText(apellido, TextFormat.Bold);
row.Cells[0].MergeRight = 1;
//Documento
row = table.AddRow();
paragraph = row.Cells[0].AddParagraph("Document: ");
paragraph.AddFormattedText(documento, TextFormat.Bold);
row.Cells[0].MergeRight = 1;
//Apellido
row = table.AddRow();
paragraph = row.Cells[0].AddParagraph("Birth Date: ");
paragraph.AddFormattedText(nacimiento, TextFormat.Bold);
paragraph = row.Cells[1].AddParagraph("Nationality: ");
paragraph.AddFormattedText(nacionalidad, TextFormat.Bold);
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
string filename = "Invoice.pdf";
pdfRenderer.PdfDocument.Save(filename);
// Creates a PrintDocument that simplyfies printing of MigraDoc documents
//MigraDocPrintDocument printDocument = new MigraDocPrintDocument();
}
要获得预览,请尝试PDFsharp MigraDoc WPF或PDFsharp MigraDoc GDI
检查文档查看器示例:
您可以在此处下载完整的示例代码:
如果要打印,请使用早期版本中的printing类。另见:
您将需要GDI版本进行打印。要获得预览,请尝试PDFsharp MigraDoc WPF或PDFsharp MigraDoc GDI
检查文档查看器示例:
您可以在此处下载完整的示例代码:
如果要打印,请使用早期版本中的printing类。另见:
您需要GDI版本进行打印。谢谢!这篇文章的链接解决了我的印刷问题。使用GDI+并将MigraDocPrintDocument.cs添加到我的项目中。现在,我将寻找您建议的文档查看器。但是主要问题已经解决了,所以我会认为你的答案是正确的。再次感谢。DocumentViewer很容易使用。这是GDI库中的控件。谢谢!这篇文章的链接解决了我的印刷问题。使用GDI+并将MigraDocPrintDocument.cs添加到我的项目中。现在,我将寻找您建议的文档查看器。但是主要问题已经解决了,所以我会认为你的答案是正确的。再次感谢。DocumentViewer很容易使用。它是GDI库中的一个控件。