我在项目中添加了Nuget软件包:
PDFSHARP MIGRADOC
版本:1.50.4790-beta5a(preelease(
添加了参考文献:
migradoc.documentObjectModel
Migradoc.rendering
Migradoc.rtfrendering
pdfsharp
pdfsharp.charting
我正在使用VS2013,目标.NET框架4.5。
没有 crigadocprintDocument class/namespace,否 printing.migradocprintdocument ...
还尝试将 pagepreview 控制到我的表单(我正在开发Windows.forms应用程序(,但是没有这样的控件,也无法从我的工具箱中添加此类项目dlls/packages。
我使PDF文档非常简单,但是现在我坚持了最后一步,看不到光。需要打印到热电器。
我代码的简短片段:
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
。
检查Document Viewer
样本:
http://www.pdfsharp.net/wiki/documentViewer-sample.ashx
您可以在此处下载完整的示例代码:
https://sourceforge.net/projects/pdfsharp/files/pdfsharp/pdfsharp/pdfsharp 1.50 (beta 3)/
如果要打印,请从较早版本中获得打印类。另请参阅:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3202
您将需要GDI构建才能打印。