Skip to content

Commit

Permalink
Adjust the exposure of the PdfWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
garryxiao committed Apr 16, 2024
1 parent 7a2206e commit 285932e
Show file tree
Hide file tree
Showing 34 changed files with 974 additions and 551 deletions.
141 changes: 48 additions & 93 deletions ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using com.etsoo.EasyPdf;
using com.etsoo.EasyPdf.Content;
using com.etsoo.EasyPdf.Support;
using System.Globalization;

var path = "D:\\a.pdf";
Expand All @@ -20,121 +21,75 @@
pdf.Metadata.Keywords = "ETSOO, PDF";

pdf.Style.FontSize = 16;

/*
pdf.Style.BackgroundColor = PdfColor.Parse("gray");
pdf.Style.Border = new PdfStyleBorder(PdfColor.Red, 40);
pdf.Style.Border.Top.Width = 80;
pdf.Style.Border.Bottom.Width = 160;
pdf.Style.Border.Bottom.Color = PdfColor.Yellow;
pdf.Style.Border.Right.Width = 120;
pdf.Style.Border.Right.Color = PdfColor.Blue;
*/
pdf.Style.Border = new PdfStyleBorder(PdfColor.Red, 10);

// Fonts
await pdf.Fonts.LoadAsync("C:\\Windows\\Fonts\\simsun.ttc");
await pdf.Fonts.LoadAsync("C:\\Windows\\Fonts\\Arial.ttf");

pdf.Style.Font = "宋体";
pdf.Style.TextAlign = PdfTextAlign.Justify;

//await pdf.Fonts.LoadAsync("C:\\Windows\\Fonts\\simsun.ttc");
//pdf.Style.Font = "宋体";

await pdf.Fonts.LoadAsync("C:\\Windows\\Fonts\\msyh.ttc");
pdf.Style.Font = "Microsoft YaHei"; // 微软雅黑


// Get writer and start writing
var w = await pdf.GetWriterAsync();
await w.NewPageAsync((page) =>
var w = await pdf.GetWriterAsync((page) =>
{
page.Style.Border = new PdfStyleBorder(PdfColor.Red, 1);
page.Style.Padding = new PdfStyleSpace(10);
page.Data.PageSize = PdfPageSize.A4;
page.Style.LineHeight = 30;
//page.Data.PageSize = new System.Drawing.SizeF(595, 300);
});

var p3 = new PdfParagraph();
p3.Style.SetFontStyle(PdfFontStyle.Bold).SetTextAlign(PdfTextAlign.Center);
//p3.Style.FontStyle = PdfFontStyle.Bold;
//p3.Style.TextAlign = PdfTextAlign.Center;
p3.Add("青岛亿速思维网络科技有限公司");
var chunk = p3.Add("斜体");
chunk.Style.FontSize = 30;
chunk.Style.FontStyle = PdfFontStyle.Italic;

var chunk2 = p3.Add("普通斜体");
chunk2.Style.FontStyle = PdfFontStyle.Italic;

var chunk3 = p3.Add("小斜体");
chunk3.Style.FontStyle = PdfFontStyle.Italic;
chunk3.Style.FontSize = 10;

p3.Add("恢复政策").Style.FontStyle = PdfFontStyle.Regular;
await w.WriteAsync(p3);
// Paragraphs
var p0 = new PdfParagraph();
p0.Add(new PdfImage("D:\\etsoo.png"));
await w.WriteAsync(p0);

var p1 = new PdfParagraph();
p1.Add("青岛亿速思维网络科技有限公司 1").Style.Margin.Right = 40;
p1.Style.TextAlign = PdfTextAlign.End;
//p1.Style.LetterSpacing = 10;
p1.Style.SetFontSize(30).SetTextAlign(PdfTextAlign.Center).SetMargin(new PdfStyleSpace(10, 0));
p1.Add("亿速思维");
p1.Add(new PdfSuperscript("®"));
p1.Add(" - ");
p1.Add("ETSOO");
p1.Add(new PdfSuperscript("®"));
await w.WriteAsync(p1);

var p2 = new PdfParagraph();
p2.Add("青岛亿速思维网络科技有限公司 2");
await w.WriteAsync(p2);

var longText = new PdfParagraph();
var longChunk = longText.Add("关于<甘肃>前首富阙文彬的财产执行情况,再起波澜。3月21日,成都武侯法院发布一则悬赏公告,内容提到李建秋申请执行阙文彬合同纠纷一案,法院责令被执行人阙文彬限期履行生效法律文书确定的义务,但是被执行人逾期未履行,法院决定悬赏查找被执行人财产。该案的执行标的将近1300万元,悬赏金为执行到位金额的10%。3月22日,记者了解到,该案件的被执行人阙文彬正是此前因涉及借贷纠纷的甘肃“前首富”,其持有的全部恒康医疗股份被杭州市下城区人民法院司法冻结,而在2021年,成都市中级人民法院也曾发布拍卖信息,将位于成都双流国际机场的两架公务机“湾流G550”和“湾流G450”进行司法拍卖,这两架飞机原属四川纵横航空有限公司,该公司由四川恒康发展有限责任公司100%控股,当时的实控人正是阙文彬。为何要悬赏执行?有法院系统专业人士告诉记者,悬赏执行,其实就是法院在执行过程中依据申请执行人申请,向社会发布悬赏公告,公开发布悬赏信息征集知情人提供被执行人财产线索,并在据此取得执行效果后向财产线索提供人支付悬赏金的执行措施,“有几种情况可以申请悬赏执行,一是法院穷尽执行措施无法查找被执行人可供执行财产的;被执行人下落不明或隐匿行踪,且无法查证被执行人财产状况的;被执行人名下的车辆或其他动产被人民法院查封等限制措施后未能实际控制的;被执行人有转移、隐匿财产行为或嫌疑的;其他需要实行悬赏执行的。” - In this example, Vector2Wrapper is a class that contains a Vector2 property that contains a Vector3 property Vector4. X");
//longChunk.Style.LetterSpacing = 10;
//longChunk.Style.WordSpacing = 20;

var superscript = new PdfSuperscript("123456789abcdefg");
superscript.Style.Color = PdfColor.Blue;
longText.Add(superscript);

var subscript = new PdfSubscript("3b");
subscript.Style.Color = PdfColor.Red;
longText.Add(subscript);

var cchunk = longText.Add("继续文字,看看是否中断!");

await w.WriteAsync(longText);

var englishText = new PdfParagraph();
englishText.Style.Font = "Arial";
var enchunk = englishText.Add("The TJ operator provides even more flexibility by letting you independently specify the space between letters. Instead of a string, TJ accepts an array of strings and numbers. When it encounters a string, TJ displays it just as Tj does. But when it encounters a number, it subtracts that value from the current horizontal text position.");
await w.WriteAsync(englishText);

/*
var p2 = new PdfParagraph();
p2.Style.FontStyle = PdfFontStyle.Bold;
p2.Add("青岛亿速思维网络科技有限公司 粗体");
await w.AddAsync(p2);
await w.WriteAsync(p2);

// Paragraphs
var p1 = new PdfParagraph();
p1.Add("青岛亿速思维网络科技有限公司");
p1.Add("青岛亿速思维网络科技有限公司 粗体").Style.FontStyle = PdfFontStyle.Bold;
p1.Add("青岛亿速思维网络科技有限公司 斜体").Style.FontStyle = PdfFontStyle.Italic;
await w.AddAsync(p1);
var p3 = new PdfParagraph();
p3.Style.FontStyle = PdfFontStyle.Italic;
p3.Add("青岛亿速思维网络科技有限公司 斜体");
await w.WriteAsync(p3);

var p5 = new PdfParagraph();
p5.Style.FontStyle = PdfFontStyle.BoldItalic;
p5.Add("青岛亿速思维网络科技有限公司 粗体斜体");
await w.AddAsync(p5);
var p4 = new PdfParagraph();
p4.Style.FontStyle = PdfFontStyle.BoldItalic;
p4.Add("上海亿商网络科技有限公司 粗体 & 斜体");
await w.WriteAsync(p4);

await w.NewPageAsync((page) =>
{
page.Data.PageSize = PdfPageSize.A4;
page.Style.Padding = new PdfStyleSpace(30);
page.Style.Color = PdfColor.Parse("white");
page.Style.BackgroundColor = PdfColor.Parse("blue");
});
var hr = new PdfHR();
await w.WriteAsync(hr);

var p4 = new PdfParagraph();
p4.Style.FontStyle = PdfFontStyle.Bold;
p4.Add("Qingdao ETSOO Network-Tech Co., Ltd. (Bold, Italic)");
await w.AddAsync(p4);
*/
var p5 = new PdfParagraph();
p5.Style.SetFontSize(14)
.SetTextAlign(PdfTextAlign.Justify)
.SetLineHeight(20)
.SetBorder(new PdfStyleBorder(PdfColor.Blue, 2))
.SetBackgroundColor(PdfColor.Parse("#f3f3f3"))
.SetMargin(new PdfStyleSpace(20, 0))
.SetPadding(new PdfStyleSpace(10));
p5.Add("亿速思维(ETSOO)自成立以来致力于自主研发,在过去的20年中一直秉持着对技术的不懈追求和创新精神,为中小企业提供高效的信息化管理解决方案。公司的使命在于为客户创造价值,通过持续创新和卓越的服务,助力企业实现数字化转型。ETSOO has been dedicated to independent research and development since its establishment, maintaining an unwavering pursuit of technology and spirit of innovation over the past 20 years. We specialize in providing efficient information management solutions for small and medium-sized enterprises. Our mission is to create value for our customers by facilitating digital transformation through continuous innovation and excellent service.");
await w.WriteAsync(p5);

var p6 = new PdfParagraph();
p6.Style.SetFontSize(50).SetColor(new PdfColor(255, 0, 0)).SetRotate(-45).SetOpacity(0.1f).SetTextAlign(PdfTextAlign.Center);
p6.Add($"ETSOO® 亿速思维® {DateTime.Now.Year}");
await w.WriteAsync(p6);

var p7 = new PdfParagraph();
p7.Style.SetFontSize(12).SetTextAlign(PdfTextAlign.End);
p7.Add("欢迎访问 / Please visit ");
p7.Add(new PdfLink("ETSOO Website", new Uri("https://www.etsoo.com"), "点击访问官方网站"));
await w.WriteAsync(p7);

// Dispose
await pdf.DisposeAsync();
Expand Down
Binary file added com.etsoo.EasyPdf.Tests/Resources/html/etsoo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 285932e

Please sign in to comment.