首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法用MigraDoc/PDFsharp打印

无法用MigraDoc/PDFsharp打印
EN

Stack Overflow用户
提问于 2018-02-21 11:32:39
回答 1查看 4.4K关注 0票数 1

我将NuGet包添加到我的项目中:

PDFsharp + MigraDoc 版本: 1.50.4790-beta5a (预发布)

这就增加了参考资料:

MigraDoc.DocumentObjectModel MigraDoc.Rendering MigraDoc.RtfRendering PdfSharp PdfSharp.Charting

我正在使用VS2013,目标是.NET Framework4.5。

没有MigraDocPrintDocument类/命名空间,也没有Printing.MigraDocPrintDocument...

此外,我还尝试将PagePreview控件添加到表单中(我正在开发Windows.Forms应用程序),但没有这样的控件,也无法从dll/包将此类项添加到工具箱中。

我已经把PDF文档写得很直了,但是现在我被困在最后一步了,我看不到光明。需要打印到热感打印机上。

我的代码的一个简短片段:

代码语言:javascript
复制
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();
       
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-21 14:26:10

要获得预览,请尝试PDFsharp-MigraDoc-WPFPDFsharp-MigraDoc-GDI

检查Document Viewer示例:

http://www.pdfsharp.net/wiki/DocumentViewer-sample.ashx

您可以在这里下载完整的示例代码:

https://sourceforge.net/projects/pdfsharp/files/pdfsharp/PDFsharp%201.50%20%28beta%203%29/

如果要打印,请从早期版本中选择打印类。另请参阅:

http://forum.pdfsharp.net/viewtopic.php?f=8&t=3202

您将需要GDI构建来打印。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48904836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档