嗨,我正在使用 PDFSharp 为某些图表创建 PDF 文档。将我的图表转换为 PDF 后,我应该将它们打印在一个页面上以获得非常小的图表,但是如果我有大图表,那么将它们打印在一页上会产生不好的打印质量,图表将显示很小并且图表内容不可读. 如果我给出一个高比例,图表会显示得更大,但一些节点会消失。
那么如何创建更多取决于我的比例和图表大小的页面?
private void convertBitmap(BitmapSource Img)
{
try
{
PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument();
document.Info.Title = activeDiagram.Model.Name;
PdfSharp.Pdf.PdfPage pdfPage = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(pdfPage);
XImage xIMage = XImage.FromBitmapSource(Img);
XImage logo = XImage.FromFile("logo.png");
pdfPage.Width = xIMage.PointWidth;
pdfPage.Height = xIMage.PointHeight;
//draw the logo
gfx.DrawImage(xIMage, 15, 70, pdfPage.Width, pdfPage.Height);
gfx.DrawImage(logo, 500, 5);
// Draw the texts
string typ = "";
if (activeDiagram == myDiagram1)
typ = "EPC";
XFont font = new XFont("Arial", 12, XFontStyle.Bold);
XFont font2 = new XFont("Arial", 10, XFontStyle.Bold);
gfx.DrawString("Modelname: " + activeDiagram.Model.Name, font, XBrushes.Black,
new XRect(50, 5, 400, 20), XStringFormats.TopLeft);
gfx.DrawString("Modeltyp: " + typ, font, XBrushes.Black, new XRect(50, 25, 400,
20), XStringFormats.TopLeft);
gfx.DrawLine(new XPen(XColor.FromKnownColor(XKnownColor.CornflowerBlue), 2), 20,
45, 600, 45);
gfx.DrawLine(new XPen(XColor.FromKnownColor(XKnownColor.CornflowerBlue), 2), 20,
900, 600, 900);
gfx.DrawString("Date: " + DateTime.Now.ToShortDateString(), font2, XBrushes.Black,
new XRect(50, 905, 100, 25), XStringFormats.TopLeft);
gfx.DrawString("Page: 1 von 1 ", font2, XBrushes.Black, new XRect(530, 905, 100,
25), XStringFormats.TopLeft);
SaveFileDialog dlg = new SaveFileDialog();
lg.FileName = activeDiagram.Model.Name;
dlg.AddExtension = true;
dlg.DefaultExt = "pdf";
dlg.Filter = "PDF Document|*.pdf|*.pdf|";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Save the document...
string filename = dlg.FileName;
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Error saving graph as a
pdf");
}
}