PDF Quick Start
Edit on GitHubCreate a PDF with headings, paragraphs, a table, and an image, then load it and read its text, with OfficeIMO.Pdf, PSWriteOffice, or the officeimo CLI.
OfficeIMO.Pdf writes and reads PDF files directly in .NET. It has no native dependencies and does not need a browser, printer driver, or Office installation.
dotnet add package OfficeIMO.Pdf
Create a PDF
PdfDocument.Create takes a builder callback. Content flows down the page and breaks onto new pages automatically.
C#
using OfficeIMO;
using OfficeIMO.Pdf;
byte[] logo = File.ReadAllBytes("logo.png");
PdfDocument.Create(pdf => pdf.Content(content => content
.H1("Service review")
.AddParagraph("All scheduled checks passed. Two follow-ups remain open.")
.AddTable(new[] {
new[] { "Task", "Owner", "Due" },
new[] { "Rotate certificates", "Platform", "4 Nov" },
new[] { "Renew backup licence", "Operations", "12 Nov" } })
.AddImage(logo, OfficeLength.Points(120), OfficeLength.Points(48), OfficeAlignment.Right)),
new PdfCreateOptions { CreateOutlineFromHeadings = true })
.Meta(title: "Service review", author: "Operations")
.Save("Service-review.pdf");
CreateOutlineFromHeadings turns headings into bookmarks. For rich text inside a paragraph, use the callback overload:
using OfficeIMO.Pdf;
PdfDocument.Create(pdf => pdf.Content(content => content
.AddParagraph(p => {
p.AddText("Status: ");
p.AddText("Healthy").SetBold();
})))
.Save("Status.pdf");
PowerShell
$services = @(
[pscustomobject]@{ Name = 'Directory'; Status = 'Healthy'; Incidents = 0 }
[pscustomobject]@{ Name = 'Mail'; Status = 'Watch'; Incidents = 2 }
)
New-OfficePdf -Path .\Service-review.pdf -CreateOutlineFromHeadings {
PdfHeading 'Service review'
PdfParagraph 'All scheduled checks passed. Two follow-ups remain open.'
PdfTable -InputObject $services
}
CLI
Convert an existing document instead of composing one:
officeimo convert report.docx report.pdf
officeimo convert notes.md notes.pdf
Load a PDF and read it
C#
using OfficeIMO.Pdf;
PdfDocument pdf = PdfDocument.Load("Service-review.pdf");
Console.WriteLine($"{pdf.Pages.Count} page(s)");
Console.WriteLine(pdf.ExtractText());
PowerShell
Read-OfficeDocument -Path .\Service-review.pdf -As Text
CLI
officeimo read Service-review.pdf --format markdown
Next steps
- Merge, split, and select pages
- Extract text and tables
- Fill and flatten forms
- Redact content
- Encrypt and sign
- Convert to PDF/A
- Watermarks and stamps
Limits and reference
Limits: see the PDF package row in the compatibility matrix.
Reference: OfficeIMO.Pdf API