mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
f5f7370562
This change changes PDFViaEMFPrintHelper so that instead of loading the entire contents of a PDF document into memory to pass to PDFium, it now simply passes PDFium a file system path to load the PDF from. This should help us reduce memory use (and potentially avoid running out of memory) when larger PDFs are printed. MozReview-Commit-ID: GISolZYC2GJ --HG-- extra : rebase_source : a59925542b6c075cd14c67577653163cc2d49c0f
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef PDFVIAEMFPRINTHELPER_H_
|
|
#define PDFVIAEMFPRINTHELPER_H_
|
|
|
|
#include "nsCOMPtr.h"
|
|
#include "PDFiumEngineShim.h"
|
|
#include "mozilla/Vector.h"
|
|
|
|
/* include windows.h for the HDC definitions that we need. */
|
|
#include <windows.h>
|
|
|
|
class nsIFile;
|
|
class nsFileInputStream;
|
|
|
|
namespace mozilla {
|
|
namespace widget {
|
|
|
|
/**
|
|
* This class helps draw a PDF file to a given Windows DC.
|
|
* To do that it first converts the PDF file to EMF.
|
|
* Windows EMF:
|
|
* https://msdn.microsoft.com/en-us/windows/hardware/drivers/print/emf-data-type
|
|
*/
|
|
class PDFViaEMFPrintHelper
|
|
{
|
|
public:
|
|
explicit PDFViaEMFPrintHelper(PRLibrary* aPDFiumLibrary);
|
|
~PDFViaEMFPrintHelper();
|
|
|
|
/** Loads the specified PDF file. */
|
|
NS_IMETHOD OpenDocument(nsIFile *aFile);
|
|
|
|
/** Releases document buffer. */
|
|
void CloseDocument();
|
|
|
|
int GetPageCount() { return mPDFiumEngine->GetPageCount(mPDFDoc); }
|
|
|
|
/** Convert specified PDF page to EMF and draw the EMF onto the given DC. */
|
|
bool DrawPage(HDC aPrinterDC, unsigned int aPageIndex,
|
|
int aPageWidth, int aPageHeight);
|
|
|
|
/** Convert specified PDF page to EMF and save it to file. */
|
|
bool DrawPageToFile(const wchar_t* aFilePath, unsigned int aPageIndex,
|
|
int aPageWidth, int aPageHeight);
|
|
|
|
private:
|
|
|
|
bool LoadPDFDataToBuffer(nsIFile *aFile);
|
|
|
|
bool RenderPageToDC(HDC aDC, unsigned int aPageIndex,
|
|
int aPageWidth, int aPageHeight);
|
|
|
|
UniquePtr<PDFiumEngineShim> mPDFiumEngine;
|
|
FPDF_DOCUMENT mPDFDoc;
|
|
PRLibrary* mPDFiumLibrary;
|
|
};
|
|
|
|
} // namespace widget
|
|
} // namespace mozilla
|
|
|
|
#endif /* PDFVIAEMFPRINTHELPER_H_ */ |