mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Utilities: Add a pdf
utility
This utility will learn tricks such as extracting images from PDFs and dumping tables from PDFs so that we can create code from specs. It also allows testing LibPDF things in lagom, and allows testing reading large amounts of PDFs using a shell script.
This commit is contained in:
parent
e7e454f1d6
commit
efad31dac1
Notes:
sideshowbarker
2024-07-17 01:23:08 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/efad31dac1 Pull-request: https://github.com/SerenityOS/serenity/pull/19777
3 changed files with 51 additions and 0 deletions
|
@ -555,6 +555,9 @@ if (BUILD_LAGOM)
|
|||
target_link_libraries(ntpquery LibCore LibMain)
|
||||
endif()
|
||||
|
||||
add_executable(pdf ../../Userland/Utilities/pdf.cpp)
|
||||
target_link_libraries(pdf LibCore LibPDF LibMain)
|
||||
|
||||
add_executable(sql ../../Userland/Utilities/sql.cpp)
|
||||
target_link_libraries(sql LibCore LibFileSystem LibIPC LibLine LibMain LibSQL)
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ target_link_libraries(notify PRIVATE LibGfx LibGUI)
|
|||
target_link_libraries(open PRIVATE LibDesktop LibFileSystem)
|
||||
target_link_libraries(passwd PRIVATE LibCrypt)
|
||||
target_link_libraries(paste PRIVATE LibGUI)
|
||||
target_link_libraries(pdf PRIVATE LibPDF)
|
||||
target_link_libraries(pgrep PRIVATE LibRegex)
|
||||
target_link_libraries(pixelflut PRIVATE LibImageDecoderClient LibIPC LibGfx)
|
||||
target_link_libraries(pkill PRIVATE LibRegex)
|
||||
|
|
47
Userland/Utilities/pdf.cpp
Normal file
47
Userland/Utilities/pdf.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Nico Weber <thakis@chromium.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibPDF/Document.h>
|
||||
|
||||
static PDF::PDFErrorOr<int> pdf_main(Main::Arguments arguments)
|
||||
{
|
||||
Core::ArgsParser args_parser;
|
||||
|
||||
StringView in_path;
|
||||
args_parser.add_positional_argument(in_path, "Path to input image file", "FILE");
|
||||
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::MappedFile::map(in_path));
|
||||
|
||||
auto document = TRY(PDF::Document::create(file->bytes()));
|
||||
|
||||
if (auto handler = document->security_handler(); handler && !handler->has_user_password()) {
|
||||
// FIXME: Add a flag for passing in a password and suggest it in this diag.
|
||||
warnln("PDF requires password");
|
||||
return 1;
|
||||
}
|
||||
|
||||
TRY(document->initialize());
|
||||
|
||||
outln("{} pages", document->get_page_count());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
auto maybe_error = pdf_main(move(arguments));
|
||||
if (maybe_error.is_error()) {
|
||||
auto error = maybe_error.release_error();
|
||||
warnln("{}", error.message());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue