Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletClosePDF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Closes an open PDF document.</summary>
/// <para>Disposes the <c>PdfDocument</c> instance and releases associated resources.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>After closing, the document cannot be used further.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Close a document.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Close-PDF -Document $pdf
/// </code>
/// <para>Closes the specified PDF document.</para>
/// </example>
/// <example>
/// <summary>Pipe a document.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>$pdf | Close-PDF
/// </code>
/// <para>Closes the document passed through the pipeline.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet("Close", "PDF")]
public class CmdletClosePDF : PSCmdlet
{
/// <summary>PDF document to close.</summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public PdfDocument Document { get; set; } = null!;

Expand Down
32 changes: 32 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletConvertHTMLToPDF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Converts HTML content to a PDF file.</summary>
/// <para>Accepts HTML from a URI, string content, or file and writes a PDF to disk.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>Existing output files are overwritten when <c>-Force</c> is specified.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Convert from URI.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Convert-HTMLToPDF -Uri 'https://example.com' -OutputFilePath 'page.pdf'
/// </code>
/// <para>Downloads the page and saves it as PDF.</para>
/// </example>
/// <example>
/// <summary>Convert from file with CSS.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Convert-HTMLToPDF -FilePath 'index.html' -CssFilePath 'style.css' -OutputFilePath 'out.pdf'
/// </code>
/// <para>Applies the specified CSS and writes the PDF.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsData.Convert, "HTMLToPDF", DefaultParameterSetName = ParameterSetNames.Uri, SupportsShouldProcess = true)]
public class CmdletConvertHTMLToPDF : AsyncPSCmdlet
{
Expand All @@ -18,27 +42,35 @@ private static class ParameterSetNames
public const string File = "File";
}

/// <summary>URI of the HTML page.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.Uri)]
public string Uri { get; set; }

/// <summary>Raw HTML content.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.Content)]
public string Content { get; set; }

/// <summary>Path to an HTML file.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.File)]
public string FilePath { get; set; }

/// <summary>Output PDF path.</summary>
[Parameter(Mandatory = true)]
public string OutputFilePath { get; set; }

/// <summary>Open the PDF after creation.</summary>
[Parameter]
public SwitchParameter Open { get; set; }

/// <summary>Overwrite existing files.</summary>
[Parameter]
public SwitchParameter Force { get; set; }

/// <summary>Base URI for relative links.</summary>
[Parameter]
public string BaseUri { get; set; }

/// <summary>Paths to CSS files to include.</summary>
[Parameter]
public string[] CssFilePath { get; set; }

Expand Down
29 changes: 29 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletConvertPDFToText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,54 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Converts PDF pages to plain text.</summary>
/// <para>Extracts text from specified pages of a PDF document using iText strategies.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>Protected documents may require the <c>IgnoreProtection</c> switch to extract text.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Extract text from a PDF.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Convert-PDFToText -FilePath 'file.pdf'
/// </code>
/// <para>Returns text objects for each page.</para>
/// </example>
/// <example>
/// <summary>Save extracted text to a file.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Convert-PDFToText -FilePath 'file.pdf' -OutFile 'output.txt'
/// </code>
/// <para>Writes combined text to the specified file.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsData.Convert, "PDFToText")]
[OutputType(typeof(PSObject))]
public class CmdletConvertPDFToText : PSCmdlet
{
/// <summary>Path to the PDF file.</summary>
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
[Alias("FullName")]
public string FilePath { get; set; } = string.Empty;

/// <summary>Pages to extract.</summary>
[Parameter]
public int[] Page { get; set; } = Array.Empty<int>();

/// <summary>Extraction strategy to use.</summary>
[Parameter]
public PdfExtractionStrategyName ExtractionStrategy { get; set; } = PdfExtractionStrategyName.Simple;

/// <summary>Ignore document protection.</summary>
[Parameter]
public SwitchParameter IgnoreProtection { get; set; }

/// <summary>Optional output file.</summary>
[Parameter]
public string? OutFile { get; set; }

Check warning on line 59 in Sources/PSWritePDF/Cmdlets/CmdletConvertPDFToText.cs

View workflow job for this annotation

GitHub Actions / Windows PowerShell 5.1

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

protected override void ProcessRecord()
{
Expand Down
26 changes: 26 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletGetPDF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,39 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Opens an existing PDF file.</summary>
/// <para>Returns an iText <c>PdfDocument</c> for further processing.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>The caller must dispose the returned document.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Load a PDF.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDF -FilePath 'doc.pdf'
/// </code>
/// <para>Returns a <c>PdfDocument</c> instance.</para>
/// </example>
/// <example>
/// <summary>Ignore protection.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDF -FilePath 'doc.pdf' -IgnoreProtection
/// </code>
/// <para>Opens a protected PDF for reading.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsCommon.Get, "PDF")]
[OutputType(typeof(PdfDocument))]
public class CmdletGetPDF : PSCmdlet
{
/// <summary>Path to the PDF file.</summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public string FilePath { get; set; } = null!;

/// <summary>Ignore document protection.</summary>
[Parameter]
public SwitchParameter IgnoreProtection { get; set; }

Expand Down
26 changes: 26 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletGetPDFAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Gets numeric values of PDF actions.</summary>
/// <para>Converts <c>PdfActionName</c> values to their integer representation or lists all names.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>Action names correspond to constants defined in iText.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Get integer value for an action.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFAction -Action Hide
/// </code>
/// <para>Returns the numeric constant for the Hide action.</para>
/// </example>
/// <example>
/// <summary>List all action names.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFAction -All
/// </code>
/// <para>Displays all available action names.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsCommon.Get, "PDFAction", DefaultParameterSetName = ParameterSetNames.ByName)]
[Alias("Get-PDFConstantAction")]
[OutputType(typeof(int), ParameterSetName = new[] { ParameterSetNames.ByName })]
Expand All @@ -16,9 +40,11 @@ private static class ParameterSetNames
public const string All = "All";
}

/// <summary>Action name to translate.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.ByName)]
public PdfActionName Action { get; set; }

/// <summary>Return all action names.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.All)]
public SwitchParameter All { get; set; }

Expand Down
25 changes: 25 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletGetPDFDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,35 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Gets descriptive information about a PDF document.</summary>
/// <para>Returns metadata, margins, page sizes, and other details.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>The document is inspected but not modified.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Retrieve document details.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFDetails -Document $pdf
/// </code>
/// <para>Outputs a <c>PdfDocumentDetails</c> object.</para>
/// </example>
/// <example>
/// <summary>Pipe from New-PDF.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>New-PDF -FilePath 'out.pdf' | Get-PDFDetails
/// </code>
/// <para>Creates a PDF and immediately inspects it.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsCommon.Get, "PDFDetails")]
[OutputType(typeof(PdfDocumentDetails))]
public class CmdletGetPDFDetails : PSCmdlet
{
/// <summary>PDF document to analyze.</summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public PdfDocument Document { get; set; } = null!;

Expand Down
25 changes: 25 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletGetPDFFormField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,34 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Retrieves form fields from a PDF document.</summary>
/// <para>Enumerates AcroForm fields and returns their names and objects.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>The cmdlet emits warnings if the document contains no forms.</description>
/// </item>
/// </list>
/// <example>
/// <summary>List form fields.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFFormField -PDF $pdf
/// </code>
/// <para>Outputs form field information.</para>
/// </example>
/// <example>
/// <summary>Stop on read errors.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFFormField -PDF $pdf -ErrorAction Stop
/// </code>
/// <para>Throws a terminating error if forms cannot be read.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsCommon.Get, "PDFFormField")]
public class CmdletGetPDFFormField : PSCmdlet
{
/// <summary>PDF document to inspect.</summary>
[Parameter(Mandatory = true)]
public PdfDocument PDF { get; set; } = null!;

Expand Down
26 changes: 26 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletGetPDFPageSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Gets standard PDF page sizes.</summary>
/// <para>Returns an iText <c>PageSize</c> or enumerates available page size names.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>Page size names correspond to <c>PdfPageSizeName</c> enumeration values.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Get size for A4.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFPageSize -PageSize A4
/// </code>
/// <para>Returns the iText page size for A4.</para>
/// </example>
/// <example>
/// <summary>List all page sizes.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFPageSize -All
/// </code>
/// <para>Displays all supported page size names.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsCommon.Get, "PDFPageSize", DefaultParameterSetName = ParameterSetNames.ByName)]
[Alias("Get-PDFConstantPageSize")]
[OutputType(typeof(iText.Kernel.Geom.PageSize), ParameterSetName = new[] { ParameterSetNames.ByName })]
Expand All @@ -16,9 +40,11 @@ private static class ParameterSetNames
public const string All = "All";
}

/// <summary>Page size name to retrieve.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.ByName)]
public PdfPageSizeName PageSize { get; set; }

/// <summary>Return all page size names.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.All)]
public SwitchParameter All { get; set; }

Expand Down
26 changes: 26 additions & 0 deletions Sources/PSWritePDF/Cmdlets/CmdletGetPDFVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@

namespace PSWritePDF.Cmdlets;

/// <summary>Retrieves PDF version information.</summary>
/// <para>Returns a specific PDF version constant or lists all available versions.</para>
/// <list type="alertSet">
/// <item>
/// <term>Note</term>
/// <description>Version names must match those defined by iText.</description>
/// </item>
/// </list>
/// <example>
/// <summary>Get a specific version.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFVersion -Version PDF_2_0
/// </code>
/// <para>Returns the iText version constant for PDF 2.0.</para>
/// </example>
/// <example>
/// <summary>List all versions.</summary>
/// <code>
/// <prefix>PS&gt; </prefix>Get-PDFVersion -All
/// </code>
/// <para>Displays all supported PDF versions.</para>
/// </example>
/// <seealso href="https://learn.microsoft.com/dotnet/api/system.management.automation.cmdlet">MS Learn</seealso>
/// <seealso href="https://evotec.xyz/hub/scripts/pswritepdf/">Project documentation</seealso>
[Cmdlet(VerbsCommon.Get, "PDFVersion", DefaultParameterSetName = ParameterSetNames.ByName)]
[Alias("Get-PDFConstantVersion")]
[OutputType(typeof(iText.Kernel.Pdf.PdfVersion), ParameterSetName = new[] { ParameterSetNames.ByName })]
Expand All @@ -16,9 +40,11 @@ private static class ParameterSetNames
public const string All = "All";
}

/// <summary>Version name to translate.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.ByName)]
public PdfVersionName Version { get; set; }

/// <summary>Return all version names.</summary>
[Parameter(Mandatory = true, ParameterSetName = ParameterSetNames.All)]
public SwitchParameter All { get; set; }

Expand Down
Loading
Loading