HtmlToPdf/src/HtmlToPdfService.Client/Models/PdfOptions.cs
zpc f7495e5fd4 feat: 支持PDF自定义页面尺寸和浏览器视口设置,新增外部对接文档
- PdfConversionOptions 新增 Width/Height(自定义纸张尺寸)和 ViewportWidth/ViewportHeight(浏览器视口)
- PuppeteerPdfService 渲染前设置视口,BuildPdfOptions 支持自定义宽高优先于预设Format
- ConversionTask 新增 PdfWidth/PdfHeight 字段
- 全链路透传:API DTO → TaskOrchestrator → TaskProcessor → PuppeteerPdfService
- Client SDK PdfOptions 同步更新
- 新增 docs/外部对接文档.md
2026-03-16 18:33:06 +08:00

91 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.Json.Serialization;
namespace HtmlToPdfService.Client.Models;
/// <summary>
/// PDF 转换选项
/// </summary>
public class PdfOptions
{
/// <summary>
/// 页面格式,如 A4, Letter, Legal 等
/// </summary>
[JsonPropertyName("format")]
public string? Format { get; set; }
/// <summary>
/// 是否横向
/// </summary>
[JsonPropertyName("landscape")]
public bool? Landscape { get; set; }
/// <summary>
/// 是否打印背景
/// </summary>
[JsonPropertyName("printBackground")]
public bool? PrintBackground { get; set; }
/// <summary>
/// 页边距设置
/// </summary>
[JsonPropertyName("margin")]
public MarginOptions? Margin { get; set; }
/// <summary>
/// 自定义页面宽度支持单位px, in, cm, mm如 "1309px", "210mm"
/// 设置后将忽略 Format 参数
/// </summary>
[JsonPropertyName("width")]
public string? Width { get; set; }
/// <summary>
/// 自定义页面高度支持单位px, in, cm, mm如 "926px", "297mm"
/// 设置后将忽略 Format 参数
/// </summary>
[JsonPropertyName("height")]
public string? Height { get; set; }
/// <summary>
/// 浏览器视口宽度(像素),控制页面渲染时的窗口宽度
/// </summary>
[JsonPropertyName("viewportWidth")]
public int? ViewportWidth { get; set; }
/// <summary>
/// 浏览器视口高度(像素),控制页面渲染时的窗口高度
/// </summary>
[JsonPropertyName("viewportHeight")]
public int? ViewportHeight { get; set; }
}
/// <summary>
/// 页边距选项
/// </summary>
public class MarginOptions
{
/// <summary>
/// 上边距(如 "10mm"
/// </summary>
[JsonPropertyName("top")]
public string? Top { get; set; }
/// <summary>
/// 右边距
/// </summary>
[JsonPropertyName("right")]
public string? Right { get; set; }
/// <summary>
/// 下边距
/// </summary>
[JsonPropertyName("bottom")]
public string? Bottom { get; set; }
/// <summary>
/// 左边距
/// </summary>
[JsonPropertyName("left")]
public string? Left { get; set; }
}