$ErrorActionPreference = "Stop"
$dir = Join-Path ([Environment]::GetFolderPath("Desktop")) "LR4"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
New-Item -ItemType Directory -Force -Path "$dir\screenshots" | Out-Null
# Find LibreOffice
$lo = @(
"$env:ProgramFiles\LibreOffice\program\soffice.com",
"$env:ProgramFiles\LibreOffice\program\soffice.exe",
"${env:ProgramFiles(x86)}\LibreOffice\program\soffice.exe"
) | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $lo) {
throw "LibreOffice not found. Check installation."
}
# Create PDF source
$source = Join-Path $dir "LR4_PDF_encrypted.txt"
@"
Лабораторная работа № 4
Защищенный документооборот
Исследование методов парольной защиты
электронных документов.
Формат документа: PDF.
Способ защиты: шифрование с паролем на открытие.
Документ содержит учебную информацию.
"@ | Set-Content -Path $source -Encoding UTF8
# Export encrypted PDF
$filter = 'pdf:writer_pdf_Export:{"EncryptFile":{"type":"boolean","value":"true"},"DocumentOpenPassword":{"type":"string","value":"P7d!"}}'
& $lo --headless --convert-to $filter --outdir $dir $source
$pdf = Join-Path $dir "LR4_PDF_encrypted.pdf"
if (Test-Path $pdf) {
Write-Host "SUCCESS! PDF CREATED" -ForegroundColor Green
Write-Host "File: $pdf"
Write-Host "Password: P7d!"
} else {
throw "PDF creation failed"
}
explorer.exe $dir