1 // Copyright (c) 2010 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.
10 #include "base/containers/span.h"
11 #include "build/build_config.h"
18 typedef void (*PDFEnsureTypefaceCharactersAccessible)(const LOGFONT* font,
28 namespace chrome_pdf {
31 // Printing modes - type to convert PDF to for printing
39 // |pdf_buffer| is the buffer that contains the entire PDF document to be
41 // |page_number| is the 0-based index of the page to be rendered.
42 // |dc| is the device context to render into.
43 // |dpi_x| and |dpi_y| is the resolution.
44 // |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height|
45 // specify a bounds rectangle within the DC in which to render the PDF
47 // |fit_to_bounds| specifies whether the output should be shrunk to fit the
48 // supplied bounds if the page size is larger than the bounds in any
49 // dimension. If this is false, parts of the PDF page that lie outside
50 // the bounds will be clipped.
51 // |stretch_to_bounds| specifies whether the output should be stretched to fit
52 // the supplied bounds if the page size is smaller than the bounds in any
54 // If both |fit_to_bounds| and |stretch_to_bounds| are true, then
55 // |fit_to_bounds| is honored first.
56 // |keep_aspect_ratio| If any scaling is to be done is true, this flag
57 // specifies whether the original aspect ratio of the page should be
58 // preserved while scaling.
59 // |center_in_bounds| specifies whether the final image (after any scaling is
60 // done) should be centered within the given bounds.
61 // |autorotate| specifies whether the final image should be rotated to match
63 // |use_color| specifies color or grayscale.
64 // Returns false if the document or the page number are not valid.
65 bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer,
75 bool stretch_to_bounds,
76 bool keep_aspect_ratio,
77 bool center_in_bounds,
81 void SetPDFEnsureTypefaceCharactersAccessible(
82 PDFEnsureTypefaceCharactersAccessible func);
84 void SetPDFUseGDIPrinting(bool enable);
86 void SetPDFUsePrintMode(int mode);
87 #endif // defined(OS_WIN)
89 // |page_count| and |max_page_width| are optional and can be NULL.
90 // Returns false if the document is not valid.
91 bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
93 double* max_page_width);
95 // Gets the dimensions of a specific page in a document.
96 // |pdf_buffer| is the buffer that contains the entire PDF document to be
98 // |page_number| is the page number that the function will get the dimensions
100 // |width| is the output for the width of the page in points.
101 // |height| is the output for the height of the page in points.
102 // Returns false if the document or the page number are not valid.
103 bool GetPDFPageSizeByIndex(base::span<const uint8_t> pdf_buffer,
108 // Renders PDF page into 4-byte per pixel BGRA color bitmap.
109 // |pdf_buffer| is the buffer that contains the entire PDF document to be
111 // |page_number| is the 0-based index of the page to be rendered.
112 // |bitmap_buffer| is the output buffer for bitmap.
113 // |bitmap_width| is the width of the output bitmap.
114 // |bitmap_height| is the height of the output bitmap.
115 // |dpi_x| and |dpi_y| is the resolution.
116 // |autorotate| specifies whether the final image should be rotated to match
118 // |use_color| specifies color or grayscale.
119 // Returns false if the document or the page number are not valid.
120 bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
130 // Convert multiple PDF pages into a N-up PDF.
131 // |input_buffers| is the vector of buffers with each buffer contains a PDF.
132 // If any of the PDFs contains multiple pages, only the first page of the
134 // |pages_per_sheet| is the number of pages to put on one sheet.
135 // |page_size| is the output page size, measured in PDF "user space" units.
136 // |printable_area| is the output page printable area, measured in PDF
137 // "user space" units. Should be smaller than |page_size|.
139 // |page_size| is the print media size. The page size of the output N-up PDF is
140 // determined by the |pages_per_sheet|, the orientation of the PDF pages
141 // contained in the |input_buffers|, and the media page size |page_size|. For
142 // example, when |page_size| = 512x792, |pages_per_sheet| = 2, and the
143 // orientation of |input_buffers| = portrait, the output N-up PDF will be
145 // See printing::NupParameters for more details on how the output page
146 // orientation is determined, to understand why |page_size| may be swapped in
148 std::vector<uint8_t> ConvertPdfPagesToNupPdf(
149 std::vector<base::span<const uint8_t>> input_buffers,
150 size_t pages_per_sheet,
151 const gfx::Size& page_size,
152 const gfx::Rect& printable_area);
154 // Convert a PDF document to a N-up PDF document.
155 // |input_buffer| is the buffer that contains the entire PDF document to be
156 // converted to a N-up PDF document.
157 // |pages_per_sheet| is the number of pages to put on one sheet.
158 // |page_size| is the output page size, measured in PDF "user space" units.
159 // |printable_area| is the output page printable area, measured in PDF
160 // "user space" units. Should be smaller than |page_size|.
162 // Refer to the description of ConvertPdfPagesToNupPdf to understand how the
163 // output page size will be calculated.
164 // The algorithm used to determine the output page size is the same.
165 std::vector<uint8_t> ConvertPdfDocumentToNupPdf(
166 base::span<const uint8_t> input_buffer,
167 size_t pages_per_sheet,
168 const gfx::Size& page_size,
169 const gfx::Rect& printable_area);
171 } // namespace chrome_pdf