Dtronix / PDFiumCore

.NET Standard P/Invoke bindings for PDFium.
Apache License 2.0
146 stars 23 forks source link

How to Print Pdf file with PDFiumCore #10

Closed fpenbegul closed 2 years ago

fpenbegul commented 2 years ago

PdfiumViewer is good alternative for print pdf directly on .net framework. But its not support .net core platform. Any good way to print pdf file directly, using PDFiumCore?

DJGosnell commented 2 years ago

Currently, there is not a method to do this as printing across multiple OSes, but there are methods to supposedly print directly from the library to a Win32 device context. See below for the Win32 only version of the FPDF_RenderPage and FPDF_SetPrintMode functions in the fpdfview.h header. I just never pursued this avenue since it would add special functionality to only certain environments.

While the main goal of this library is to provide common functionality throughout as many environments as possible, I would not be opposed to generating specific OS methods, I just don't have the time to invest in this right at the moment.

#ifdef _WIN32
// Function: FPDF_RenderPage
//          Render contents of a page to a device (screen, bitmap, or printer).
//          This function is only supported on Windows.
// Parameters:
//          dc          -   Handle to the device context.
//          page        -   Handle to the page. Returned by FPDF_LoadPage.
//          start_x     -   Left pixel position of the display area in
//                          device coordinates.
//          start_y     -   Top pixel position of the display area in device
//                          coordinates.
//          size_x      -   Horizontal size (in pixels) for displaying the page.
//          size_y      -   Vertical size (in pixels) for displaying the page.
//          rotate      -   Page orientation:
//                            0 (normal)
//                            1 (rotated 90 degrees clockwise)
//                            2 (rotated 180 degrees)
//                            3 (rotated 90 degrees counter-clockwise)
//          flags       -   0 for normal display, or combination of flags
//                          defined above.
// Return value:
//          None.
FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc,
                                               FPDF_PAGE page,
                                               int start_x,
                                               int start_y,
                                               int size_x,
                                               int size_y,
                                               int rotate,
                                               int flags);
#endif
#if defined(_WIN32)
// Experimental API.
// Function: FPDF_SetPrintMode
//          Set printing mode when printing on Windows.
// Parameters:
//          mode - FPDF_PRINTMODE_EMF to output EMF (default)
//                 FPDF_PRINTMODE_TEXTONLY to output text only (for charstream
//                 devices)
//                 FPDF_PRINTMODE_POSTSCRIPT2 to output level 2 PostScript into
//                 EMF as a series of GDI comments.
//                 FPDF_PRINTMODE_POSTSCRIPT3 to output level 3 PostScript into
//                 EMF as a series of GDI comments.
//                 FPDF_PRINTMODE_POSTSCRIPT2_PASSTHROUGH to output level 2
//                 PostScript via ExtEscape() in PASSTHROUGH mode.
//                 FPDF_PRINTMODE_POSTSCRIPT3_PASSTHROUGH to output level 3
//                 PostScript via ExtEscape() in PASSTHROUGH mode.
//                 FPDF_PRINTMODE_EMF_IMAGE_MASKS to output EMF, with more
//                 efficient processing of documents containing image masks.
//                 FPDF_PRINTMODE_POSTSCRIPT3_TYPE42 to output level 3
//                 PostScript with embedded Type 42 fonts, when applicable, into
//                 EMF as a series of GDI comments.
//                 FPDF_PRINTMODE_POSTSCRIPT3_TYPE42_PASSTHROUGH to output level
//                 3 PostScript with embedded Type 42 fonts, when applicable,
//                 via ExtEscape() in PASSTHROUGH mode.
// Return value:
//          True if successful, false if unsuccessful (typically invalid input).
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SetPrintMode(int mode);
#endif  // defined(_WIN32)
DJGosnell commented 2 years ago

Closing as outside of scope.