gpt4 book ai didi

c# - 无法使用 MigraDoc/PDFsharp 打印

转载 作者:太空宇宙 更新时间:2023-11-03 22:48:05 30 4
gpt4 key购买 nike

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

PDFsharp + MigraDoc

Version: 1.50.4790-beta5a (Prerelease)

添加了引用:

MigraDoc.DocumentObjectModel

MigraDoc.Rendering

MigraDoc.RtfRendering

PdfSharp

PdfSharp.Charting

我正在使用 VS2013,目标是 .NET Framework 4.5。

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

我还尝试将 PagePreview 控件添加到我的表单(我正在开发一个 Windows.Forms 应用程序)但是没有这样的控件,我也不能将这样的项目添加到我的工具箱中dll/包。

我已将 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-WPFPDFsharp-MigraDoc-GDI

检查文档查看器示例:
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 版本进行打印。

关于c# - 无法使用 MigraDoc/PDFsharp 打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48904836/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com