gpt4 book ai didi

c# - 我正在使用 PdfSharp,找不到类 BeginBox 它在哪里?

转载 作者:可可西里 更新时间:2023-11-01 08:07:04 27 4
gpt4 key购买 nike

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace Lightnings_Extractor
{
class PDF
{
public PDF()
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";

// Create an empty page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
// Save the document...
const string filename = @"d:\HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}

private void DrawImage(XGraphics gfx, int number)
{
}
}
}

我正在从这个链接中获取示例:http://www.pdfsharp.net/wiki/Graphics-sample.ashx那里有一个示例:Draw an image in original size

void DrawImage(XGraphics gfx, int number)
{
BeginBox(gfx, number, "DrawImage (original)");

XImage image = XImage.FromFile(jpegSamplePath);

// Left position in point
double x = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
gfx.DrawImage(image, x, 0);

EndBox(gfx);
}

我在这里错过了什么?

最佳答案

BeginBoxEndBox 是在 bottom of the sample page 中定义的辅助方法.

请注意,这些方法仅用于创建周围的框,可能不是实现您真正想要的功能(在本例中,以原始大小绘制图像)所需要的。所以我只想从代码中删除这两行。

public void BeginBox(XGraphics gfx, int number, string title)
{
const int dEllipse = 15;
XRect rect = new XRect(0, 20, 300, 200);
if (number % 2 == 0)
rect.X = 300 - 5;
rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
rect.Inflate(-10, -10);
XRect rect2 = rect;
rect2.Offset(this.borderWidth, this.borderWidth);
gfx.DrawRoundedRectangle(new XSolidBrush(this.shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8));
XLinearGradientBrush brush = new XLinearGradientBrush(rect, this.backColor, this.backColor2, XLinearGradientMode.Vertical);
gfx.DrawRoundedRectangle(this.borderPen, brush, rect, new XSize(dEllipse, dEllipse));
rect.Inflate(-5, -5);

XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter);

rect.Inflate(-10, -5);
rect.Y += 20;
rect.Height -= 20;

this.state = gfx.Save();
gfx.TranslateTransform(rect.X, rect.Y);
}

public void EndBox(XGraphics gfx)
{
gfx.Restore(this.state);
}

关于c# - 我正在使用 PdfSharp,找不到类 BeginBox 它在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13905849/

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