diff options
-rw-r--r-- | pdf/pdf.cc | 51 | ||||
-rw-r--r-- | pdf/pdf_engine.h | 6 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.cc | 14 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.h | 5 |
4 files changed, 66 insertions, 10 deletions
@@ -114,25 +114,26 @@ extern "C" { #if defined(OS_WIN) // |pdf_buffer| is the buffer that contains the entire PDF document to be // rendered. -// |buffer_size| is the size of pdf_buffer in bytes. +// |buffer_size| is the size of |pdf_buffer| in bytes. // |page_number| is the 0-based index of the page to be rendered. // |dc| is the device context to render into. -// |dpi_x| and |dpi_y| are the x and y resolutions respectively. If either value -// is -1, the dpi from the DC will be used. +// |dpi_x| and |dpi_y| are the x and y resolutions respectively. If either +// value is -1, the dpi from the DC will be used. // |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height| -// specify a bounds rectangle within the DC in which to render the PDF page. +// specify a bounds rectangle within the DC in which to render the PDF +// page. // |fit_to_bounds| specifies whether the output should be shrunk to fit the // supplied bounds if the page size is larger than the bounds in any -// dimension. If this is false, parts of the PDF page that lie outside the -// bounds will be clipped. +// dimension. If this is false, parts of the PDF page that lie outside +// the bounds will be clipped. // |stretch_to_bounds| specifies whether the output should be stretched to fit // the supplied bounds if the page size is smaller than the bounds in any // dimension. // If both |fit_to_bounds| and |stretch_to_bounds| are true, then // |fit_to_bounds| is honored first. -// |keep_aspect_ratio| If any scaling is to be done is true, this flag specifies -// whether the original aspect ratio of the page should be preserved while -// scaling. +// |keep_aspect_ratio| If any scaling is to be done is true, this flag +// specifies whether the original aspect ratio of the page should be +// preserved while scaling. // |center_in_bounds| specifies whether the final image (after any scaling is // done) should be centered within the given bounds. // |autorotate| specifies whether the final image should be rotated to match @@ -199,10 +200,40 @@ bool GetPDFDocInfo(const void* pdf_buffer, return ret; } +// Gets the dimensions of a specific page in a document. +// |pdf_buffer| is the buffer that contains the entire PDF document to be +// rendered. +// |pdf_buffer_size| is the size of |pdf_buffer| in bytes. +// |page_number| is the page number that the function will get the dimensions +// of. +// |width| is the output for the width of the page in points. +// |height| is the output for the height of the page in points. +// Returns false if the document or the page number are not valid. +PDF_USED PP_EXPORT +bool GetPDFPageSizeByIndex(const void* pdf_buffer, + int pdf_buffer_size, int page_number, + double* width, double* height) { + if (!g_sdk_initialized_via_pepper) { + void* data = NULL; +#if defined(OS_WIN) + data = g_hmodule; +#endif + if (!chrome_pdf::InitializeSDK(data)) + return false; + } + scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( + chrome_pdf::PDFEngineExports::Create()); + bool ret = engine_exports->GetPDFPageSizeByIndex( + pdf_buffer, pdf_buffer_size, page_number, width, height); + if (!g_sdk_initialized_via_pepper) + chrome_pdf::ShutdownSDK(); + return ret; +} + // Renders PDF page into 4-byte per pixel BGRA color bitmap. // |pdf_buffer| is the buffer that contains the entire PDF document to be // rendered. -// |pdf_buffer_size| is the size of pdf_buffer in bytes. +// |pdf_buffer_size| is the size of |pdf_buffer| in bytes. // |page_number| is the 0-based index of the page to be rendered. // |bitmap_buffer| is the output buffer for bitmap. // |bitmap_width| is the width of the output bitmap. diff --git a/pdf/pdf_engine.h b/pdf/pdf_engine.h index b8b6fda..b5bc95d 100644 --- a/pdf/pdf_engine.h +++ b/pdf/pdf_engine.h @@ -305,10 +305,16 @@ class PDFEngineExports { int page_number, const RenderingSettings& settings, void* bitmap_buffer) = 0; + virtual bool GetPDFDocInfo(const void* pdf_buffer, int buffer_size, int* page_count, double* max_page_width) = 0; + + // See the definition of GetPDFPageSizeByIndex in pdf.cc for details. + virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer, + int pdf_buffer_size, int page_number, + double* width, double* height) = 0; }; } // namespace chrome_pdf diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index 84aa47a..d87b6db 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -3387,4 +3387,18 @@ bool PDFiumEngineExports::GetPDFDocInfo(const void* pdf_buffer, return true; } +bool PDFiumEngineExports::GetPDFPageSizeByIndex( + const void* pdf_buffer, + int pdf_buffer_size, + int page_number, + double* width, + double* height) { + FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); + if (!doc) + return false; + bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; + FPDF_CloseDocument(doc); + return success; +} + } // namespace chrome_pdf diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index 4e764b1..6118470 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -614,6 +614,11 @@ class PDFiumEngineExports : public PDFEngineExports { int buffer_size, int* page_count, double* max_page_width); + + // See the definition of GetPDFPageSizeByIndex in pdf.cc for details. + virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer, + int pdf_buffer_size, int page_number, + double* width, double* height); }; } // namespace chrome_pdf |