pdfium_print.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef PDF_PDFIUM_PDFIUM_PRINT_H_
  5. #define PDF_PDFIUM_PDFIUM_PRINT_H_
  6. #include <vector>
  7. #include "base/memory/raw_ptr.h"
  8. #include "build/build_config.h"
  9. #include "third_party/pdfium/public/cpp/fpdf_scopers.h"
  10. #include "third_party/pdfium/public/fpdfview.h"
  11. namespace blink {
  12. struct WebPrintParams;
  13. } // namespace blink
  14. namespace gfx {
  15. class Rect;
  16. class Size;
  17. } // namespace gfx
  18. namespace chrome_pdf {
  19. class PDFiumEngine;
  20. class PDFiumPrint {
  21. public:
  22. explicit PDFiumPrint(PDFiumEngine* engine);
  23. PDFiumPrint(const PDFiumPrint&) = delete;
  24. PDFiumPrint& operator=(const PDFiumPrint&) = delete;
  25. ~PDFiumPrint();
  26. #if BUILDFLAG(IS_CHROMEOS)
  27. // Flattens the `doc`.
  28. // On success, returns the flattened version of `doc` as a vector.
  29. // On failure, returns an empty vector.
  30. static std::vector<uint8_t> CreateFlattenedPdf(ScopedFPDFDocument doc);
  31. #endif // BUILDFLAG(IS_CHROMEOS)
  32. // Performs N-up PDF generation for `doc` based on `pages_per_sheet`,
  33. // `page_size`, and `printable_area`.
  34. // On success, returns the N-up version of `doc` as a vector.
  35. // On failure, returns an empty vector.
  36. static std::vector<uint8_t> CreateNupPdf(ScopedFPDFDocument doc,
  37. size_t pages_per_sheet,
  38. const gfx::Size& page_size,
  39. const gfx::Rect& printable_area);
  40. // Check the source doc orientation. Returns true if the doc is landscape.
  41. // For now the orientation of the doc is determined by its first page's
  42. // orientation. Improvement can be added in the future to better determine
  43. // the orientation of the source docs that have mixed orientation.
  44. // TODO(xlou): rotate pages if the source doc has mixed orientation. So that
  45. // the orientation of all pages of the doc are uniform. Pages of square size
  46. // will not be rotated.
  47. static bool IsSourcePdfLandscape(FPDF_DOCUMENT doc);
  48. static void FitContentsToPrintableArea(FPDF_DOCUMENT doc,
  49. const gfx::Size& page_size,
  50. const gfx::Rect& printable_area);
  51. std::vector<uint8_t> PrintPagesAsPdf(
  52. const std::vector<int>& page_numbers,
  53. const blink::WebPrintParams& print_params);
  54. private:
  55. ScopedFPDFDocument CreatePrintPdf(const std::vector<int>& page_numbers,
  56. const blink::WebPrintParams& print_params);
  57. ScopedFPDFDocument CreateRasterPdf(ScopedFPDFDocument doc, int dpi);
  58. ScopedFPDFDocument CreateSinglePageRasterPdf(FPDF_PAGE page_to_print,
  59. int dpi);
  60. const raw_ptr<PDFiumEngine> engine_;
  61. };
  62. } // namespace chrome_pdf
  63. #endif // PDF_PDFIUM_PDFIUM_PRINT_H_