From d2b8dd5f34a21d0979b13cccd5e16f699eae56d5 Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Sat, 5 Feb 2022 23:50:13 +0100 Subject: [PATCH 1/6] Add start of implementation --- pdfium.go | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/pdfium.go b/pdfium.go index bda07f49..5541f5b0 100644 --- a/pdfium.go +++ b/pdfium.go @@ -191,6 +191,141 @@ type Pdfium interface { // FPDF_GetPageSizeByIndex returns the size of a page by the page index. FPDF_GetPageSizeByIndex(request *requests.FPDF_GetPageSizeByIndex) (*responses.FPDF_GetPageSizeByIndex, error) + // FPDF_InitLibrary + FPDF_InitLibrary(request *requests.FPDF_InitLibrary) (*responses.FPDF_InitLibrary, error) + + // FPDF_InitLibraryWithConfig + FPDF_InitLibraryWithConfig(request *requests.FPDF_InitLibraryWithConfig) (*responses.FPDF_InitLibraryWithConfig, error) + + // FPDF_DestroyLibrary + FPDF_DestroyLibrary(request *requests.FPDF_DestroyLibrary) (*responses.FPDF_DestroyLibrary, error) + + // FPDF_SetTypefaceAccessibleFunc + FPDF_SetTypefaceAccessibleFunc(request *requests.FPDF_SetTypefaceAccessibleFunc) (*responses.FPDF_SetTypefaceAccessibleFunc, error) + + // FPDF_SetPrintTextWithGDI + FPDF_SetPrintTextWithGDI(request *requests.FPDF_SetPrintTextWithGDI) (*responses.FPDF_SetPrintTextWithGDI, error) + + // FPDF_SetPrintMode + FPDF_SetPrintMode(request *requests.FPDF_SetPrintMode) (*responses.FPDF_SetPrintMode, error) + + // FPDF_DocumentHasValidCrossReferenceTable + FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable) (*responses.FPDF_DocumentHasValidCrossReferenceTable, error) + + // FPDF_GetTrailerEnds + FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds) (*responses.FPDF_GetTrailerEnds, error) + + // FPDF_GetPageWidthF + FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF) (*responses.FPDF_GetPageWidthF, error) + + // FPDF_GetPageHeightF + FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF) (*responses.FPDF_GetPageHeightF, error) + + // FPDF_GetPageBoundingBox + FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox) (*responses.FPDF_GetPageBoundingBox, error) + + // FPDF_GetPageSizeByIndexF + FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF) (*responses.FPDF_GetPageSizeByIndexF, error) + + // FPDF_RenderPage + FPDF_RenderPage(request *requests.FPDF_RenderPage) (*responses.FPDF_RenderPage, error) + + // FPDF_RenderPageBitmap + FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap) (*responses.FPDF_RenderPageBitmap, error) + + // FPDF_RenderPageBitmapWithMatrix + FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix) (*responses.FPDF_RenderPageBitmapWithMatrix, error) + + // FPDF_RenderPageSkp + FPDF_RenderPageSkp(request *requests.FPDF_RenderPageSkp) (*responses.FPDF_RenderPageSkp, error) + + // FPDF_DeviceToPage + FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage) (*responses.FPDF_DeviceToPage, error) + + // FPDF_PageToDevice + FPDF_PageToDevice(request *requests.FPDF_PageToDevice) (*responses.FPDF_PageToDevice, error) + + // FPDFBitmap_Create + FPDFBitmap_Create(request *requests.FPDFBitmap_Create) (*responses.FPDFBitmap_Create, error) + + // FPDFBitmap_CreateEx + FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx) (*responses.FPDFBitmap_CreateEx, error) + + // FPDFBitmap_GetFormat + FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat) (*responses.FPDFBitmap_GetFormat, error) + + // FPDFBitmap_FillRect + FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect) (*responses.FPDFBitmap_FillRect, error) + + // FPDFBitmap_GetBuffer + FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer) (*responses.FPDFBitmap_GetBuffer, error) + + // FPDFBitmap_GetWidth + FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth) (*responses.FPDFBitmap_GetWidth, error) + + // FPDFBitmap_GetHeight + FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight) (*responses.FPDFBitmap_GetHeight, error) + + // FPDFBitmap_GetStride + FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride) (*responses.FPDFBitmap_GetStride, error) + + // FPDFBitmap_Destroy + FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy) (*responses.FPDFBitmap_Destroy, error) + + // FPDF_VIEWERREF_GetPrintScaling + FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling) (*responses.FPDF_VIEWERREF_GetPrintScaling, error) + + // FPDF_VIEWERREF_GetNumCopies + FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies) (*responses.FPDF_VIEWERREF_GetNumCopies, error) + + // FPDF_VIEWERREF_GetPrintPageRange + FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange) (*responses.FPDF_VIEWERREF_GetPrintPageRange, error) + + // FPDF_VIEWERREF_GetPrintPageRangeCount + FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (*responses.FPDF_VIEWERREF_GetPrintPageRangeCount, error) + + // FPDF_VIEWERREF_GetPrintPageRangeElement + FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (*responses.FPDF_VIEWERREF_GetPrintPageRangeElement, error) + + // FPDF_VIEWERREF_GetDuplex + FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex) (*responses.FPDF_VIEWERREF_GetDuplex, error) + + // FPDF_VIEWERREF_GetName + FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName) (*responses.FPDF_VIEWERREF_GetName, error) + + // FPDF_CountNamedDests + FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests) (*responses.FPDF_CountNamedDests, error) + + // FPDF_GetNamedDestByName + FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName) (*responses.FPDF_GetNamedDestByName, error) + + // FPDF_GetNamedDest + FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest) (*responses.FPDF_GetNamedDest, error) + + // FPDF_GetXFAPacketCount + FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount) (*responses.FPDF_GetXFAPacketCount, error) + + // FPDF_GetXFAPacketName + FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName) (*responses.FPDF_GetXFAPacketName, error) + + // FPDF_GetXFAPacketContent + FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) + + // FPDF_GetRecommendedV8Flags + FPDF_GetRecommendedV8Flags(request *requests.FPDF_GetRecommendedV8Flags) (*responses.FPDF_GetRecommendedV8Flags, error) + + // FPDF_GetArrayBufferAllocatorSharedInstance + FPDF_GetArrayBufferAllocatorSharedInstance(request *requests.FPDF_GetArrayBufferAllocatorSharedInstance) (*responses.FPDF_GetArrayBufferAllocatorSharedInstance, error) + + // FPDF_BStr_Init + FPDF_BStr_Init(request *requests.FPDF_BStr_Init) (*responses.FPDF_BStr_Init, error) + + // FPDF_BStr_Set + FPDF_BStr_Set(request *requests.FPDF_BStr_Set) (*responses.FPDF_BStr_Set, error) + + // FPDF_BStr_Clear + FPDF_BStr_Clear(request *requests.FPDF_BStr_Clear) (*responses.FPDF_BStr_Clear, error) + // End fpdfview.h // Start fpdf_edit.h From 73149f5aa8b2f5cf024ca990c1b8a9c69d259f8c Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Sun, 6 Feb 2022 17:41:17 +0100 Subject: [PATCH 2/6] Implement leftover fpdfview.h methods --- enums/enums.go | 38 + internal/commons/generated.go | 988 +++++++++++++++++++++- internal/implementation/fpdfview.go | 733 +++++++++++++++- internal/implementation/implementation.go | 24 + internal/implementation/pagerange.go | 23 + multi_threaded/generated.go | 256 ++++++ pdfium.go | 159 ++-- requests/fpdfview.go | 173 ++++ responses/fpdfview.go | 129 ++- single_threaded/generated.go | 448 ++++++++++ structs/structs.go | 5 + 11 files changed, 2873 insertions(+), 103 deletions(-) create mode 100644 internal/implementation/pagerange.go diff --git a/enums/enums.go b/enums/enums.go index 99aa55ce..c630e6b4 100644 --- a/enums/enums.go +++ b/enums/enums.go @@ -130,3 +130,41 @@ const ( FPDF_TEXTRENDERMODE_FILL_STROKE_CLIP FPDF_TEXT_RENDERMODE = 6 FPDF_TEXTRENDERMODE_CLIP FPDF_TEXT_RENDERMODE = 7 ) + +type FPDF_BITMAP_FORMAT int + +const ( + FPDF_BITMAP_FORMAT_UNKNOWN FPDF_BITMAP_FORMAT = 0 // Unknown or unsupported format. + FPDF_BITMAP_FORMAT_GRAY FPDF_BITMAP_FORMAT = 1 // Gray scale bitmap, one byte per pixel. + FPDF_BITMAP_FORMAT_BGR FPDF_BITMAP_FORMAT = 2 // 3 bytes per pixel, byte order: blue, green, red. + FPDF_BITMAP_FORMAT_BGRX FPDF_BITMAP_FORMAT = 3 // 4 bytes per pixel, byte order: blue, green, red, unused. + FPDF_BITMAP_FORMAT_BGRA FPDF_BITMAP_FORMAT = 4 // 4 bytes per pixel, byte order: blue, green, red, alpha. +) + +type FPDF_DUPLEXTYPE int + +const ( + FPDF_DUPLEXTYPE_UNDEFINED FPDF_DUPLEXTYPE = 0 + FPDF_DUPLEXTYPE_SIMPLEX FPDF_DUPLEXTYPE = 1 + FPDF_DUPLEXTYPE_DUPLEX_FLIP_SHORT_EDGE FPDF_DUPLEXTYPE = 2 + FPDF_DUPLEXTYPE_DUPLEX_FLIP_LONG_EDGE FPDF_DUPLEXTYPE = 3 +) + +type FPDF_RENDER_FLAG int + +const ( + FPDF_RENDER_FLAG_ANNOT FPDF_RENDER_FLAG = 0x01 // Set if annotations are to be rendered. + FPDF_RENDER_FLAG_LCD_TEXT FPDF_RENDER_FLAG = 0x02 // Set if using text rendering optimized for LCD display. This flag will only take effect if anti-aliasing is enabled for text. + FPDF_RENDER_FLAG_NO_NATIVETEXT FPDF_RENDER_FLAG = 0x04 // Don't use the native text output available on some platforms. + FPDF_RENDER_FLAG_GRAYSCALE FPDF_RENDER_FLAG = 0x08 // Grayscale output. + FPDF_RENDER_FLAG_DEBUG_INFO FPDF_RENDER_FLAG = 0x80 // Obsolete, has no effect, retained for compatibility. + FPDF_RENDER_FLAG_NO_CATCH FPDF_RENDER_FLAG = 0x100 // Obsolete, has no effect, retained for compatibility. + FPDF_RENDER_FLAG_RENDER_LIMITEDIMAGECACHE FPDF_RENDER_FLAG = 0x200 // Limit image cache size. + FPDF_RENDER_FLAG_RENDER_FORCEHALFTONE FPDF_RENDER_FLAG = 0x400 // Always use halftone for image stretching. + FPDF_RENDER_FLAG_PRINTING FPDF_RENDER_FLAG = 0x800 // Render for printing. + FPDF_RENDER_FLAG_RENDER_NO_SMOOTHTEXT FPDF_RENDER_FLAG = 0x1000 // Set to disable anti-aliasing on text. This flag will also disable LCD optimization for text rendering. + FPDF_RENDER_FLAG_RENDER_NO_SMOOTHIMAGE FPDF_RENDER_FLAG = 0x2000 // Set to disable anti-aliasing on images. + FPDF_RENDER_FLAG_RENDER_NO_SMOOTHPATH FPDF_RENDER_FLAG = 0x4000 // Set to disable anti-aliasing on paths. + FPDF_RENDER_FLAG_REVERSE_BYTE_ORDER FPDF_RENDER_FLAG = 0x10 // Set whether to render in a reverse Byte order, this flag is only used when rendering to a bitmap. + FPDF_RENDER_FLAG_CONVERT_FILL_TO_STROKE FPDF_RENDER_FLAG = 0x20 // Set whether fill paths need to be stroked. This flag is only used when FPDF_COLORSCHEME is passed in, since with a single fill color for paths the boundaries of adjacent fill paths are less visible. +) diff --git a/internal/commons/generated.go b/internal/commons/generated.go index 0886e44d..8372d38b 100644 --- a/internal/commons/generated.go +++ b/internal/commons/generated.go @@ -23,6 +23,15 @@ type Pdfium interface { FPDFAttachment_HasKey(*requests.FPDFAttachment_HasKey) (*responses.FPDFAttachment_HasKey, error) FPDFAttachment_SetFile(*requests.FPDFAttachment_SetFile) (*responses.FPDFAttachment_SetFile, error) FPDFAttachment_SetStringValue(*requests.FPDFAttachment_SetStringValue) (*responses.FPDFAttachment_SetStringValue, error) + FPDFBitmap_Create(*requests.FPDFBitmap_Create) (*responses.FPDFBitmap_Create, error) + FPDFBitmap_CreateEx(*requests.FPDFBitmap_CreateEx) (*responses.FPDFBitmap_CreateEx, error) + FPDFBitmap_Destroy(*requests.FPDFBitmap_Destroy) (*responses.FPDFBitmap_Destroy, error) + FPDFBitmap_FillRect(*requests.FPDFBitmap_FillRect) (*responses.FPDFBitmap_FillRect, error) + FPDFBitmap_GetBuffer(*requests.FPDFBitmap_GetBuffer) (*responses.FPDFBitmap_GetBuffer, error) + FPDFBitmap_GetFormat(*requests.FPDFBitmap_GetFormat) (*responses.FPDFBitmap_GetFormat, error) + FPDFBitmap_GetHeight(*requests.FPDFBitmap_GetHeight) (*responses.FPDFBitmap_GetHeight, error) + FPDFBitmap_GetStride(*requests.FPDFBitmap_GetStride) (*responses.FPDFBitmap_GetStride, error) + FPDFBitmap_GetWidth(*requests.FPDFBitmap_GetWidth) (*responses.FPDFBitmap_GetWidth, error) FPDFBookmark_Find(*requests.FPDFBookmark_Find) (*responses.FPDFBookmark_Find, error) FPDFBookmark_GetAction(*requests.FPDFBookmark_GetAction) (*responses.FPDFBookmark_GetAction, error) FPDFBookmark_GetDest(*requests.FPDFBookmark_GetDest) (*responses.FPDFBookmark_GetDest, error) @@ -104,21 +113,34 @@ type Pdfium interface { FPDF_ClosePage(*requests.FPDF_ClosePage) (*responses.FPDF_ClosePage, error) FPDF_CloseXObject(*requests.FPDF_CloseXObject) (*responses.FPDF_CloseXObject, error) FPDF_CopyViewerPreferences(*requests.FPDF_CopyViewerPreferences) (*responses.FPDF_CopyViewerPreferences, error) + FPDF_CountNamedDests(*requests.FPDF_CountNamedDests) (*responses.FPDF_CountNamedDests, error) FPDF_CreateNewDocument(*requests.FPDF_CreateNewDocument) (*responses.FPDF_CreateNewDocument, error) + FPDF_DeviceToPage(*requests.FPDF_DeviceToPage) (*responses.FPDF_DeviceToPage, error) + FPDF_DocumentHasValidCrossReferenceTable(*requests.FPDF_DocumentHasValidCrossReferenceTable) (*responses.FPDF_DocumentHasValidCrossReferenceTable, error) FPDF_GetDocPermissions(*requests.FPDF_GetDocPermissions) (*responses.FPDF_GetDocPermissions, error) FPDF_GetFileIdentifier(*requests.FPDF_GetFileIdentifier) (*responses.FPDF_GetFileIdentifier, error) FPDF_GetFileVersion(*requests.FPDF_GetFileVersion) (*responses.FPDF_GetFileVersion, error) FPDF_GetLastError(*requests.FPDF_GetLastError) (*responses.FPDF_GetLastError, error) FPDF_GetMetaText(*requests.FPDF_GetMetaText) (*responses.FPDF_GetMetaText, error) + FPDF_GetNamedDest(*requests.FPDF_GetNamedDest) (*responses.FPDF_GetNamedDest, error) + FPDF_GetNamedDestByName(*requests.FPDF_GetNamedDestByName) (*responses.FPDF_GetNamedDestByName, error) FPDF_GetPageAAction(*requests.FPDF_GetPageAAction) (*responses.FPDF_GetPageAAction, error) + FPDF_GetPageBoundingBox(*requests.FPDF_GetPageBoundingBox) (*responses.FPDF_GetPageBoundingBox, error) FPDF_GetPageCount(*requests.FPDF_GetPageCount) (*responses.FPDF_GetPageCount, error) FPDF_GetPageHeight(*requests.FPDF_GetPageHeight) (*responses.FPDF_GetPageHeight, error) + FPDF_GetPageHeightF(*requests.FPDF_GetPageHeightF) (*responses.FPDF_GetPageHeightF, error) FPDF_GetPageLabel(*requests.FPDF_GetPageLabel) (*responses.FPDF_GetPageLabel, error) FPDF_GetPageSizeByIndex(*requests.FPDF_GetPageSizeByIndex) (*responses.FPDF_GetPageSizeByIndex, error) + FPDF_GetPageSizeByIndexF(*requests.FPDF_GetPageSizeByIndexF) (*responses.FPDF_GetPageSizeByIndexF, error) FPDF_GetPageWidth(*requests.FPDF_GetPageWidth) (*responses.FPDF_GetPageWidth, error) + FPDF_GetPageWidthF(*requests.FPDF_GetPageWidthF) (*responses.FPDF_GetPageWidthF, error) FPDF_GetSecurityHandlerRevision(*requests.FPDF_GetSecurityHandlerRevision) (*responses.FPDF_GetSecurityHandlerRevision, error) FPDF_GetSignatureCount(*requests.FPDF_GetSignatureCount) (*responses.FPDF_GetSignatureCount, error) FPDF_GetSignatureObject(*requests.FPDF_GetSignatureObject) (*responses.FPDF_GetSignatureObject, error) + FPDF_GetTrailerEnds(*requests.FPDF_GetTrailerEnds) (*responses.FPDF_GetTrailerEnds, error) + FPDF_GetXFAPacketContent(*requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) + FPDF_GetXFAPacketCount(*requests.FPDF_GetXFAPacketCount) (*responses.FPDF_GetXFAPacketCount, error) + FPDF_GetXFAPacketName(*requests.FPDF_GetXFAPacketName) (*responses.FPDF_GetXFAPacketName, error) FPDF_ImportNPagesToOne(*requests.FPDF_ImportNPagesToOne) (*responses.FPDF_ImportNPagesToOne, error) FPDF_ImportPages(*requests.FPDF_ImportPages) (*responses.FPDF_ImportPages, error) FPDF_ImportPagesByIndex(*requests.FPDF_ImportPagesByIndex) (*responses.FPDF_ImportPagesByIndex, error) @@ -129,9 +151,19 @@ type Pdfium interface { FPDF_LoadPage(*requests.FPDF_LoadPage) (*responses.FPDF_LoadPage, error) FPDF_NewFormObjectFromXObject(*requests.FPDF_NewFormObjectFromXObject) (*responses.FPDF_NewFormObjectFromXObject, error) FPDF_NewXObjectFromPage(*requests.FPDF_NewXObjectFromPage) (*responses.FPDF_NewXObjectFromPage, error) + FPDF_PageToDevice(*requests.FPDF_PageToDevice) (*responses.FPDF_PageToDevice, error) + FPDF_RenderPageBitmap(*requests.FPDF_RenderPageBitmap) (*responses.FPDF_RenderPageBitmap, error) + FPDF_RenderPageBitmapWithMatrix(*requests.FPDF_RenderPageBitmapWithMatrix) (*responses.FPDF_RenderPageBitmapWithMatrix, error) FPDF_SaveAsCopy(*requests.FPDF_SaveAsCopy) (*responses.FPDF_SaveAsCopy, error) FPDF_SaveWithVersion(*requests.FPDF_SaveWithVersion) (*responses.FPDF_SaveWithVersion, error) FPDF_SetSandBoxPolicy(*requests.FPDF_SetSandBoxPolicy) (*responses.FPDF_SetSandBoxPolicy, error) + FPDF_VIEWERREF_GetDuplex(*requests.FPDF_VIEWERREF_GetDuplex) (*responses.FPDF_VIEWERREF_GetDuplex, error) + FPDF_VIEWERREF_GetName(*requests.FPDF_VIEWERREF_GetName) (*responses.FPDF_VIEWERREF_GetName, error) + FPDF_VIEWERREF_GetNumCopies(*requests.FPDF_VIEWERREF_GetNumCopies) (*responses.FPDF_VIEWERREF_GetNumCopies, error) + FPDF_VIEWERREF_GetPrintPageRange(*requests.FPDF_VIEWERREF_GetPrintPageRange) (*responses.FPDF_VIEWERREF_GetPrintPageRange, error) + FPDF_VIEWERREF_GetPrintPageRangeCount(*requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (*responses.FPDF_VIEWERREF_GetPrintPageRangeCount, error) + FPDF_VIEWERREF_GetPrintPageRangeElement(*requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (*responses.FPDF_VIEWERREF_GetPrintPageRangeElement, error) + FPDF_VIEWERREF_GetPrintScaling(*requests.FPDF_VIEWERREF_GetPrintScaling) (*responses.FPDF_VIEWERREF_GetPrintScaling, error) FSDK_SetLocaltimeFunction(*requests.FSDK_SetLocaltimeFunction) (*responses.FSDK_SetLocaltimeFunction, error) FSDK_SetTimeFunction(*requests.FSDK_SetTimeFunction) (*responses.FSDK_SetTimeFunction, error) FSDK_SetUnSpObjProcessHandler(*requests.FSDK_SetUnSpObjProcessHandler) (*responses.FSDK_SetUnSpObjProcessHandler, error) @@ -264,6 +296,96 @@ func (g *PdfiumRPC) FPDFAttachment_SetStringValue(request *requests.FPDFAttachme return resp, nil } +func (g *PdfiumRPC) FPDFBitmap_Create(request *requests.FPDFBitmap_Create) (*responses.FPDFBitmap_Create, error) { + resp := &responses.FPDFBitmap_Create{} + err := g.client.Call("Plugin.FPDFBitmap_Create", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx) (*responses.FPDFBitmap_CreateEx, error) { + resp := &responses.FPDFBitmap_CreateEx{} + err := g.client.Call("Plugin.FPDFBitmap_CreateEx", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy) (*responses.FPDFBitmap_Destroy, error) { + resp := &responses.FPDFBitmap_Destroy{} + err := g.client.Call("Plugin.FPDFBitmap_Destroy", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect) (*responses.FPDFBitmap_FillRect, error) { + resp := &responses.FPDFBitmap_FillRect{} + err := g.client.Call("Plugin.FPDFBitmap_FillRect", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer) (*responses.FPDFBitmap_GetBuffer, error) { + resp := &responses.FPDFBitmap_GetBuffer{} + err := g.client.Call("Plugin.FPDFBitmap_GetBuffer", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat) (*responses.FPDFBitmap_GetFormat, error) { + resp := &responses.FPDFBitmap_GetFormat{} + err := g.client.Call("Plugin.FPDFBitmap_GetFormat", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight) (*responses.FPDFBitmap_GetHeight, error) { + resp := &responses.FPDFBitmap_GetHeight{} + err := g.client.Call("Plugin.FPDFBitmap_GetHeight", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride) (*responses.FPDFBitmap_GetStride, error) { + resp := &responses.FPDFBitmap_GetStride{} + err := g.client.Call("Plugin.FPDFBitmap_GetStride", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth) (*responses.FPDFBitmap_GetWidth, error) { + resp := &responses.FPDFBitmap_GetWidth{} + err := g.client.Call("Plugin.FPDFBitmap_GetWidth", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDFBookmark_Find(request *requests.FPDFBookmark_Find) (*responses.FPDFBookmark_Find, error) { resp := &responses.FPDFBookmark_Find{} err := g.client.Call("Plugin.FPDFBookmark_Find", request, resp) @@ -1074,6 +1196,16 @@ func (g *PdfiumRPC) FPDF_CopyViewerPreferences(request *requests.FPDF_CopyViewer return resp, nil } +func (g *PdfiumRPC) FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests) (*responses.FPDF_CountNamedDests, error) { + resp := &responses.FPDF_CountNamedDests{} + err := g.client.Call("Plugin.FPDF_CountNamedDests", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_CreateNewDocument(request *requests.FPDF_CreateNewDocument) (*responses.FPDF_CreateNewDocument, error) { resp := &responses.FPDF_CreateNewDocument{} err := g.client.Call("Plugin.FPDF_CreateNewDocument", request, resp) @@ -1084,6 +1216,26 @@ func (g *PdfiumRPC) FPDF_CreateNewDocument(request *requests.FPDF_CreateNewDocum return resp, nil } +func (g *PdfiumRPC) FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage) (*responses.FPDF_DeviceToPage, error) { + resp := &responses.FPDF_DeviceToPage{} + err := g.client.Call("Plugin.FPDF_DeviceToPage", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable) (*responses.FPDF_DocumentHasValidCrossReferenceTable, error) { + resp := &responses.FPDF_DocumentHasValidCrossReferenceTable{} + err := g.client.Call("Plugin.FPDF_DocumentHasValidCrossReferenceTable", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_GetDocPermissions(request *requests.FPDF_GetDocPermissions) (*responses.FPDF_GetDocPermissions, error) { resp := &responses.FPDF_GetDocPermissions{} err := g.client.Call("Plugin.FPDF_GetDocPermissions", request, resp) @@ -1134,6 +1286,26 @@ func (g *PdfiumRPC) FPDF_GetMetaText(request *requests.FPDF_GetMetaText) (*respo return resp, nil } +func (g *PdfiumRPC) FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest) (*responses.FPDF_GetNamedDest, error) { + resp := &responses.FPDF_GetNamedDest{} + err := g.client.Call("Plugin.FPDF_GetNamedDest", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName) (*responses.FPDF_GetNamedDestByName, error) { + resp := &responses.FPDF_GetNamedDestByName{} + err := g.client.Call("Plugin.FPDF_GetNamedDestByName", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_GetPageAAction(request *requests.FPDF_GetPageAAction) (*responses.FPDF_GetPageAAction, error) { resp := &responses.FPDF_GetPageAAction{} err := g.client.Call("Plugin.FPDF_GetPageAAction", request, resp) @@ -1144,6 +1316,16 @@ func (g *PdfiumRPC) FPDF_GetPageAAction(request *requests.FPDF_GetPageAAction) ( return resp, nil } +func (g *PdfiumRPC) FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox) (*responses.FPDF_GetPageBoundingBox, error) { + resp := &responses.FPDF_GetPageBoundingBox{} + err := g.client.Call("Plugin.FPDF_GetPageBoundingBox", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_GetPageCount(request *requests.FPDF_GetPageCount) (*responses.FPDF_GetPageCount, error) { resp := &responses.FPDF_GetPageCount{} err := g.client.Call("Plugin.FPDF_GetPageCount", request, resp) @@ -1164,6 +1346,16 @@ func (g *PdfiumRPC) FPDF_GetPageHeight(request *requests.FPDF_GetPageHeight) (*r return resp, nil } +func (g *PdfiumRPC) FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF) (*responses.FPDF_GetPageHeightF, error) { + resp := &responses.FPDF_GetPageHeightF{} + err := g.client.Call("Plugin.FPDF_GetPageHeightF", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_GetPageLabel(request *requests.FPDF_GetPageLabel) (*responses.FPDF_GetPageLabel, error) { resp := &responses.FPDF_GetPageLabel{} err := g.client.Call("Plugin.FPDF_GetPageLabel", request, resp) @@ -1184,6 +1376,16 @@ func (g *PdfiumRPC) FPDF_GetPageSizeByIndex(request *requests.FPDF_GetPageSizeBy return resp, nil } +func (g *PdfiumRPC) FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF) (*responses.FPDF_GetPageSizeByIndexF, error) { + resp := &responses.FPDF_GetPageSizeByIndexF{} + err := g.client.Call("Plugin.FPDF_GetPageSizeByIndexF", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) (*responses.FPDF_GetPageWidth, error) { resp := &responses.FPDF_GetPageWidth{} err := g.client.Call("Plugin.FPDF_GetPageWidth", request, resp) @@ -1194,6 +1396,16 @@ func (g *PdfiumRPC) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) (*res return resp, nil } +func (g *PdfiumRPC) FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF) (*responses.FPDF_GetPageWidthF, error) { + resp := &responses.FPDF_GetPageWidthF{} + err := g.client.Call("Plugin.FPDF_GetPageWidthF", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_GetSecurityHandlerRevision(request *requests.FPDF_GetSecurityHandlerRevision) (*responses.FPDF_GetSecurityHandlerRevision, error) { resp := &responses.FPDF_GetSecurityHandlerRevision{} err := g.client.Call("Plugin.FPDF_GetSecurityHandlerRevision", request, resp) @@ -1224,6 +1436,46 @@ func (g *PdfiumRPC) FPDF_GetSignatureObject(request *requests.FPDF_GetSignatureO return resp, nil } +func (g *PdfiumRPC) FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds) (*responses.FPDF_GetTrailerEnds, error) { + resp := &responses.FPDF_GetTrailerEnds{} + err := g.client.Call("Plugin.FPDF_GetTrailerEnds", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) { + resp := &responses.FPDF_GetXFAPacketContent{} + err := g.client.Call("Plugin.FPDF_GetXFAPacketContent", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount) (*responses.FPDF_GetXFAPacketCount, error) { + resp := &responses.FPDF_GetXFAPacketCount{} + err := g.client.Call("Plugin.FPDF_GetXFAPacketCount", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName) (*responses.FPDF_GetXFAPacketName, error) { + resp := &responses.FPDF_GetXFAPacketName{} + err := g.client.Call("Plugin.FPDF_GetXFAPacketName", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_ImportNPagesToOne(request *requests.FPDF_ImportNPagesToOne) (*responses.FPDF_ImportNPagesToOne, error) { resp := &responses.FPDF_ImportNPagesToOne{} err := g.client.Call("Plugin.FPDF_ImportNPagesToOne", request, resp) @@ -1324,6 +1576,36 @@ func (g *PdfiumRPC) FPDF_NewXObjectFromPage(request *requests.FPDF_NewXObjectFro return resp, nil } +func (g *PdfiumRPC) FPDF_PageToDevice(request *requests.FPDF_PageToDevice) (*responses.FPDF_PageToDevice, error) { + resp := &responses.FPDF_PageToDevice{} + err := g.client.Call("Plugin.FPDF_PageToDevice", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap) (*responses.FPDF_RenderPageBitmap, error) { + resp := &responses.FPDF_RenderPageBitmap{} + err := g.client.Call("Plugin.FPDF_RenderPageBitmap", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix) (*responses.FPDF_RenderPageBitmapWithMatrix, error) { + resp := &responses.FPDF_RenderPageBitmapWithMatrix{} + err := g.client.Call("Plugin.FPDF_RenderPageBitmapWithMatrix", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FPDF_SaveAsCopy(request *requests.FPDF_SaveAsCopy) (*responses.FPDF_SaveAsCopy, error) { resp := &responses.FPDF_SaveAsCopy{} err := g.client.Call("Plugin.FPDF_SaveAsCopy", request, resp) @@ -1354,6 +1636,76 @@ func (g *PdfiumRPC) FPDF_SetSandBoxPolicy(request *requests.FPDF_SetSandBoxPolic return resp, nil } +func (g *PdfiumRPC) FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex) (*responses.FPDF_VIEWERREF_GetDuplex, error) { + resp := &responses.FPDF_VIEWERREF_GetDuplex{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetDuplex", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName) (*responses.FPDF_VIEWERREF_GetName, error) { + resp := &responses.FPDF_VIEWERREF_GetName{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetName", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies) (*responses.FPDF_VIEWERREF_GetNumCopies, error) { + resp := &responses.FPDF_VIEWERREF_GetNumCopies{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetNumCopies", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange) (*responses.FPDF_VIEWERREF_GetPrintPageRange, error) { + resp := &responses.FPDF_VIEWERREF_GetPrintPageRange{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetPrintPageRange", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (*responses.FPDF_VIEWERREF_GetPrintPageRangeCount, error) { + resp := &responses.FPDF_VIEWERREF_GetPrintPageRangeCount{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetPrintPageRangeCount", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (*responses.FPDF_VIEWERREF_GetPrintPageRangeElement, error) { + resp := &responses.FPDF_VIEWERREF_GetPrintPageRangeElement{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetPrintPageRangeElement", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *PdfiumRPC) FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling) (*responses.FPDF_VIEWERREF_GetPrintScaling, error) { + resp := &responses.FPDF_VIEWERREF_GetPrintScaling{} + err := g.client.Call("Plugin.FPDF_VIEWERREF_GetPrintScaling", request, resp) + if err != nil { + return nil, err + } + + return resp, nil +} + func (g *PdfiumRPC) FSDK_SetLocaltimeFunction(request *requests.FSDK_SetLocaltimeFunction) (*responses.FSDK_SetLocaltimeFunction, error) { resp := &responses.FSDK_SetLocaltimeFunction{} err := g.client.Call("Plugin.FSDK_SetLocaltimeFunction", request, resp) @@ -1742,14 +2094,14 @@ func (s *PdfiumRPCServer) FPDFAttachment_SetStringValue(request *requests.FPDFAt return nil } -func (s *PdfiumRPCServer) FPDFBookmark_Find(request *requests.FPDFBookmark_Find, resp *responses.FPDFBookmark_Find) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_Create(request *requests.FPDFBitmap_Create, resp *responses.FPDFBitmap_Create) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_Find", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_Create", panicError) } }() - implResp, err := s.Impl.FPDFBookmark_Find(request) + implResp, err := s.Impl.FPDFBitmap_Create(request) if err != nil { return err } @@ -1760,14 +2112,14 @@ func (s *PdfiumRPCServer) FPDFBookmark_Find(request *requests.FPDFBookmark_Find, return nil } -func (s *PdfiumRPCServer) FPDFBookmark_GetAction(request *requests.FPDFBookmark_GetAction, resp *responses.FPDFBookmark_GetAction) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx, resp *responses.FPDFBitmap_CreateEx) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetAction", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_CreateEx", panicError) } }() - implResp, err := s.Impl.FPDFBookmark_GetAction(request) + implResp, err := s.Impl.FPDFBitmap_CreateEx(request) if err != nil { return err } @@ -1778,14 +2130,14 @@ func (s *PdfiumRPCServer) FPDFBookmark_GetAction(request *requests.FPDFBookmark_ return nil } -func (s *PdfiumRPCServer) FPDFBookmark_GetDest(request *requests.FPDFBookmark_GetDest, resp *responses.FPDFBookmark_GetDest) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy, resp *responses.FPDFBitmap_Destroy) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetDest", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_Destroy", panicError) } }() - implResp, err := s.Impl.FPDFBookmark_GetDest(request) + implResp, err := s.Impl.FPDFBitmap_Destroy(request) if err != nil { return err } @@ -1796,14 +2148,14 @@ func (s *PdfiumRPCServer) FPDFBookmark_GetDest(request *requests.FPDFBookmark_Ge return nil } -func (s *PdfiumRPCServer) FPDFBookmark_GetFirstChild(request *requests.FPDFBookmark_GetFirstChild, resp *responses.FPDFBookmark_GetFirstChild) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect, resp *responses.FPDFBitmap_FillRect) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetFirstChild", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_FillRect", panicError) } }() - implResp, err := s.Impl.FPDFBookmark_GetFirstChild(request) + implResp, err := s.Impl.FPDFBitmap_FillRect(request) if err != nil { return err } @@ -1814,14 +2166,14 @@ func (s *PdfiumRPCServer) FPDFBookmark_GetFirstChild(request *requests.FPDFBookm return nil } -func (s *PdfiumRPCServer) FPDFBookmark_GetNextSibling(request *requests.FPDFBookmark_GetNextSibling, resp *responses.FPDFBookmark_GetNextSibling) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer, resp *responses.FPDFBitmap_GetBuffer) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetNextSibling", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetBuffer", panicError) } }() - implResp, err := s.Impl.FPDFBookmark_GetNextSibling(request) + implResp, err := s.Impl.FPDFBitmap_GetBuffer(request) if err != nil { return err } @@ -1832,14 +2184,14 @@ func (s *PdfiumRPCServer) FPDFBookmark_GetNextSibling(request *requests.FPDFBook return nil } -func (s *PdfiumRPCServer) FPDFBookmark_GetTitle(request *requests.FPDFBookmark_GetTitle, resp *responses.FPDFBookmark_GetTitle) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat, resp *responses.FPDFBitmap_GetFormat) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetTitle", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetFormat", panicError) } }() - implResp, err := s.Impl.FPDFBookmark_GetTitle(request) + implResp, err := s.Impl.FPDFBitmap_GetFormat(request) if err != nil { return err } @@ -1850,14 +2202,14 @@ func (s *PdfiumRPCServer) FPDFBookmark_GetTitle(request *requests.FPDFBookmark_G return nil } -func (s *PdfiumRPCServer) FPDFCatalog_IsTagged(request *requests.FPDFCatalog_IsTagged, resp *responses.FPDFCatalog_IsTagged) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight, resp *responses.FPDFBitmap_GetHeight) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFCatalog_IsTagged", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetHeight", panicError) } }() - implResp, err := s.Impl.FPDFCatalog_IsTagged(request) + implResp, err := s.Impl.FPDFBitmap_GetHeight(request) if err != nil { return err } @@ -1868,14 +2220,14 @@ func (s *PdfiumRPCServer) FPDFCatalog_IsTagged(request *requests.FPDFCatalog_IsT return nil } -func (s *PdfiumRPCServer) FPDFDest_GetDestPageIndex(request *requests.FPDFDest_GetDestPageIndex, resp *responses.FPDFDest_GetDestPageIndex) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride, resp *responses.FPDFBitmap_GetStride) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFDest_GetDestPageIndex", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetStride", panicError) } }() - implResp, err := s.Impl.FPDFDest_GetDestPageIndex(request) + implResp, err := s.Impl.FPDFBitmap_GetStride(request) if err != nil { return err } @@ -1886,14 +2238,14 @@ func (s *PdfiumRPCServer) FPDFDest_GetDestPageIndex(request *requests.FPDFDest_G return nil } -func (s *PdfiumRPCServer) FPDFDest_GetLocationInPage(request *requests.FPDFDest_GetLocationInPage, resp *responses.FPDFDest_GetLocationInPage) (err error) { +func (s *PdfiumRPCServer) FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth, resp *responses.FPDFBitmap_GetWidth) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFDest_GetLocationInPage", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetWidth", panicError) } }() - implResp, err := s.Impl.FPDFDest_GetLocationInPage(request) + implResp, err := s.Impl.FPDFBitmap_GetWidth(request) if err != nil { return err } @@ -1904,14 +2256,176 @@ func (s *PdfiumRPCServer) FPDFDest_GetLocationInPage(request *requests.FPDFDest_ return nil } -func (s *PdfiumRPCServer) FPDFDest_GetView(request *requests.FPDFDest_GetView, resp *responses.FPDFDest_GetView) (err error) { +func (s *PdfiumRPCServer) FPDFBookmark_Find(request *requests.FPDFBookmark_Find, resp *responses.FPDFBookmark_Find) (err error) { defer func() { if panicError := recover(); panicError != nil { - err = fmt.Errorf("panic occurred in %s: %v", "FPDFDest_GetView", panicError) + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_Find", panicError) } }() - implResp, err := s.Impl.FPDFDest_GetView(request) + implResp, err := s.Impl.FPDFBookmark_Find(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFBookmark_GetAction(request *requests.FPDFBookmark_GetAction, resp *responses.FPDFBookmark_GetAction) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetAction", panicError) + } + }() + + implResp, err := s.Impl.FPDFBookmark_GetAction(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFBookmark_GetDest(request *requests.FPDFBookmark_GetDest, resp *responses.FPDFBookmark_GetDest) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetDest", panicError) + } + }() + + implResp, err := s.Impl.FPDFBookmark_GetDest(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFBookmark_GetFirstChild(request *requests.FPDFBookmark_GetFirstChild, resp *responses.FPDFBookmark_GetFirstChild) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetFirstChild", panicError) + } + }() + + implResp, err := s.Impl.FPDFBookmark_GetFirstChild(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFBookmark_GetNextSibling(request *requests.FPDFBookmark_GetNextSibling, resp *responses.FPDFBookmark_GetNextSibling) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetNextSibling", panicError) + } + }() + + implResp, err := s.Impl.FPDFBookmark_GetNextSibling(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFBookmark_GetTitle(request *requests.FPDFBookmark_GetTitle, resp *responses.FPDFBookmark_GetTitle) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBookmark_GetTitle", panicError) + } + }() + + implResp, err := s.Impl.FPDFBookmark_GetTitle(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFCatalog_IsTagged(request *requests.FPDFCatalog_IsTagged, resp *responses.FPDFCatalog_IsTagged) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFCatalog_IsTagged", panicError) + } + }() + + implResp, err := s.Impl.FPDFCatalog_IsTagged(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFDest_GetDestPageIndex(request *requests.FPDFDest_GetDestPageIndex, resp *responses.FPDFDest_GetDestPageIndex) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFDest_GetDestPageIndex", panicError) + } + }() + + implResp, err := s.Impl.FPDFDest_GetDestPageIndex(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFDest_GetLocationInPage(request *requests.FPDFDest_GetLocationInPage, resp *responses.FPDFDest_GetLocationInPage) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFDest_GetLocationInPage", panicError) + } + }() + + implResp, err := s.Impl.FPDFDest_GetLocationInPage(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDFDest_GetView(request *requests.FPDFDest_GetView, resp *responses.FPDFDest_GetView) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFDest_GetView", panicError) + } + }() + + implResp, err := s.Impl.FPDFDest_GetView(request) if err != nil { return err } @@ -3200,6 +3714,24 @@ func (s *PdfiumRPCServer) FPDF_CopyViewerPreferences(request *requests.FPDF_Copy return nil } +func (s *PdfiumRPCServer) FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests, resp *responses.FPDF_CountNamedDests) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_CountNamedDests", panicError) + } + }() + + implResp, err := s.Impl.FPDF_CountNamedDests(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_CreateNewDocument(request *requests.FPDF_CreateNewDocument, resp *responses.FPDF_CreateNewDocument) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3218,6 +3750,42 @@ func (s *PdfiumRPCServer) FPDF_CreateNewDocument(request *requests.FPDF_CreateNe return nil } +func (s *PdfiumRPCServer) FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage, resp *responses.FPDF_DeviceToPage) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_DeviceToPage", panicError) + } + }() + + implResp, err := s.Impl.FPDF_DeviceToPage(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable, resp *responses.FPDF_DocumentHasValidCrossReferenceTable) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_DocumentHasValidCrossReferenceTable", panicError) + } + }() + + implResp, err := s.Impl.FPDF_DocumentHasValidCrossReferenceTable(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_GetDocPermissions(request *requests.FPDF_GetDocPermissions, resp *responses.FPDF_GetDocPermissions) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3308,6 +3876,42 @@ func (s *PdfiumRPCServer) FPDF_GetMetaText(request *requests.FPDF_GetMetaText, r return nil } +func (s *PdfiumRPCServer) FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest, resp *responses.FPDF_GetNamedDest) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetNamedDest", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetNamedDest(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName, resp *responses.FPDF_GetNamedDestByName) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetNamedDestByName", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetNamedDestByName(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_GetPageAAction(request *requests.FPDF_GetPageAAction, resp *responses.FPDF_GetPageAAction) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3326,6 +3930,24 @@ func (s *PdfiumRPCServer) FPDF_GetPageAAction(request *requests.FPDF_GetPageAAct return nil } +func (s *PdfiumRPCServer) FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox, resp *responses.FPDF_GetPageBoundingBox) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageBoundingBox", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetPageBoundingBox(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_GetPageCount(request *requests.FPDF_GetPageCount, resp *responses.FPDF_GetPageCount) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3362,6 +3984,24 @@ func (s *PdfiumRPCServer) FPDF_GetPageHeight(request *requests.FPDF_GetPageHeigh return nil } +func (s *PdfiumRPCServer) FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF, resp *responses.FPDF_GetPageHeightF) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageHeightF", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetPageHeightF(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_GetPageLabel(request *requests.FPDF_GetPageLabel, resp *responses.FPDF_GetPageLabel) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3398,6 +4038,24 @@ func (s *PdfiumRPCServer) FPDF_GetPageSizeByIndex(request *requests.FPDF_GetPage return nil } +func (s *PdfiumRPCServer) FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF, resp *responses.FPDF_GetPageSizeByIndexF) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageSizeByIndexF", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetPageSizeByIndexF(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth, resp *responses.FPDF_GetPageWidth) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3416,6 +4074,24 @@ func (s *PdfiumRPCServer) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth, return nil } +func (s *PdfiumRPCServer) FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF, resp *responses.FPDF_GetPageWidthF) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageWidthF", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetPageWidthF(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_GetSecurityHandlerRevision(request *requests.FPDF_GetSecurityHandlerRevision, resp *responses.FPDF_GetSecurityHandlerRevision) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3470,6 +4146,78 @@ func (s *PdfiumRPCServer) FPDF_GetSignatureObject(request *requests.FPDF_GetSign return nil } +func (s *PdfiumRPCServer) FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds, resp *responses.FPDF_GetTrailerEnds) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetTrailerEnds", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetTrailerEnds(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent, resp *responses.FPDF_GetXFAPacketContent) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetXFAPacketContent", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetXFAPacketContent(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount, resp *responses.FPDF_GetXFAPacketCount) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetXFAPacketCount", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetXFAPacketCount(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName, resp *responses.FPDF_GetXFAPacketName) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetXFAPacketName", panicError) + } + }() + + implResp, err := s.Impl.FPDF_GetXFAPacketName(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_ImportNPagesToOne(request *requests.FPDF_ImportNPagesToOne, resp *responses.FPDF_ImportNPagesToOne) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3650,6 +4398,60 @@ func (s *PdfiumRPCServer) FPDF_NewXObjectFromPage(request *requests.FPDF_NewXObj return nil } +func (s *PdfiumRPCServer) FPDF_PageToDevice(request *requests.FPDF_PageToDevice, resp *responses.FPDF_PageToDevice) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_PageToDevice", panicError) + } + }() + + implResp, err := s.Impl.FPDF_PageToDevice(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap, resp *responses.FPDF_RenderPageBitmap) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_RenderPageBitmap", panicError) + } + }() + + implResp, err := s.Impl.FPDF_RenderPageBitmap(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix, resp *responses.FPDF_RenderPageBitmapWithMatrix) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_RenderPageBitmapWithMatrix", panicError) + } + }() + + implResp, err := s.Impl.FPDF_RenderPageBitmapWithMatrix(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FPDF_SaveAsCopy(request *requests.FPDF_SaveAsCopy, resp *responses.FPDF_SaveAsCopy) (err error) { defer func() { if panicError := recover(); panicError != nil { @@ -3704,6 +4506,132 @@ func (s *PdfiumRPCServer) FPDF_SetSandBoxPolicy(request *requests.FPDF_SetSandBo return nil } +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex, resp *responses.FPDF_VIEWERREF_GetDuplex) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetDuplex", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetDuplex(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName, resp *responses.FPDF_VIEWERREF_GetName) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetName", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetName(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies, resp *responses.FPDF_VIEWERREF_GetNumCopies) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetNumCopies", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetNumCopies(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange, resp *responses.FPDF_VIEWERREF_GetPrintPageRange) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintPageRange", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetPrintPageRange(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount, resp *responses.FPDF_VIEWERREF_GetPrintPageRangeCount) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintPageRangeCount", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetPrintPageRangeCount(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement, resp *responses.FPDF_VIEWERREF_GetPrintPageRangeElement) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintPageRangeElement", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetPrintPageRangeElement(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + +func (s *PdfiumRPCServer) FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling, resp *responses.FPDF_VIEWERREF_GetPrintScaling) (err error) { + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintScaling", panicError) + } + }() + + implResp, err := s.Impl.FPDF_VIEWERREF_GetPrintScaling(request) + if err != nil { + return err + } + + // Overwrite the target address of resp to the target address of implResp. + *resp = *implResp + + return nil +} + func (s *PdfiumRPCServer) FSDK_SetLocaltimeFunction(request *requests.FSDK_SetLocaltimeFunction, resp *responses.FSDK_SetLocaltimeFunction) (err error) { defer func() { if panicError := recover(); panicError != nil { diff --git a/internal/implementation/fpdfview.go b/internal/implementation/fpdfview.go index da21a1c6..fcfc1de7 100644 --- a/internal/implementation/fpdfview.go +++ b/internal/implementation/fpdfview.go @@ -2,15 +2,20 @@ package implementation // #cgo pkg-config: pdfium // #include "fpdfview.h" +// #include import "C" import ( "errors" - "github.com/google/uuid" + "unsafe" + "github.com/klippa-app/go-pdfium/enums" pdfium_errors "github.com/klippa-app/go-pdfium/errors" "github.com/klippa-app/go-pdfium/references" "github.com/klippa-app/go-pdfium/requests" "github.com/klippa-app/go-pdfium/responses" + "github.com/klippa-app/go-pdfium/structs" + + "github.com/google/uuid" ) // FPDF_LoadDocument opens and load a PDF document from a file path. @@ -357,3 +362,729 @@ func (p *PdfiumImplementation) FPDF_GetPageSizeByIndex(request *requests.FPDF_Ge Height: float64(height), }, nil } + +// FPDF_DocumentHasValidCrossReferenceTable returns whether the document's cross reference table is valid or not. +func (p *PdfiumImplementation) FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable) (*responses.FPDF_DocumentHasValidCrossReferenceTable, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + isValid := C.FPDF_DocumentHasValidCrossReferenceTable(documentHandle.handle) + return &responses.FPDF_DocumentHasValidCrossReferenceTable{ + DocumentHasValidCrossReferenceTable: int(isValid) == 1, + }, nil +} + +// FPDF_GetTrailerEnds returns the byte offsets of trailer ends. +// Experimental API. +func (p *PdfiumImplementation) FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds) (*responses.FPDF_GetTrailerEnds, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + trailerSize := C.FPDF_GetTrailerEnds(documentHandle.handle, nil, 0) + if int(trailerSize) == 0 { + return nil, errors.New("could not read trailer ends") + } + + cTrailerEnds := make([]C.uint, int(trailerSize)) + readTrailers := C.FPDF_GetTrailerEnds(documentHandle.handle, (*C.uint)(unsafe.Pointer(&cTrailerEnds[0])), trailerSize) + if int(readTrailers) == 0 { + return nil, errors.New("could not read trailer ends") + } + + trailerEnds := make([]int, trailerSize) + for i := range cTrailerEnds { + trailerEnds[i] = int(cTrailerEnds[i]) + } + + return &responses.FPDF_GetTrailerEnds{ + TrailerEnds: trailerEnds, + }, nil +} + +// FPDF_GetPageWidthF returns the page width in float32. +func (p *PdfiumImplementation) FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF) (*responses.FPDF_GetPageWidthF, error) { + p.Lock() + defer p.Unlock() + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + pageWidth := C.FPDF_GetPageWidthF(pageHandle.handle) + return &responses.FPDF_GetPageWidthF{ + PageWidth: float32(pageWidth), + }, nil +} + +// FPDF_GetPageHeightF returns the page height in float32. +func (p *PdfiumImplementation) FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF) (*responses.FPDF_GetPageHeightF, error) { + p.Lock() + defer p.Unlock() + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + pageHeight := C.FPDF_GetPageHeightF(pageHandle.handle) + return &responses.FPDF_GetPageHeightF{ + PageHeight: float32(pageHeight), + }, nil +} + +// FPDF_GetPageBoundingBox returns the bounding box of the page. This is the intersection between +// its media box and its crop box. +func (p *PdfiumImplementation) FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox) (*responses.FPDF_GetPageBoundingBox, error) { + p.Lock() + defer p.Unlock() + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + rect := C.FS_RECTF{} + success := C.FPDF_GetPageBoundingBox(pageHandle.handle, &rect) + if int(success) == 0 { + return nil, errors.New("could not get page bounding box") + } + + return &responses.FPDF_GetPageBoundingBox{ + Rect: structs.FPDF_FS_RECTF{ + Left: float32(rect.left), + Top: float32(rect.top), + Right: float32(rect.right), + Bottom: float32(rect.bottom), + }, + }, nil +} + +// FPDF_GetPageSizeByIndexF returns the size of the page at the given index. +// Prefer FPDF_GetPageSizeByIndexF(). This will be deprecated in the future. +func (p *PdfiumImplementation) FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF) (*responses.FPDF_GetPageSizeByIndexF, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + size := C.FS_SIZEF{} + success := C.FPDF_GetPageSizeByIndexF(documentHandle.handle, C.int(request.Index), &size) + if int(success) == 0 { + return nil, errors.New("could not get page size by index") + } + + return &responses.FPDF_GetPageSizeByIndexF{ + Size: structs.FPDF_FS_SIZEF{ + Width: float32(size.width), + Height: float32(size.height), + }, + }, nil +} + +// FPDF_RenderPageBitmap renders contents of a page to a device independent bitmap. +func (p *PdfiumImplementation) FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap) (*responses.FPDF_RenderPageBitmap, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + C.FPDF_RenderPageBitmap(bitmapHandle.handle, pageHandle.handle, C.int(request.StartX), C.int(request.StartY), C.int(request.SizeX), C.int(request.SizeY), C.int(request.Rotate), C.int(request.Flags)) + + return &responses.FPDF_RenderPageBitmap{}, nil +} + +// FPDF_RenderPageBitmapWithMatrix renders contents of a page to a device independent bitmap. +func (p *PdfiumImplementation) FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix) (*responses.FPDF_RenderPageBitmapWithMatrix, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + matrix := C.FS_MATRIX{ + a: C.float(request.Matrix.A), + b: C.float(request.Matrix.B), + c: C.float(request.Matrix.C), + d: C.float(request.Matrix.D), + e: C.float(request.Matrix.E), + f: C.float(request.Matrix.F), + } + + clipping := C.FS_RECTF{ + left: C.float(request.Clipping.Left), + top: C.float(request.Clipping.Top), + right: C.float(request.Clipping.Right), + bottom: C.float(request.Clipping.Bottom), + } + + C.FPDF_RenderPageBitmapWithMatrix(bitmapHandle.handle, pageHandle.handle, &matrix, &clipping, C.int(request.Flags)) + + return nil, nil +} + +// FPDF_DeviceToPage converts the screen coordinates of a point to page coordinates. +// The page coordinate system has its origin at the left-bottom corner +// of the page, with the X-axis on the bottom going to the right, and +// the Y-axis on the left side going up. +// +// NOTE: this coordinate system can be altered when you zoom, scroll, +// or rotate a page, however, a point on the page should always have +// the same coordinate values in the page coordinate system. +// +// The device coordinate system is device dependent. For screen device, +// its origin is at the left-top corner of the window. However this +// origin can be altered by the Windows coordinate transformation +// utilities. +// +// You must make sure the start_x, start_y, size_x, size_y +// and rotate parameters have exactly same values as you used in +// the FPDF_RenderPage() function call. +func (p *PdfiumImplementation) FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage) (*responses.FPDF_DeviceToPage, error) { + p.Lock() + defer p.Unlock() + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + pageX := C.double(0) + pageY := C.double(0) + + success := C.FPDF_DeviceToPage(pageHandle.handle, C.int(request.StartX), C.int(request.StartY), C.int(request.SizeX), C.int(request.SizeY), C.int(request.Rotate), C.int(request.DeviceX), C.int(request.DeviceY), &pageX, &pageY) + if int(success) == 0 { + return nil, errors.New("could not calculate from device to page") + } + + return &responses.FPDF_DeviceToPage{ + PageX: float64(pageX), + PageY: float64(pageY), + }, nil +} + +// FPDF_PageToDevice converts the page coordinates of a point to screen coordinates. +// See comments for FPDF_DeviceToPage(). +func (p *PdfiumImplementation) FPDF_PageToDevice(request *requests.FPDF_PageToDevice) (*responses.FPDF_PageToDevice, error) { + p.Lock() + defer p.Unlock() + + pageHandle, err := p.loadPage(request.Page) + if err != nil { + return nil, err + } + + deviceX := C.int(0) + deviceY := C.int(0) + + success := C.FPDF_PageToDevice(pageHandle.handle, C.int(request.StartX), C.int(request.StartY), C.int(request.SizeX), C.int(request.SizeY), C.int(request.Rotate), C.double(request.PageX), C.double(request.PageY), &deviceX, &deviceY) + if int(success) == 0 { + return nil, errors.New("could not calculate from page to device") + } + + return &responses.FPDF_PageToDevice{ + DeviceX: int(deviceX), + DeviceY: int(deviceY), + }, nil +} + +// FPDFBitmap_Create Create a device independent bitmap (FXDIB). +func (p *PdfiumImplementation) FPDFBitmap_Create(request *requests.FPDFBitmap_Create) (*responses.FPDFBitmap_Create, error) { + p.Lock() + defer p.Unlock() + + bitmap := C.FPDFBitmap_Create(C.int(request.Width), C.int(request.Height), C.int(request.Alpha)) + bitmapHandle := p.registerBitmap(bitmap) + + return &responses.FPDFBitmap_Create{ + Bitmap: bitmapHandle.nativeRef, + }, nil +} + +// FPDFBitmap_CreateEx Create a device independent bitmap (FXDIB) with an +// external buffer. +// Similar to FPDFBitmap_Create function, but allows for more formats +// and an external buffer is supported. The bitmap created by this +// function can be used in any place that a FPDF_BITMAP handle is +// required. +// +// If an external buffer is used, then the application should destroy +// the buffer by itself. FPDFBitmap_Destroy function will not destroy +// the buffer. +// +// Not supported on multi-threaded usage. +func (p *PdfiumImplementation) FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx) (*responses.FPDFBitmap_CreateEx, error) { + p.Lock() + defer p.Unlock() + + bitmap := C.FPDFBitmap_CreateEx(C.int(request.Width), C.int(request.Height), C.int(request.Format), unsafe.Pointer(&request.Buffer[0]), C.int(request.Stride)) + bitmapHandle := p.registerBitmap(bitmap) + + return &responses.FPDFBitmap_CreateEx{ + Bitmap: bitmapHandle.nativeRef, + }, nil +} + +// FPDFBitmap_GetFormat returns the format of the bitmap. +// Only formats supported by FPDFBitmap_CreateEx are supported by this function. +func (p *PdfiumImplementation) FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat) (*responses.FPDFBitmap_GetFormat, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + format := C.FPDFBitmap_GetFormat(bitmapHandle.handle) + + return &responses.FPDFBitmap_GetFormat{ + Format: enums.FPDF_BITMAP_FORMAT(format), + }, nil +} + +// FPDFBitmap_FillRect fills a rectangle in a bitmap. +// This function sets the color and (optionally) alpha value in the +// specified region of the bitmap. +// +// NOTE: If the alpha channel is used, this function does NOT +// composite the background with the source color, instead the +// background will be replaced by the source color and the alpha. +// +// If the alpha channel is not used, the alpha parameter is ignored. +func (p *PdfiumImplementation) FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect) (*responses.FPDFBitmap_FillRect, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + C.FPDFBitmap_FillRect(bitmapHandle.handle, C.int(request.Left), C.int(request.Top), C.int(request.Width), C.int(request.Height), C.ulong(request.Color)) + + return &responses.FPDFBitmap_FillRect{}, nil +} + +// FPDFBitmap_GetBuffer returns the data buffer of a bitmap. +// The stride may be more than width * number of bytes per pixel +// +// Applications can use this function to get the bitmap buffer pointer, +// then manipulate any color and/or alpha values for any pixels in the +// bitmap. +// +// The data is in BGRA format. Where the A maybe unused if alpha was +// not specified. +func (p *PdfiumImplementation) FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer) (*responses.FPDFBitmap_GetBuffer, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + // We need to calculate the buffer size, this is stride (bytes per bitmap line) * height. + stride := C.FPDFBitmap_GetStride(bitmapHandle.handle) + height := C.FPDFBitmap_GetHeight(bitmapHandle.handle) + size := int(stride * height) + + // The pointer to the first byte of the bitmap buffer. + buffer := C.FPDFBitmap_GetBuffer(bitmapHandle.handle) + + // We create a Go slice backed by a C array (without copying the original data), + // and acquire its length at runtime and use a type conversion to a pointer to a very big array and then slice it to the length that we want. + // Refer https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices + data := (*[1<<50 - 1]byte)(unsafe.Pointer(buffer))[:size:size] // For 64-bit machine, the max number it can go is 50 as per https://github.com/golang/go/issues/13656#issuecomment-291957684 + + return &responses.FPDFBitmap_GetBuffer{ + Buffer: data, + }, nil +} + +// FPDFBitmap_GetWidth returns the width of a bitmap. +func (p *PdfiumImplementation) FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth) (*responses.FPDFBitmap_GetWidth, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + width := C.FPDFBitmap_GetHeight(bitmapHandle.handle) + return &responses.FPDFBitmap_GetWidth{ + Width: int(width), + }, nil +} + +// FPDFBitmap_GetHeight returns the height of a bitmap. +func (p *PdfiumImplementation) FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight) (*responses.FPDFBitmap_GetHeight, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + height := C.FPDFBitmap_GetHeight(bitmapHandle.handle) + return &responses.FPDFBitmap_GetHeight{ + Height: int(height), + }, nil +} + +// FPDFBitmap_GetStride returns the number of bytes for each line in the bitmap buffer. +func (p *PdfiumImplementation) FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride) (*responses.FPDFBitmap_GetStride, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + stride := C.FPDFBitmap_GetStride(bitmapHandle.handle) + return &responses.FPDFBitmap_GetStride{ + Stride: int(stride), + }, nil +} + +// FPDFBitmap_Destroy destroys a bitmap and release all related buffers. +// This function will not destroy any external buffers provided when +// the bitmap was created. +func (p *PdfiumImplementation) FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy) (*responses.FPDFBitmap_Destroy, error) { + p.Lock() + defer p.Unlock() + + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + if err != nil { + return nil, err + } + + C.FPDFBitmap_Destroy(bitmapHandle.handle) + + delete(p.bitmapRefs, bitmapHandle.nativeRef) + + return nil, nil +} + +// FPDF_VIEWERREF_GetPrintScaling returns whether the PDF document prefers to be scaled or not. +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling) (*responses.FPDF_VIEWERREF_GetPrintScaling, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + printScaling := C.FPDF_VIEWERREF_GetPrintScaling(documentHandle.handle) + return &responses.FPDF_VIEWERREF_GetPrintScaling{ + PreferPrintScaling: int(printScaling) == 1, + }, nil +} + +// FPDF_VIEWERREF_GetNumCopies returns the number of copies to be printed. +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies) (*responses.FPDF_VIEWERREF_GetNumCopies, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + numCopies := C.FPDF_VIEWERREF_GetNumCopies(documentHandle.handle) + return &responses.FPDF_VIEWERREF_GetNumCopies{ + NumCopies: int(numCopies), + }, nil +} + +// FPDF_VIEWERREF_GetPrintPageRange returns the page numbers to initialize print dialog box when file is printed. +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange) (*responses.FPDF_VIEWERREF_GetPrintPageRange, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + pageRange := C.FPDF_VIEWERREF_GetPrintPageRange(documentHandle.handle) + pageRangeHandle := p.registerPageRange(pageRange, documentHandle) + + return &responses.FPDF_VIEWERREF_GetPrintPageRange{ + PageRange: pageRangeHandle.nativeRef, + }, nil +} + +// FPDF_VIEWERREF_GetPrintPageRangeCount returns the number of elements in a FPDF_PAGERANGE. +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (*responses.FPDF_VIEWERREF_GetPrintPageRangeCount, error) { + p.Lock() + defer p.Unlock() + + pageRangeHandle, err := p.getPageRangeHandle(request.PageRange) + if err != nil { + return nil, err + } + + count := C.FPDF_VIEWERREF_GetPrintPageRangeCount(pageRangeHandle.handle) + return &responses.FPDF_VIEWERREF_GetPrintPageRangeCount{ + Count: uint64(count), + }, nil +} + +// FPDF_VIEWERREF_GetPrintPageRangeElement returns an element from a FPDF_PAGERANGE. +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (*responses.FPDF_VIEWERREF_GetPrintPageRangeElement, error) { + p.Lock() + defer p.Unlock() + + pageRangeHandle, err := p.getPageRangeHandle(request.PageRange) + if err != nil { + return nil, err + } + + value := C.FPDF_VIEWERREF_GetPrintPageRangeElement(pageRangeHandle.handle, C.size_t(request.Index)) + return &responses.FPDF_VIEWERREF_GetPrintPageRangeElement{ + Value: int(value), + }, nil +} + +// FPDF_VIEWERREF_GetDuplex returns the paper handling option to be used when printing from the print dialog. +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex) (*responses.FPDF_VIEWERREF_GetDuplex, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + duplexType := C.FPDF_VIEWERREF_GetDuplex(documentHandle.handle) + return &responses.FPDF_VIEWERREF_GetDuplex{ + DuplexType: enums.FPDF_DUPLEXTYPE(duplexType), + }, nil +} + +// FPDF_VIEWERREF_GetName returns the contents for a viewer ref, with a given key. The value must be of type "name". +func (p *PdfiumImplementation) FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName) (*responses.FPDF_VIEWERREF_GetName, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + cstr := C.CString(request.Key) + defer C.free(unsafe.Pointer(cstr)) + + // First get the metadata length. + nameSize := C.FPDF_VIEWERREF_GetName(documentHandle.handle, cstr, nil, 0) + if nameSize == 0 { + return nil, errors.New("Could not get name") + } + + charData := make([]byte, uint64(nameSize)) + C.FPDF_VIEWERREF_GetName(documentHandle.handle, cstr, (*C.char)(unsafe.Pointer(&charData[0])), C.ulong(len(charData))) + + transformedText, err := p.transformUTF16LEToUTF8(charData) + if err != nil { + return nil, err + } + + return &responses.FPDF_VIEWERREF_GetName{ + Name: transformedText, + }, nil +} + +// FPDF_CountNamedDests returns the count of named destinations in the PDF document. +func (p *PdfiumImplementation) FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests) (*responses.FPDF_CountNamedDests, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + count := C.FPDF_CountNamedDests(documentHandle.handle) + return &responses.FPDF_CountNamedDests{ + Count: uint64(count), + }, nil +} + +// FPDF_GetNamedDestByName returns the destination handle for the given name. +func (p *PdfiumImplementation) FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName) (*responses.FPDF_GetNamedDestByName, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + cstr := C.CString(request.Name) + defer C.free(unsafe.Pointer(cstr)) + + dest := C.FPDF_GetNamedDestByName(documentHandle.handle, cstr) + if dest == nil { + return nil, errors.New("could not get named dest by name") + } + + destHandle := p.registerDest(dest, documentHandle) + return &responses.FPDF_GetNamedDestByName{ + Dest: destHandle.nativeRef, + }, nil +} + +// FPDF_GetNamedDest returns the named destination by index. +func (p *PdfiumImplementation) FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest) (*responses.FPDF_GetNamedDest, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + bufLen := C.long(0) + + // First get the name length. + C.FPDF_GetNamedDest(documentHandle.handle, C.int(request.Index), nil, &bufLen) + if int64(bufLen) <= 0 { + return nil, errors.New("could not get name of named dest") + } + + charData := make([]byte, int64(bufLen)) + dest := C.FPDF_GetNamedDest(documentHandle.handle, C.int(request.Index), unsafe.Pointer(&charData[0]), &bufLen) + + transformedText, err := p.transformUTF16LEToUTF8(charData) + if err != nil { + return nil, err + } + + destHandle := p.registerDest(dest, documentHandle) + return &responses.FPDF_GetNamedDest{ + Dest: destHandle.nativeRef, + Name: transformedText, + }, nil +} + +// FPDF_GetXFAPacketCount returns the number of valid packets in the XFA entry. +// Experimental API. +func (p *PdfiumImplementation) FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount) (*responses.FPDF_GetXFAPacketCount, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + count := C.FPDF_GetXFAPacketCount(documentHandle.handle) + if int(count) == -1 { + return nil, errors.New("error getting XFA packet count") + } + + return &responses.FPDF_GetXFAPacketCount{ + Count: int(count), + }, nil +} + +// FPDF_GetXFAPacketName returns the name of a packet in the XFA array. +// Experimental API. +func (p *PdfiumImplementation) FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName) (*responses.FPDF_GetXFAPacketName, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + // First get the name length. + nameSize := C.FPDF_GetXFAPacketName(documentHandle.handle, C.int(request.Index), nil, 0) + if uint64(nameSize) == 0 { + return nil, errors.New("could not get name of the XFA packet") + } + + charData := make([]byte, uint64(nameSize)) + result := C.FPDF_GetXFAPacketName(documentHandle.handle, C.int(request.Index), unsafe.Pointer(&charData[0]), C.ulong(len(charData))) + if uint64(result) == 0 { + return nil, errors.New("could not get name of the XFA packet") + } + + transformedText, err := p.transformUTF16LEToUTF8(charData) + if err != nil { + return nil, err + } + + return &responses.FPDF_GetXFAPacketName{ + Name: transformedText, + }, nil +} + +// FPDF_GetXFAPacketContent returns the content of a packet in the XFA array. +func (p *PdfiumImplementation) FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) { + p.Lock() + defer p.Unlock() + + documentHandle, err := p.getDocumentHandle(request.Document) + if err != nil { + return nil, err + } + + outBufLen := C.ulong(0) + + // First get the name length. + success := C.FPDF_GetXFAPacketContent(documentHandle.handle, C.int(request.Index), nil, 0, &outBufLen) + if int(success) == 0 || uint64(outBufLen) == 0 { + return nil, errors.New("could not get content of the XFA packet") + } + + contentData := make([]byte, uint64(outBufLen)) + success = C.FPDF_GetXFAPacketContent(documentHandle.handle, C.int(request.Index), unsafe.Pointer(&contentData[0]), C.ulong(len(contentData)), &outBufLen) + if int(success) == 0 { + return nil, errors.New("could not get content of the XFA packet") + } + + // Callers must check both the return value and the input |buflen| is no + // less than the returned |out_buflen| before using the data in |buffer|. + if uint64(len(contentData)) < uint64(outBufLen) { + return nil, errors.New("could not get content of the XFA packet") + } + + return &responses.FPDF_GetXFAPacketContent{ + Content: contentData, + }, nil +} diff --git a/internal/implementation/implementation.go b/internal/implementation/implementation.go index 60f96601..4d885ab4 100644 --- a/internal/implementation/implementation.go +++ b/internal/implementation/implementation.go @@ -568,3 +568,27 @@ func (p *PdfiumImplementation) getPageLinkHandle(pageLink references.FPDF_PAGELI return nil, errors.New("could not find pageLink handle, perhaps the pageLink was already closed or you tried to share pageLinks between instances") } + +func (p *PdfiumImplementation) getBitmapHandle(bitmap references.FPDF_BITMAP) (*BitmapHandle, error) { + if bitmap == "" { + return nil, errors.New("bitmap not given") + } + + if val, ok := p.bitmapRefs[bitmap]; ok { + return val, nil + } + + return nil, errors.New("could not find bitmap handle, perhaps the bitmap was already closed or you tried to share bitmaps between instances") +} + +func (p *PdfiumImplementation) getPageRangeHandle(pageRange references.FPDF_PAGERANGE) (*PageRangeHandle, error) { + if pageRange == "" { + return nil, errors.New("pageRange not given") + } + + if val, ok := p.pageRangeRefs[pageRange]; ok { + return val, nil + } + + return nil, errors.New("could not find pageRange handle, perhaps the pageRange was already closed or you tried to share pageRanges between instances") +} diff --git a/internal/implementation/pagerange.go b/internal/implementation/pagerange.go new file mode 100644 index 00000000..068e768b --- /dev/null +++ b/internal/implementation/pagerange.go @@ -0,0 +1,23 @@ +package implementation + +// #cgo pkg-config: pdfium +// #include "fpdfview.h" +import "C" +import ( + "github.com/google/uuid" + "github.com/klippa-app/go-pdfium/references" +) + +func (p *PdfiumImplementation) registerPageRange(pageRange C.FPDF_PAGERANGE, documentHandle *DocumentHandle) *PageRangeHandle { + ref := uuid.New() + handle := &PageRangeHandle{ + handle: pageRange, + nativeRef: references.FPDF_PAGERANGE(ref.String()), + documentRef: documentHandle.nativeRef, + } + + p.pageRangeRefs[handle.nativeRef] = handle + documentHandle.pageRangeRefs[handle.nativeRef] = handle + + return handle +} diff --git a/multi_threaded/generated.go b/multi_threaded/generated.go index a6489aa9..5b4b8ad1 100644 --- a/multi_threaded/generated.go +++ b/multi_threaded/generated.go @@ -99,6 +99,78 @@ func (i *pdfiumInstance) FPDFAttachment_SetStringValue(request *requests.FPDFAtt return i.worker.plugin.FPDFAttachment_SetStringValue(request) } +func (i *pdfiumInstance) FPDFBitmap_Create(request *requests.FPDFBitmap_Create) (*responses.FPDFBitmap_Create, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_Create(request) +} + +func (i *pdfiumInstance) FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx) (*responses.FPDFBitmap_CreateEx, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_CreateEx(request) +} + +func (i *pdfiumInstance) FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy) (*responses.FPDFBitmap_Destroy, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_Destroy(request) +} + +func (i *pdfiumInstance) FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect) (*responses.FPDFBitmap_FillRect, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_FillRect(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer) (*responses.FPDFBitmap_GetBuffer, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_GetBuffer(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat) (*responses.FPDFBitmap_GetFormat, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_GetFormat(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight) (*responses.FPDFBitmap_GetHeight, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_GetHeight(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride) (*responses.FPDFBitmap_GetStride, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_GetStride(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth) (*responses.FPDFBitmap_GetWidth, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDFBitmap_GetWidth(request) +} + func (i *pdfiumInstance) FPDFBookmark_Find(request *requests.FPDFBookmark_Find) (*responses.FPDFBookmark_Find, error) { if i.closed { return nil, errors.New("instance is closed") @@ -747,6 +819,14 @@ func (i *pdfiumInstance) FPDF_CopyViewerPreferences(request *requests.FPDF_CopyV return i.worker.plugin.FPDF_CopyViewerPreferences(request) } +func (i *pdfiumInstance) FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests) (*responses.FPDF_CountNamedDests, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_CountNamedDests(request) +} + func (i *pdfiumInstance) FPDF_CreateNewDocument(request *requests.FPDF_CreateNewDocument) (*responses.FPDF_CreateNewDocument, error) { if i.closed { return nil, errors.New("instance is closed") @@ -755,6 +835,22 @@ func (i *pdfiumInstance) FPDF_CreateNewDocument(request *requests.FPDF_CreateNew return i.worker.plugin.FPDF_CreateNewDocument(request) } +func (i *pdfiumInstance) FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage) (*responses.FPDF_DeviceToPage, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_DeviceToPage(request) +} + +func (i *pdfiumInstance) FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable) (*responses.FPDF_DocumentHasValidCrossReferenceTable, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_DocumentHasValidCrossReferenceTable(request) +} + func (i *pdfiumInstance) FPDF_GetDocPermissions(request *requests.FPDF_GetDocPermissions) (*responses.FPDF_GetDocPermissions, error) { if i.closed { return nil, errors.New("instance is closed") @@ -795,6 +891,22 @@ func (i *pdfiumInstance) FPDF_GetMetaText(request *requests.FPDF_GetMetaText) (* return i.worker.plugin.FPDF_GetMetaText(request) } +func (i *pdfiumInstance) FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest) (*responses.FPDF_GetNamedDest, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetNamedDest(request) +} + +func (i *pdfiumInstance) FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName) (*responses.FPDF_GetNamedDestByName, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetNamedDestByName(request) +} + func (i *pdfiumInstance) FPDF_GetPageAAction(request *requests.FPDF_GetPageAAction) (*responses.FPDF_GetPageAAction, error) { if i.closed { return nil, errors.New("instance is closed") @@ -803,6 +915,14 @@ func (i *pdfiumInstance) FPDF_GetPageAAction(request *requests.FPDF_GetPageAActi return i.worker.plugin.FPDF_GetPageAAction(request) } +func (i *pdfiumInstance) FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox) (*responses.FPDF_GetPageBoundingBox, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetPageBoundingBox(request) +} + func (i *pdfiumInstance) FPDF_GetPageCount(request *requests.FPDF_GetPageCount) (*responses.FPDF_GetPageCount, error) { if i.closed { return nil, errors.New("instance is closed") @@ -819,6 +939,14 @@ func (i *pdfiumInstance) FPDF_GetPageHeight(request *requests.FPDF_GetPageHeight return i.worker.plugin.FPDF_GetPageHeight(request) } +func (i *pdfiumInstance) FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF) (*responses.FPDF_GetPageHeightF, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetPageHeightF(request) +} + func (i *pdfiumInstance) FPDF_GetPageLabel(request *requests.FPDF_GetPageLabel) (*responses.FPDF_GetPageLabel, error) { if i.closed { return nil, errors.New("instance is closed") @@ -835,6 +963,14 @@ func (i *pdfiumInstance) FPDF_GetPageSizeByIndex(request *requests.FPDF_GetPageS return i.worker.plugin.FPDF_GetPageSizeByIndex(request) } +func (i *pdfiumInstance) FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF) (*responses.FPDF_GetPageSizeByIndexF, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetPageSizeByIndexF(request) +} + func (i *pdfiumInstance) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) (*responses.FPDF_GetPageWidth, error) { if i.closed { return nil, errors.New("instance is closed") @@ -843,6 +979,14 @@ func (i *pdfiumInstance) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) return i.worker.plugin.FPDF_GetPageWidth(request) } +func (i *pdfiumInstance) FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF) (*responses.FPDF_GetPageWidthF, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetPageWidthF(request) +} + func (i *pdfiumInstance) FPDF_GetSecurityHandlerRevision(request *requests.FPDF_GetSecurityHandlerRevision) (*responses.FPDF_GetSecurityHandlerRevision, error) { if i.closed { return nil, errors.New("instance is closed") @@ -867,6 +1011,38 @@ func (i *pdfiumInstance) FPDF_GetSignatureObject(request *requests.FPDF_GetSigna return i.worker.plugin.FPDF_GetSignatureObject(request) } +func (i *pdfiumInstance) FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds) (*responses.FPDF_GetTrailerEnds, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetTrailerEnds(request) +} + +func (i *pdfiumInstance) FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetXFAPacketContent(request) +} + +func (i *pdfiumInstance) FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount) (*responses.FPDF_GetXFAPacketCount, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetXFAPacketCount(request) +} + +func (i *pdfiumInstance) FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName) (*responses.FPDF_GetXFAPacketName, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_GetXFAPacketName(request) +} + func (i *pdfiumInstance) FPDF_ImportNPagesToOne(request *requests.FPDF_ImportNPagesToOne) (*responses.FPDF_ImportNPagesToOne, error) { if i.closed { return nil, errors.New("instance is closed") @@ -962,6 +1138,30 @@ func (i *pdfiumInstance) FPDF_NewXObjectFromPage(request *requests.FPDF_NewXObje return i.worker.plugin.FPDF_NewXObjectFromPage(request) } +func (i *pdfiumInstance) FPDF_PageToDevice(request *requests.FPDF_PageToDevice) (*responses.FPDF_PageToDevice, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_PageToDevice(request) +} + +func (i *pdfiumInstance) FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap) (*responses.FPDF_RenderPageBitmap, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_RenderPageBitmap(request) +} + +func (i *pdfiumInstance) FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix) (*responses.FPDF_RenderPageBitmapWithMatrix, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_RenderPageBitmapWithMatrix(request) +} + func (i *pdfiumInstance) FPDF_SaveAsCopy(request *requests.FPDF_SaveAsCopy) (*responses.FPDF_SaveAsCopy, error) { if i.closed { return nil, errors.New("instance is closed") @@ -986,6 +1186,62 @@ func (i *pdfiumInstance) FPDF_SetSandBoxPolicy(request *requests.FPDF_SetSandBox return i.worker.plugin.FPDF_SetSandBoxPolicy(request) } +func (i *pdfiumInstance) FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex) (*responses.FPDF_VIEWERREF_GetDuplex, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetDuplex(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName) (*responses.FPDF_VIEWERREF_GetName, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetName(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies) (*responses.FPDF_VIEWERREF_GetNumCopies, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetNumCopies(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange) (*responses.FPDF_VIEWERREF_GetPrintPageRange, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetPrintPageRange(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (*responses.FPDF_VIEWERREF_GetPrintPageRangeCount, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetPrintPageRangeCount(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (*responses.FPDF_VIEWERREF_GetPrintPageRangeElement, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetPrintPageRangeElement(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling) (*responses.FPDF_VIEWERREF_GetPrintScaling, error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + return i.worker.plugin.FPDF_VIEWERREF_GetPrintScaling(request) +} + func (i *pdfiumInstance) FSDK_SetLocaltimeFunction(request *requests.FSDK_SetLocaltimeFunction) (*responses.FSDK_SetLocaltimeFunction, error) { if i.closed { return nil, errors.New("instance is closed") diff --git a/pdfium.go b/pdfium.go index 5541f5b0..aa2b5cb1 100644 --- a/pdfium.go +++ b/pdfium.go @@ -183,149 +183,166 @@ type Pdfium interface { FPDF_GetPageCount(request *requests.FPDF_GetPageCount) (*responses.FPDF_GetPageCount, error) // FPDF_GetPageWidth returns the width of a page. + // Prefer FPDF_GetPageWidthF(). This will be deprecated in the future. FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) (*responses.FPDF_GetPageWidth, error) // FPDF_GetPageHeight returns the height of a page. + // Prefer FPDF_GetPageHeightF(). This will be deprecated in the future. FPDF_GetPageHeight(request *requests.FPDF_GetPageHeight) (*responses.FPDF_GetPageHeight, error) // FPDF_GetPageSizeByIndex returns the size of a page by the page index. FPDF_GetPageSizeByIndex(request *requests.FPDF_GetPageSizeByIndex) (*responses.FPDF_GetPageSizeByIndex, error) - // FPDF_InitLibrary - FPDF_InitLibrary(request *requests.FPDF_InitLibrary) (*responses.FPDF_InitLibrary, error) - - // FPDF_InitLibraryWithConfig - FPDF_InitLibraryWithConfig(request *requests.FPDF_InitLibraryWithConfig) (*responses.FPDF_InitLibraryWithConfig, error) - - // FPDF_DestroyLibrary - FPDF_DestroyLibrary(request *requests.FPDF_DestroyLibrary) (*responses.FPDF_DestroyLibrary, error) - - // FPDF_SetTypefaceAccessibleFunc - FPDF_SetTypefaceAccessibleFunc(request *requests.FPDF_SetTypefaceAccessibleFunc) (*responses.FPDF_SetTypefaceAccessibleFunc, error) - - // FPDF_SetPrintTextWithGDI - FPDF_SetPrintTextWithGDI(request *requests.FPDF_SetPrintTextWithGDI) (*responses.FPDF_SetPrintTextWithGDI, error) - - // FPDF_SetPrintMode - FPDF_SetPrintMode(request *requests.FPDF_SetPrintMode) (*responses.FPDF_SetPrintMode, error) - - // FPDF_DocumentHasValidCrossReferenceTable + // FPDF_DocumentHasValidCrossReferenceTable returns whether the document's cross reference table is valid or not. FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable) (*responses.FPDF_DocumentHasValidCrossReferenceTable, error) - // FPDF_GetTrailerEnds + // FPDF_GetTrailerEnds returns the byte offsets of trailer ends. + // Experimental API. FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds) (*responses.FPDF_GetTrailerEnds, error) - // FPDF_GetPageWidthF + // FPDF_GetPageWidthF returns the page width in float32. FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF) (*responses.FPDF_GetPageWidthF, error) - // FPDF_GetPageHeightF + // FPDF_GetPageHeightF returns the page height in float32. FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF) (*responses.FPDF_GetPageHeightF, error) - // FPDF_GetPageBoundingBox + // FPDF_GetPageBoundingBox returns the bounding box of the page. This is the intersection between + // its media box and its crop box. FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox) (*responses.FPDF_GetPageBoundingBox, error) - // FPDF_GetPageSizeByIndexF + // FPDF_GetPageSizeByIndexF returns the size of the page at the given index. + // Prefer FPDF_GetPageSizeByIndexF(). This will be deprecated in the future. FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF) (*responses.FPDF_GetPageSizeByIndexF, error) - // FPDF_RenderPage - FPDF_RenderPage(request *requests.FPDF_RenderPage) (*responses.FPDF_RenderPage, error) - - // FPDF_RenderPageBitmap + // FPDF_RenderPageBitmap renders contents of a page to a device independent bitmap. FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap) (*responses.FPDF_RenderPageBitmap, error) - // FPDF_RenderPageBitmapWithMatrix + // FPDF_RenderPageBitmapWithMatrix renders contents of a page to a device independent bitmap. FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix) (*responses.FPDF_RenderPageBitmapWithMatrix, error) - // FPDF_RenderPageSkp - FPDF_RenderPageSkp(request *requests.FPDF_RenderPageSkp) (*responses.FPDF_RenderPageSkp, error) - - // FPDF_DeviceToPage + // FPDF_DeviceToPage converts the screen coordinates of a point to page coordinates. + // The page coordinate system has its origin at the left-bottom corner + // of the page, with the X-axis on the bottom going to the right, and + // the Y-axis on the left side going up. + // + // NOTE: this coordinate system can be altered when you zoom, scroll, + // or rotate a page, however, a point on the page should always have + // the same coordinate values in the page coordinate system. + // + // The device coordinate system is device dependent. For screen device, + // its origin is at the left-top corner of the window. However this + // origin can be altered by the Windows coordinate transformation + // utilities. + // + // You must make sure the start_x, start_y, size_x, size_y + // and rotate parameters have exactly same values as you used in + // the FPDF_RenderPage() function call. FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage) (*responses.FPDF_DeviceToPage, error) - // FPDF_PageToDevice + // FPDF_PageToDevice converts the page coordinates of a point to screen coordinates. + // See comments for FPDF_DeviceToPage(). FPDF_PageToDevice(request *requests.FPDF_PageToDevice) (*responses.FPDF_PageToDevice, error) - // FPDFBitmap_Create + // FPDFBitmap_Create Create a device independent bitmap (FXDIB). FPDFBitmap_Create(request *requests.FPDFBitmap_Create) (*responses.FPDFBitmap_Create, error) - // FPDFBitmap_CreateEx + // FPDFBitmap_CreateEx Create a device independent bitmap (FXDIB) with an + // external buffer. + // Similar to FPDFBitmap_Create function, but allows for more formats + // and an external buffer is supported. The bitmap created by this + // function can be used in any place that a FPDF_BITMAP handle is + // required. + // + // If an external buffer is used, then the application should destroy + // the buffer by itself. FPDFBitmap_Destroy function will not destroy + // the buffer. + // + // Not supported on multi-threaded usage. FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx) (*responses.FPDFBitmap_CreateEx, error) - // FPDFBitmap_GetFormat + // FPDFBitmap_GetFormat returns the format of the bitmap. + // Only formats supported by FPDFBitmap_CreateEx are supported by this function. FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat) (*responses.FPDFBitmap_GetFormat, error) - // FPDFBitmap_FillRect + // FPDFBitmap_FillRect fills a rectangle in a bitmap. + // This function sets the color and (optionally) alpha value in the + // specified region of the bitmap. + // + // NOTE: If the alpha channel is used, this function does NOT + // composite the background with the source color, instead the + // background will be replaced by the source color and the alpha. + // + // If the alpha channel is not used, the alpha parameter is ignored. FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect) (*responses.FPDFBitmap_FillRect, error) - // FPDFBitmap_GetBuffer + // FPDFBitmap_GetBuffer returns the data buffer of a bitmap. + // The stride may be more than width * number of bytes per pixel + // + // Applications can use this function to get the bitmap buffer pointer, + // then manipulate any color and/or alpha values for any pixels in the + // bitmap. + // + // The data is in BGRA format. Where the A maybe unused if alpha was + // not specified. FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer) (*responses.FPDFBitmap_GetBuffer, error) - // FPDFBitmap_GetWidth + // FPDFBitmap_GetWidth returns the width of a bitmap. FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth) (*responses.FPDFBitmap_GetWidth, error) - // FPDFBitmap_GetHeight + // FPDFBitmap_GetHeight returns the height of a bitmap. FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight) (*responses.FPDFBitmap_GetHeight, error) - // FPDFBitmap_GetStride + // FPDFBitmap_GetStride returns the number of bytes for each line in the bitmap buffer. FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride) (*responses.FPDFBitmap_GetStride, error) - // FPDFBitmap_Destroy + // FPDFBitmap_Destroy destroys a bitmap and release all related buffers. + // This function will not destroy any external buffers provided when + // the bitmap was created. FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy) (*responses.FPDFBitmap_Destroy, error) - // FPDF_VIEWERREF_GetPrintScaling + // FPDF_VIEWERREF_GetPrintScaling returns whether the PDF document prefers to be scaled or not. FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling) (*responses.FPDF_VIEWERREF_GetPrintScaling, error) - // FPDF_VIEWERREF_GetNumCopies + // FPDF_VIEWERREF_GetNumCopies returns the number of copies to be printed. FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies) (*responses.FPDF_VIEWERREF_GetNumCopies, error) - // FPDF_VIEWERREF_GetPrintPageRange + // FPDF_VIEWERREF_GetPrintPageRange returns the page numbers to initialize print dialog box when file is printed. FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange) (*responses.FPDF_VIEWERREF_GetPrintPageRange, error) - // FPDF_VIEWERREF_GetPrintPageRangeCount + // FPDF_VIEWERREF_GetPrintPageRangeCount returns the number of elements in a FPDF_PAGERANGE. + // Experimental API. FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (*responses.FPDF_VIEWERREF_GetPrintPageRangeCount, error) - // FPDF_VIEWERREF_GetPrintPageRangeElement + // FPDF_VIEWERREF_GetPrintPageRangeElement returns an element from a FPDF_PAGERANGE. + // Experimental API. FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (*responses.FPDF_VIEWERREF_GetPrintPageRangeElement, error) - // FPDF_VIEWERREF_GetDuplex + // FPDF_VIEWERREF_GetDuplex returns the paper handling option to be used when printing from the print dialog. FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex) (*responses.FPDF_VIEWERREF_GetDuplex, error) - // FPDF_VIEWERREF_GetName + // FPDF_VIEWERREF_GetName returns the contents for a viewer ref, with a given key. The value must be of type "name". FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName) (*responses.FPDF_VIEWERREF_GetName, error) - // FPDF_CountNamedDests + // FPDF_CountNamedDests returns the count of named destinations in the PDF document. FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests) (*responses.FPDF_CountNamedDests, error) - // FPDF_GetNamedDestByName + // FPDF_GetNamedDestByName returns the destination handle for the given name. FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName) (*responses.FPDF_GetNamedDestByName, error) - // FPDF_GetNamedDest + // FPDF_GetNamedDest returns the named destination by index. FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest) (*responses.FPDF_GetNamedDest, error) - // FPDF_GetXFAPacketCount + // FPDF_GetXFAPacketCount returns the number of valid packets in the XFA entry. + // Experimental API. FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount) (*responses.FPDF_GetXFAPacketCount, error) - // FPDF_GetXFAPacketName + // FPDF_GetXFAPacketName returns the name of a packet in the XFA array. + // Experimental API. FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName) (*responses.FPDF_GetXFAPacketName, error) - // FPDF_GetXFAPacketContent + // FPDF_GetXFAPacketContent returns the content of a packet in the XFA array. FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) - // FPDF_GetRecommendedV8Flags - FPDF_GetRecommendedV8Flags(request *requests.FPDF_GetRecommendedV8Flags) (*responses.FPDF_GetRecommendedV8Flags, error) - - // FPDF_GetArrayBufferAllocatorSharedInstance - FPDF_GetArrayBufferAllocatorSharedInstance(request *requests.FPDF_GetArrayBufferAllocatorSharedInstance) (*responses.FPDF_GetArrayBufferAllocatorSharedInstance, error) - - // FPDF_BStr_Init - FPDF_BStr_Init(request *requests.FPDF_BStr_Init) (*responses.FPDF_BStr_Init, error) - - // FPDF_BStr_Set - FPDF_BStr_Set(request *requests.FPDF_BStr_Set) (*responses.FPDF_BStr_Set, error) - - // FPDF_BStr_Clear - FPDF_BStr_Clear(request *requests.FPDF_BStr_Clear) (*responses.FPDF_BStr_Clear, error) - // End fpdfview.h // Start fpdf_edit.h diff --git a/requests/fpdfview.go b/requests/fpdfview.go index 78aa78d9..b37f3c4a 100644 --- a/requests/fpdfview.go +++ b/requests/fpdfview.go @@ -1,7 +1,9 @@ package requests import ( + "github.com/klippa-app/go-pdfium/enums" "github.com/klippa-app/go-pdfium/references" + "github.com/klippa-app/go-pdfium/structs" "io" ) @@ -80,3 +82,174 @@ type FPDF_GetPageSizeByIndex struct { Document references.FPDF_DOCUMENT Index int } + +type FPDF_DocumentHasValidCrossReferenceTable struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_GetTrailerEnds struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_GetPageWidthF struct { + Page Page +} + +type FPDF_GetPageHeightF struct { + Page Page +} + +type FPDF_GetPageBoundingBox struct { + Page Page +} + +type FPDF_GetPageSizeByIndexF struct { + Document references.FPDF_DOCUMENT + Index int +} + +type FPDF_RenderPageBitmap struct { + Bitmap references.FPDF_BITMAP + Page Page + StartX int // Left pixel position of the display area in bitmap coordinates. + StartY int // Top pixel position of the display area in bitmap coordinates. + SizeX int // Horizontal size (in pixels) for displaying the page. + SizeY int // Vertical size (in pixels) for displaying the page. + Rotate enums.FPDF_PAGE_ROTATION // Page orientation. + Flags enums.FPDF_RENDER_FLAG // 0 for normal display, or combination of enums.FPDF_RENDER_FLAG. With the enums.FPDF_RENDER_FLAG_ANNOT flag, it renders all annotations that do not require user-interaction, which are all annotations except widget and popup annotations. +} + +type FPDF_RenderPageBitmapWithMatrix struct { + Bitmap references.FPDF_BITMAP + Page Page + Matrix structs.FPDF_FS_MATRIX // The transform matrix, which must be invertible. See PDF Reference 1.7, 4.2.2 Common Transformations. + Clipping structs.FPDF_FS_RECTF // The rect to clip to in device coords. + Flags enums.FPDF_RENDER_FLAG // 0 for normal display, or combination of enums.FPDF_RENDER_FLAG. With the enums.FPDF_RENDER_FLAG_ANNOT flag, it renders all annotations that do not require user-interaction, which are all annotations except widget and popup annotations. +} + +type FPDF_DeviceToPage struct { + Page Page + StartX int // Left pixel position of the display area in device coordinates. + StartY int // Top pixel position of the display area in device coordinates. + SizeX int // Horizontal size (in pixels) for displaying the page. + SizeY int // Vertical size (in pixels) for displaying the page. + Rotate enums.FPDF_PAGE_ROTATION // Page orientation. + DeviceX int // X value in device coordinates to be converted. + DeviceY int // Y value in device coordinates to be converted. +} + +type FPDF_PageToDevice struct { + Page Page + StartX int // Left pixel position of the display area in device coordinates. + StartY int // Top pixel position of the display area in device coordinates. + SizeX int // Horizontal size (in pixels) for displaying the page. + SizeY int // Vertical size (in pixels) for displaying the page. + Rotate enums.FPDF_PAGE_ROTATION // Page orientation. + PageX float64 // X value in page coordinates to be converted. + PageY float64 // Y value in page coordinates to be converted. +} + +type FPDFBitmap_Create struct { + Width int // The number of pixels in width for the bitmap. Must be greater than 0. + Height int // The number of pixels in height for the bitmap. Must be greater than 0. + Alpha int // A flag indicating whether the alpha channel is used. Non-zero for using alpha, zero for not using. +} + +type FPDFBitmap_CreateEx struct { + Width int // The number of pixels in width for the bitmap. Must be greater than 0. + Height int // The number of pixels in height for the bitmap. Must be greater than 0. + Format enums.FPDF_BITMAP_FORMAT + Buffer []byte + Stride int +} + +type FPDFBitmap_GetFormat struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_FillRect struct { + Bitmap references.FPDF_BITMAP + Left int + Top int + Width int + Height int + Color uint64 +} + +type FPDFBitmap_GetBuffer struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_GetWidth struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_GetHeight struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_GetStride struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_Destroy struct { + Bitmap references.FPDF_BITMAP +} + +type FPDF_VIEWERREF_GetPrintScaling struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_VIEWERREF_GetNumCopies struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_VIEWERREF_GetPrintPageRange struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_VIEWERREF_GetPrintPageRangeCount struct { + PageRange references.FPDF_PAGERANGE +} + +type FPDF_VIEWERREF_GetPrintPageRangeElement struct { + PageRange references.FPDF_PAGERANGE + Index uint64 +} + +type FPDF_VIEWERREF_GetDuplex struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_VIEWERREF_GetName struct { + Document references.FPDF_DOCUMENT + Key string // Name of the key in the viewer pref dictionary. +} + +type FPDF_CountNamedDests struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_GetNamedDestByName struct { + Document references.FPDF_DOCUMENT + Name string +} + +type FPDF_GetNamedDest struct { + Document references.FPDF_DOCUMENT + Index int +} + +type FPDF_GetXFAPacketCount struct { + Document references.FPDF_DOCUMENT +} + +type FPDF_GetXFAPacketName struct { + Document references.FPDF_DOCUMENT + Index int +} + +type FPDF_GetXFAPacketContent struct { + Document references.FPDF_DOCUMENT + Index int +} diff --git a/responses/fpdfview.go b/responses/fpdfview.go index 4a3abf3a..09cde747 100644 --- a/responses/fpdfview.go +++ b/responses/fpdfview.go @@ -1,6 +1,10 @@ package responses -import "github.com/klippa-app/go-pdfium/references" +import ( + "github.com/klippa-app/go-pdfium/enums" + "github.com/klippa-app/go-pdfium/references" + "github.com/klippa-app/go-pdfium/structs" +) type FPDF_LoadDocument struct { Document references.FPDF_DOCUMENT @@ -85,3 +89,126 @@ type FPDF_GetPageSizeByIndex struct { Width float64 // The width of the page in points. One point is 1/72 inch (around 0.3528 mm). Height float64 // The height of the page in points. One point is 1/72 inch (around 0.3528 mm). } + +type FPDF_DocumentHasValidCrossReferenceTable struct { + DocumentHasValidCrossReferenceTable bool +} + +type FPDF_GetTrailerEnds struct { + TrailerEnds []int +} + +type FPDF_GetPageWidthF struct { + PageWidth float32 +} + +type FPDF_GetPageHeightF struct { + PageHeight float32 +} + +type FPDF_GetPageBoundingBox struct { + Rect structs.FPDF_FS_RECTF +} + +type FPDF_GetPageSizeByIndexF struct { + Size structs.FPDF_FS_SIZEF +} + +type FPDF_RenderPageBitmap struct{} + +type FPDF_RenderPageBitmapWithMatrix struct{} + +type FPDF_DeviceToPage struct { + PageX float64 + PageY float64 +} + +type FPDF_PageToDevice struct { + DeviceX int + DeviceY int +} + +type FPDFBitmap_Create struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_CreateEx struct { + Bitmap references.FPDF_BITMAP +} + +type FPDFBitmap_GetFormat struct { + Format enums.FPDF_BITMAP_FORMAT +} + +type FPDFBitmap_FillRect struct{} + +type FPDFBitmap_GetBuffer struct { + Buffer []byte +} + +type FPDFBitmap_GetWidth struct { + Width int +} + +type FPDFBitmap_GetHeight struct { + Height int +} + +type FPDFBitmap_GetStride struct { + Stride int +} + +type FPDFBitmap_Destroy struct{} + +type FPDF_VIEWERREF_GetPrintScaling struct { + PreferPrintScaling bool +} + +type FPDF_VIEWERREF_GetNumCopies struct { + NumCopies int +} + +type FPDF_VIEWERREF_GetPrintPageRange struct { + PageRange references.FPDF_PAGERANGE +} + +type FPDF_VIEWERREF_GetPrintPageRangeCount struct { + Count uint64 +} + +type FPDF_VIEWERREF_GetPrintPageRangeElement struct { + Value int +} + +type FPDF_VIEWERREF_GetDuplex struct { + DuplexType enums.FPDF_DUPLEXTYPE +} + +type FPDF_VIEWERREF_GetName struct { + Name string +} + +type FPDF_CountNamedDests struct { + Count uint64 +} + +type FPDF_GetNamedDestByName struct { + Dest references.FPDF_DEST +} + +type FPDF_GetNamedDest struct { + Dest references.FPDF_DEST + Name string +} + +type FPDF_GetXFAPacketCount struct { + Count int +} + +type FPDF_GetXFAPacketName struct { + Name string +} + +type FPDF_GetXFAPacketContent struct { + Content []byte +} diff --git a/single_threaded/generated.go b/single_threaded/generated.go index 4250e91b..062b6c63 100644 --- a/single_threaded/generated.go +++ b/single_threaded/generated.go @@ -165,6 +165,132 @@ func (i *pdfiumInstance) FPDFAttachment_SetStringValue(request *requests.FPDFAtt return i.pdfium.FPDFAttachment_SetStringValue(request) } +func (i *pdfiumInstance) FPDFBitmap_Create(request *requests.FPDFBitmap_Create) (resp *responses.FPDFBitmap_Create, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_Create", panicError) + } + }() + + return i.pdfium.FPDFBitmap_Create(request) +} + +func (i *pdfiumInstance) FPDFBitmap_CreateEx(request *requests.FPDFBitmap_CreateEx) (resp *responses.FPDFBitmap_CreateEx, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_CreateEx", panicError) + } + }() + + return i.pdfium.FPDFBitmap_CreateEx(request) +} + +func (i *pdfiumInstance) FPDFBitmap_Destroy(request *requests.FPDFBitmap_Destroy) (resp *responses.FPDFBitmap_Destroy, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_Destroy", panicError) + } + }() + + return i.pdfium.FPDFBitmap_Destroy(request) +} + +func (i *pdfiumInstance) FPDFBitmap_FillRect(request *requests.FPDFBitmap_FillRect) (resp *responses.FPDFBitmap_FillRect, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_FillRect", panicError) + } + }() + + return i.pdfium.FPDFBitmap_FillRect(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetBuffer(request *requests.FPDFBitmap_GetBuffer) (resp *responses.FPDFBitmap_GetBuffer, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetBuffer", panicError) + } + }() + + return i.pdfium.FPDFBitmap_GetBuffer(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetFormat(request *requests.FPDFBitmap_GetFormat) (resp *responses.FPDFBitmap_GetFormat, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetFormat", panicError) + } + }() + + return i.pdfium.FPDFBitmap_GetFormat(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetHeight(request *requests.FPDFBitmap_GetHeight) (resp *responses.FPDFBitmap_GetHeight, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetHeight", panicError) + } + }() + + return i.pdfium.FPDFBitmap_GetHeight(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetStride(request *requests.FPDFBitmap_GetStride) (resp *responses.FPDFBitmap_GetStride, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetStride", panicError) + } + }() + + return i.pdfium.FPDFBitmap_GetStride(request) +} + +func (i *pdfiumInstance) FPDFBitmap_GetWidth(request *requests.FPDFBitmap_GetWidth) (resp *responses.FPDFBitmap_GetWidth, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDFBitmap_GetWidth", panicError) + } + }() + + return i.pdfium.FPDFBitmap_GetWidth(request) +} + func (i *pdfiumInstance) FPDFBookmark_Find(request *requests.FPDFBookmark_Find) (resp *responses.FPDFBookmark_Find, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1299,6 +1425,20 @@ func (i *pdfiumInstance) FPDF_CopyViewerPreferences(request *requests.FPDF_CopyV return i.pdfium.FPDF_CopyViewerPreferences(request) } +func (i *pdfiumInstance) FPDF_CountNamedDests(request *requests.FPDF_CountNamedDests) (resp *responses.FPDF_CountNamedDests, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_CountNamedDests", panicError) + } + }() + + return i.pdfium.FPDF_CountNamedDests(request) +} + func (i *pdfiumInstance) FPDF_CreateNewDocument(request *requests.FPDF_CreateNewDocument) (resp *responses.FPDF_CreateNewDocument, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1313,6 +1453,34 @@ func (i *pdfiumInstance) FPDF_CreateNewDocument(request *requests.FPDF_CreateNew return i.pdfium.FPDF_CreateNewDocument(request) } +func (i *pdfiumInstance) FPDF_DeviceToPage(request *requests.FPDF_DeviceToPage) (resp *responses.FPDF_DeviceToPage, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_DeviceToPage", panicError) + } + }() + + return i.pdfium.FPDF_DeviceToPage(request) +} + +func (i *pdfiumInstance) FPDF_DocumentHasValidCrossReferenceTable(request *requests.FPDF_DocumentHasValidCrossReferenceTable) (resp *responses.FPDF_DocumentHasValidCrossReferenceTable, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_DocumentHasValidCrossReferenceTable", panicError) + } + }() + + return i.pdfium.FPDF_DocumentHasValidCrossReferenceTable(request) +} + func (i *pdfiumInstance) FPDF_GetDocPermissions(request *requests.FPDF_GetDocPermissions) (resp *responses.FPDF_GetDocPermissions, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1383,6 +1551,34 @@ func (i *pdfiumInstance) FPDF_GetMetaText(request *requests.FPDF_GetMetaText) (r return i.pdfium.FPDF_GetMetaText(request) } +func (i *pdfiumInstance) FPDF_GetNamedDest(request *requests.FPDF_GetNamedDest) (resp *responses.FPDF_GetNamedDest, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetNamedDest", panicError) + } + }() + + return i.pdfium.FPDF_GetNamedDest(request) +} + +func (i *pdfiumInstance) FPDF_GetNamedDestByName(request *requests.FPDF_GetNamedDestByName) (resp *responses.FPDF_GetNamedDestByName, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetNamedDestByName", panicError) + } + }() + + return i.pdfium.FPDF_GetNamedDestByName(request) +} + func (i *pdfiumInstance) FPDF_GetPageAAction(request *requests.FPDF_GetPageAAction) (resp *responses.FPDF_GetPageAAction, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1397,6 +1593,20 @@ func (i *pdfiumInstance) FPDF_GetPageAAction(request *requests.FPDF_GetPageAActi return i.pdfium.FPDF_GetPageAAction(request) } +func (i *pdfiumInstance) FPDF_GetPageBoundingBox(request *requests.FPDF_GetPageBoundingBox) (resp *responses.FPDF_GetPageBoundingBox, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageBoundingBox", panicError) + } + }() + + return i.pdfium.FPDF_GetPageBoundingBox(request) +} + func (i *pdfiumInstance) FPDF_GetPageCount(request *requests.FPDF_GetPageCount) (resp *responses.FPDF_GetPageCount, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1425,6 +1635,20 @@ func (i *pdfiumInstance) FPDF_GetPageHeight(request *requests.FPDF_GetPageHeight return i.pdfium.FPDF_GetPageHeight(request) } +func (i *pdfiumInstance) FPDF_GetPageHeightF(request *requests.FPDF_GetPageHeightF) (resp *responses.FPDF_GetPageHeightF, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageHeightF", panicError) + } + }() + + return i.pdfium.FPDF_GetPageHeightF(request) +} + func (i *pdfiumInstance) FPDF_GetPageLabel(request *requests.FPDF_GetPageLabel) (resp *responses.FPDF_GetPageLabel, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1453,6 +1677,20 @@ func (i *pdfiumInstance) FPDF_GetPageSizeByIndex(request *requests.FPDF_GetPageS return i.pdfium.FPDF_GetPageSizeByIndex(request) } +func (i *pdfiumInstance) FPDF_GetPageSizeByIndexF(request *requests.FPDF_GetPageSizeByIndexF) (resp *responses.FPDF_GetPageSizeByIndexF, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageSizeByIndexF", panicError) + } + }() + + return i.pdfium.FPDF_GetPageSizeByIndexF(request) +} + func (i *pdfiumInstance) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) (resp *responses.FPDF_GetPageWidth, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1467,6 +1705,20 @@ func (i *pdfiumInstance) FPDF_GetPageWidth(request *requests.FPDF_GetPageWidth) return i.pdfium.FPDF_GetPageWidth(request) } +func (i *pdfiumInstance) FPDF_GetPageWidthF(request *requests.FPDF_GetPageWidthF) (resp *responses.FPDF_GetPageWidthF, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetPageWidthF", panicError) + } + }() + + return i.pdfium.FPDF_GetPageWidthF(request) +} + func (i *pdfiumInstance) FPDF_GetSecurityHandlerRevision(request *requests.FPDF_GetSecurityHandlerRevision) (resp *responses.FPDF_GetSecurityHandlerRevision, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1509,6 +1761,62 @@ func (i *pdfiumInstance) FPDF_GetSignatureObject(request *requests.FPDF_GetSigna return i.pdfium.FPDF_GetSignatureObject(request) } +func (i *pdfiumInstance) FPDF_GetTrailerEnds(request *requests.FPDF_GetTrailerEnds) (resp *responses.FPDF_GetTrailerEnds, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetTrailerEnds", panicError) + } + }() + + return i.pdfium.FPDF_GetTrailerEnds(request) +} + +func (i *pdfiumInstance) FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (resp *responses.FPDF_GetXFAPacketContent, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetXFAPacketContent", panicError) + } + }() + + return i.pdfium.FPDF_GetXFAPacketContent(request) +} + +func (i *pdfiumInstance) FPDF_GetXFAPacketCount(request *requests.FPDF_GetXFAPacketCount) (resp *responses.FPDF_GetXFAPacketCount, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetXFAPacketCount", panicError) + } + }() + + return i.pdfium.FPDF_GetXFAPacketCount(request) +} + +func (i *pdfiumInstance) FPDF_GetXFAPacketName(request *requests.FPDF_GetXFAPacketName) (resp *responses.FPDF_GetXFAPacketName, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_GetXFAPacketName", panicError) + } + }() + + return i.pdfium.FPDF_GetXFAPacketName(request) +} + func (i *pdfiumInstance) FPDF_ImportNPagesToOne(request *requests.FPDF_ImportNPagesToOne) (resp *responses.FPDF_ImportNPagesToOne, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1649,6 +1957,48 @@ func (i *pdfiumInstance) FPDF_NewXObjectFromPage(request *requests.FPDF_NewXObje return i.pdfium.FPDF_NewXObjectFromPage(request) } +func (i *pdfiumInstance) FPDF_PageToDevice(request *requests.FPDF_PageToDevice) (resp *responses.FPDF_PageToDevice, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_PageToDevice", panicError) + } + }() + + return i.pdfium.FPDF_PageToDevice(request) +} + +func (i *pdfiumInstance) FPDF_RenderPageBitmap(request *requests.FPDF_RenderPageBitmap) (resp *responses.FPDF_RenderPageBitmap, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_RenderPageBitmap", panicError) + } + }() + + return i.pdfium.FPDF_RenderPageBitmap(request) +} + +func (i *pdfiumInstance) FPDF_RenderPageBitmapWithMatrix(request *requests.FPDF_RenderPageBitmapWithMatrix) (resp *responses.FPDF_RenderPageBitmapWithMatrix, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_RenderPageBitmapWithMatrix", panicError) + } + }() + + return i.pdfium.FPDF_RenderPageBitmapWithMatrix(request) +} + func (i *pdfiumInstance) FPDF_SaveAsCopy(request *requests.FPDF_SaveAsCopy) (resp *responses.FPDF_SaveAsCopy, err error) { if i.closed { return nil, errors.New("instance is closed") @@ -1691,6 +2041,104 @@ func (i *pdfiumInstance) FPDF_SetSandBoxPolicy(request *requests.FPDF_SetSandBox return i.pdfium.FPDF_SetSandBoxPolicy(request) } +func (i *pdfiumInstance) FPDF_VIEWERREF_GetDuplex(request *requests.FPDF_VIEWERREF_GetDuplex) (resp *responses.FPDF_VIEWERREF_GetDuplex, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetDuplex", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetDuplex(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetName(request *requests.FPDF_VIEWERREF_GetName) (resp *responses.FPDF_VIEWERREF_GetName, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetName", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetName(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetNumCopies(request *requests.FPDF_VIEWERREF_GetNumCopies) (resp *responses.FPDF_VIEWERREF_GetNumCopies, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetNumCopies", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetNumCopies(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintPageRange(request *requests.FPDF_VIEWERREF_GetPrintPageRange) (resp *responses.FPDF_VIEWERREF_GetPrintPageRange, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintPageRange", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetPrintPageRange(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintPageRangeCount(request *requests.FPDF_VIEWERREF_GetPrintPageRangeCount) (resp *responses.FPDF_VIEWERREF_GetPrintPageRangeCount, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintPageRangeCount", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetPrintPageRangeCount(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintPageRangeElement(request *requests.FPDF_VIEWERREF_GetPrintPageRangeElement) (resp *responses.FPDF_VIEWERREF_GetPrintPageRangeElement, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintPageRangeElement", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetPrintPageRangeElement(request) +} + +func (i *pdfiumInstance) FPDF_VIEWERREF_GetPrintScaling(request *requests.FPDF_VIEWERREF_GetPrintScaling) (resp *responses.FPDF_VIEWERREF_GetPrintScaling, err error) { + if i.closed { + return nil, errors.New("instance is closed") + } + + defer func() { + if panicError := recover(); panicError != nil { + err = fmt.Errorf("panic occurred in %s: %v", "FPDF_VIEWERREF_GetPrintScaling", panicError) + } + }() + + return i.pdfium.FPDF_VIEWERREF_GetPrintScaling(request) +} + func (i *pdfiumInstance) FSDK_SetLocaltimeFunction(request *requests.FSDK_SetLocaltimeFunction) (resp *responses.FSDK_SetLocaltimeFunction, err error) { if i.closed { return nil, errors.New("instance is closed") diff --git a/structs/structs.go b/structs/structs.go index 77dfb3f9..4818eb8e 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -26,3 +26,8 @@ type FPDF_FS_MATRIX struct { E float32 F float32 } + +type FPDF_FS_SIZEF struct { + Width float32 + Height float32 +} From 316d7f75f37cbcf6b0c2b439147cca25890b45ab Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Sun, 6 Feb 2022 17:49:44 +0100 Subject: [PATCH 3/6] Update readme --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 55a9a75c..4e6e9acd 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,15 @@ * Option between single-threaded and multi-threaded (through subprocesses), while keeping the same interface * This library will handle all complicated cgo gymnastics for you -* The goal is to implement all PDFium public API methods (including experimental), current progress: 30% +* The goal is to implement all PDFium public API methods (including experimental), current progress: 40% * Current PDFium methods exposed, no cgo required * PDFium instance configuration (sandbox policy, fonts) * Document loading (from bytes, path or io.ReadSeeker) * Document info (metadata, page count, render mode, PDF version, permissions, security handler revision) * Page info (size, transparency) * Rendering (through bitmap) + * Bitmap handling + * Named destinations * Text handling (extract, search, text size/color/font information) * Creation (create new documents and pages) * Editing (rotating, import pages from another document, copy view preferences from another document, flattening) @@ -31,15 +33,18 @@ * JavaScript actions * Thumbnails * Attachments + * XFA packet handling + * ViewerRef (print settings) * Methods to be implemented: * Form filling - * Bitmap handling - * Named destinations * Transformations (page boxes, clip paths) * Annotations * Document loading through data availability * Progressive rendering * Struct trees +* Methods that won't be implemented for now: + * Win32-only methods + * fpdf_sysfontinfo.h (probably too complicated) * Useful helpers to make your life easier: * Get all document metadata * Get all document bookmarks From 747ff2f553633de950ae82ad91b1db6bcdac67da Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Sun, 6 Feb 2022 17:50:14 +0100 Subject: [PATCH 4/6] Add flags to old-scool rendering --- internal/implementation/render.go | 12 +++++++++--- requests/render.go | 14 +++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/internal/implementation/render.go b/internal/implementation/render.go index cb13c8fb..a088d707 100644 --- a/internal/implementation/render.go +++ b/internal/implementation/render.go @@ -17,6 +17,7 @@ import ( "os" "unsafe" + "github.com/klippa-app/go-pdfium/enums" "github.com/klippa-app/go-pdfium/requests" "github.com/klippa-app/go-pdfium/responses" ) @@ -108,6 +109,7 @@ func (p *PdfiumImplementation) RenderPageInDPI(request *requests.RenderPageInDPI Width: widthInPixels, Height: heightInPixels, PointToPixelRatio: pointToPixelRatio, + Flags: request.RenderFlags, }, }, 0) if err != nil { @@ -150,6 +152,7 @@ func (p *PdfiumImplementation) RenderPagesInDPI(request *requests.RenderPagesInD Width: widthInPixels, Height: heightInPixels, PointToPixelRatio: pointToPixelRatio, + Flags: request.Pages[i].RenderFlags, } } @@ -222,6 +225,7 @@ func (p *PdfiumImplementation) RenderPageInPixels(request *requests.RenderPageIn Width: width, Height: height, PointToPixelRatio: ratio, + Flags: request.RenderFlags, }, }, 0) if err != nil { @@ -266,6 +270,7 @@ func (p *PdfiumImplementation) RenderPagesInPixels(request *requests.RenderPages Width: width, Height: height, PointToPixelRatio: ratio, + Flags: request.Pages[i].RenderFlags, } } @@ -281,6 +286,7 @@ func (p *PdfiumImplementation) RenderPagesInPixels(request *requests.RenderPages type renderPage struct { Page requests.Page + Flags enums.FPDF_RENDER_FLAG Width int Height int PointToPixelRatio float64 @@ -322,7 +328,7 @@ func (p *PdfiumImplementation) renderPages(pages []renderPage, padding int) (*re X: 0, Y: currentOffset, } - index, err := p.renderPage(bitmap, pages[i].Page, pages[i].Width, pages[i].Height, currentOffset) + index, err := p.renderPage(bitmap, pages[i].Page, pages[i].Width, pages[i].Height, currentOffset, pages[i].Flags) if err != nil { return nil, err } @@ -343,7 +349,7 @@ func (p *PdfiumImplementation) renderPages(pages []renderPage, padding int) (*re } // renderPage renders a specific page in a specific size on a bitmap. -func (p *PdfiumImplementation) renderPage(bitmap C.FPDF_BITMAP, page requests.Page, width, height, offset int) (int, error) { +func (p *PdfiumImplementation) renderPage(bitmap C.FPDF_BITMAP, page requests.Page, width, height, offset int, flags enums.FPDF_RENDER_FLAG) (int, error) { pageHandle, err := p.loadPage(page) if err != nil { return 0, err @@ -365,7 +371,7 @@ func (p *PdfiumImplementation) renderPage(bitmap C.FPDF_BITMAP, page requests.Pa // Render the bitmap into the given external bitmap, write the bytes // in reverse order so that BGRA becomes RGBA. - C.FPDF_RenderPageBitmap(bitmap, pageHandle.handle, 0, C.int(offset), C.int(width), C.int(height), 0, C.FPDF_ANNOT|C.FPDF_REVERSE_BYTE_ORDER) + C.FPDF_RenderPageBitmap(bitmap, pageHandle.handle, 0, C.int(offset), C.int(width), C.int(height), 0, C.int(flags)|C.FPDF_REVERSE_BYTE_ORDER) return pageHandle.index, nil } diff --git a/requests/render.go b/requests/render.go index c9033f21..eef7152b 100644 --- a/requests/render.go +++ b/requests/render.go @@ -1,8 +1,11 @@ package requests +import "github.com/klippa-app/go-pdfium/enums" + type RenderPageInDPI struct { - Page Page - DPI int // The DPI to render the page in. + Page Page + DPI int // The DPI to render the page in. + RenderFlags enums.FPDF_RENDER_FLAG // FPDF_RENDER_FLAG_REVERSE_BYTE_ORDER will always be set to render to Go image. } type RenderPagesInDPI struct { @@ -11,9 +14,10 @@ type RenderPagesInDPI struct { } type RenderPageInPixels struct { - Page Page - Width int // The maximum width of the image. - Height int // The maximum height of the image. + Page Page + Width int // The maximum width of the image. + Height int // The maximum height of the image. + RenderFlags enums.FPDF_RENDER_FLAG // FPDF_RENDER_FLAG_REVERSE_BYTE_ORDER will always be set to render to Go image. } type RenderPagesInPixels struct { From bdba06515780318ebec6fb6b4f91f7bd3abb302c Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Sun, 6 Feb 2022 20:10:21 +0100 Subject: [PATCH 5/6] Implement tests --- internal/implementation/fpdfview.go | 34 +- requests/render.go | 4 +- responses/fpdfview.go | 6 +- responses/render.go | 4 +- shared_tests/document.go | 9 + shared_tests/fpdf_thumbnail.go | 18 +- shared_tests/fpdfview.go | 1016 ++++++++++++++++++++++++++ shared_tests/testdata/bug_664284.pdf | Bin 0 -> 20874 bytes 8 files changed, 1064 insertions(+), 27 deletions(-) create mode 100644 shared_tests/testdata/bug_664284.pdf diff --git a/internal/implementation/fpdfview.go b/internal/implementation/fpdfview.go index fcfc1de7..42d17ad7 100644 --- a/internal/implementation/fpdfview.go +++ b/internal/implementation/fpdfview.go @@ -500,12 +500,12 @@ func (p *PdfiumImplementation) FPDF_RenderPageBitmap(request *requests.FPDF_Rend p.Lock() defer p.Unlock() - bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + pageHandle, err := p.loadPage(request.Page) if err != nil { return nil, err } - pageHandle, err := p.loadPage(request.Page) + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) if err != nil { return nil, err } @@ -520,12 +520,12 @@ func (p *PdfiumImplementation) FPDF_RenderPageBitmapWithMatrix(request *requests p.Lock() defer p.Unlock() - bitmapHandle, err := p.getBitmapHandle(request.Bitmap) + pageHandle, err := p.loadPage(request.Page) if err != nil { return nil, err } - pageHandle, err := p.loadPage(request.Page) + bitmapHandle, err := p.getBitmapHandle(request.Bitmap) if err != nil { return nil, err } @@ -548,7 +548,7 @@ func (p *PdfiumImplementation) FPDF_RenderPageBitmapWithMatrix(request *requests C.FPDF_RenderPageBitmapWithMatrix(bitmapHandle.handle, pageHandle.handle, &matrix, &clipping, C.int(request.Flags)) - return nil, nil + return &responses.FPDF_RenderPageBitmapWithMatrix{}, nil } // FPDF_DeviceToPage converts the screen coordinates of a point to page coordinates. @@ -794,7 +794,7 @@ func (p *PdfiumImplementation) FPDFBitmap_Destroy(request *requests.FPDFBitmap_D delete(p.bitmapRefs, bitmapHandle.nativeRef) - return nil, nil + return &responses.FPDFBitmap_Destroy{}, nil } // FPDF_VIEWERREF_GetPrintScaling returns whether the PDF document prefers to be scaled or not. @@ -874,6 +874,10 @@ func (p *PdfiumImplementation) FPDF_VIEWERREF_GetPrintPageRangeElement(request * } value := C.FPDF_VIEWERREF_GetPrintPageRangeElement(pageRangeHandle.handle, C.size_t(request.Index)) + if int(value) == -1 { + return nil, errors.New("could not load page range element") + } + return &responses.FPDF_VIEWERREF_GetPrintPageRangeElement{ Value: int(value), }, nil @@ -911,19 +915,14 @@ func (p *PdfiumImplementation) FPDF_VIEWERREF_GetName(request *requests.FPDF_VIE // First get the metadata length. nameSize := C.FPDF_VIEWERREF_GetName(documentHandle.handle, cstr, nil, 0) if nameSize == 0 { - return nil, errors.New("Could not get name") + return nil, errors.New("could not get name") } charData := make([]byte, uint64(nameSize)) C.FPDF_VIEWERREF_GetName(documentHandle.handle, cstr, (*C.char)(unsafe.Pointer(&charData[0])), C.ulong(len(charData))) - transformedText, err := p.transformUTF16LEToUTF8(charData) - if err != nil { - return nil, err - } - return &responses.FPDF_VIEWERREF_GetName{ - Name: transformedText, + Value: string(charData[:len(charData)-1]), // Remove nil terminator }, nil } @@ -1044,13 +1043,9 @@ func (p *PdfiumImplementation) FPDF_GetXFAPacketName(request *requests.FPDF_GetX return nil, errors.New("could not get name of the XFA packet") } - transformedText, err := p.transformUTF16LEToUTF8(charData) - if err != nil { - return nil, err - } - return &responses.FPDF_GetXFAPacketName{ - Name: transformedText, + Index: request.Index, + Name: string(charData[:len(charData)-1]), }, nil } @@ -1085,6 +1080,7 @@ func (p *PdfiumImplementation) FPDF_GetXFAPacketContent(request *requests.FPDF_G } return &responses.FPDF_GetXFAPacketContent{ + Index: request.Index, Content: contentData, }, nil } diff --git a/requests/render.go b/requests/render.go index eef7152b..7fcfae31 100644 --- a/requests/render.go +++ b/requests/render.go @@ -1,6 +1,8 @@ package requests -import "github.com/klippa-app/go-pdfium/enums" +import ( + "github.com/klippa-app/go-pdfium/enums" +) type RenderPageInDPI struct { Page Page diff --git a/responses/fpdfview.go b/responses/fpdfview.go index 09cde747..a25bff79 100644 --- a/responses/fpdfview.go +++ b/responses/fpdfview.go @@ -185,7 +185,7 @@ type FPDF_VIEWERREF_GetDuplex struct { } type FPDF_VIEWERREF_GetName struct { - Name string + Value string } type FPDF_CountNamedDests struct { @@ -206,9 +206,11 @@ type FPDF_GetXFAPacketCount struct { } type FPDF_GetXFAPacketName struct { - Name string + Index int + Name string } type FPDF_GetXFAPacketContent struct { + Index int Content []byte } diff --git a/responses/render.go b/responses/render.go index dcfd69a4..f04013b2 100644 --- a/responses/render.go +++ b/responses/render.go @@ -1,6 +1,8 @@ package responses -import "image" +import ( + "image" +) type RenderPage struct { Page int // The rendered page number (0-index based). diff --git a/shared_tests/document.go b/shared_tests/document.go index 1ce385f9..04a257f5 100644 --- a/shared_tests/document.go +++ b/shared_tests/document.go @@ -153,7 +153,16 @@ var _ = Describe("document", func() { Expect(err).To(MatchError(errors.ErrPassword.Error())) Expect(doc).To(BeNil()) }) + + It("returns the password error", func() { + doc, err := PdfiumInstance.FPDF_LoadMemDocument64(&requests.FPDF_LoadMemDocument64{ + Data: &pdfData, + }) + Expect(err).To(MatchError(errors.ErrPassword.Error())) + Expect(doc).To(BeNil()) + }) }) + When("is opened with the wrong password", func() { It("returns the password error", func() { wrongPassword := "test" diff --git a/shared_tests/fpdf_thumbnail.go b/shared_tests/fpdf_thumbnail.go index 168d811b..c7068cba 100644 --- a/shared_tests/fpdf_thumbnail.go +++ b/shared_tests/fpdf_thumbnail.go @@ -118,7 +118,7 @@ var _ = Describe("fpdf_thumbnail", func() { Expect(FPDF_CloseDocument).To(Not(BeNil())) }) - It("returns no decoded thumbnail data", func() { + It("returns decoded thumbnail data", func() { FPDFPage_GetDecodedThumbnailData, err := PdfiumInstance.FPDFPage_GetDecodedThumbnailData(&requests.FPDFPage_GetDecodedThumbnailData{ Page: requests.Page{ ByIndex: &requests.PageByIndex{ @@ -132,7 +132,7 @@ var _ = Describe("fpdf_thumbnail", func() { Expect(FPDFPage_GetDecodedThumbnailData.Thumbnail).To(HaveLen(1138)) }) - It("returns no raw thumbnail data", func() { + It("returns raw thumbnail data", func() { FPDFPage_GetRawThumbnailData, err := PdfiumInstance.FPDFPage_GetRawThumbnailData(&requests.FPDFPage_GetRawThumbnailData{ Page: requests.Page{ ByIndex: &requests.PageByIndex{ @@ -146,7 +146,8 @@ var _ = Describe("fpdf_thumbnail", func() { Expect(FPDFPage_GetRawThumbnailData.RawThumbnail).To(HaveLen(1851)) }) - It("returns no decoded thumbnail data", func() { + It("returns thumbnail as bitmap", func() { + By("when the thumbnail is fetched") FPDFPage_GetThumbnailAsBitmap, err := PdfiumInstance.FPDFPage_GetThumbnailAsBitmap(&requests.FPDFPage_GetThumbnailAsBitmap{ Page: requests.Page{ ByIndex: &requests.PageByIndex{ @@ -157,7 +158,16 @@ var _ = Describe("fpdf_thumbnail", func() { }) Expect(err).To(BeNil()) Expect(FPDFPage_GetThumbnailAsBitmap).To(Not(BeNil())) - // @todo: render thumbnail when FPDFBitmap_* is implemented and compare hash. + Expect(FPDFPage_GetThumbnailAsBitmap.Bitmap).To(Not(BeNil())) + + By("the first byte in the bitmap buffer is white") + FPDFBitmap_GetBuffer, err := PdfiumInstance.FPDFBitmap_GetBuffer(&requests.FPDFBitmap_GetBuffer{ + Bitmap: *FPDFPage_GetThumbnailAsBitmap.Bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetBuffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer[0]).To(Equal(uint8(255))) }) }) }) diff --git a/shared_tests/fpdfview.go b/shared_tests/fpdfview.go index a397fbe0..011b1510 100644 --- a/shared_tests/fpdfview.go +++ b/shared_tests/fpdfview.go @@ -1,11 +1,15 @@ package shared_tests +import "C" import ( + "io/ioutil" "os" + "github.com/klippa-app/go-pdfium/enums" "github.com/klippa-app/go-pdfium/references" "github.com/klippa-app/go-pdfium/requests" "github.com/klippa-app/go-pdfium/responses" + "github.com/klippa-app/go-pdfium/structs" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -67,6 +71,278 @@ var _ = Describe("fpdfview", func() { Expect(err).To(MatchError("document not given")) Expect(FPDF_GetPageSizeByIndex).To(BeNil()) }) + + It("returns an error when calling FPDF_DocumentHasValidCrossReferenceTable", func() { + FPDF_DocumentHasValidCrossReferenceTable, err := PdfiumInstance.FPDF_DocumentHasValidCrossReferenceTable(&requests.FPDF_DocumentHasValidCrossReferenceTable{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_DocumentHasValidCrossReferenceTable).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetTrailerEnds", func() { + FPDF_GetTrailerEnds, err := PdfiumInstance.FPDF_GetTrailerEnds(&requests.FPDF_GetTrailerEnds{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetTrailerEnds).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetPageSizeByIndexF", func() { + FPDF_GetPageSizeByIndexF, err := PdfiumInstance.FPDF_GetPageSizeByIndexF(&requests.FPDF_GetPageSizeByIndexF{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetPageSizeByIndexF).To(BeNil()) + }) + + It("returns an error when calling FPDF_VIEWERREF_GetPrintScaling", func() { + FPDF_VIEWERREF_GetPrintScaling, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintScaling(&requests.FPDF_VIEWERREF_GetPrintScaling{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_VIEWERREF_GetPrintScaling).To(BeNil()) + }) + + It("returns an error when calling FPDF_VIEWERREF_GetNumCopies", func() { + FPDF_VIEWERREF_GetNumCopies, err := PdfiumInstance.FPDF_VIEWERREF_GetNumCopies(&requests.FPDF_VIEWERREF_GetNumCopies{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_VIEWERREF_GetNumCopies).To(BeNil()) + }) + + It("returns an error when calling FPDF_VIEWERREF_GetPrintPageRange", func() { + FPDF_VIEWERREF_GetPrintPageRange, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRange(&requests.FPDF_VIEWERREF_GetPrintPageRange{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_VIEWERREF_GetPrintPageRange).To(BeNil()) + }) + + It("returns an error when calling FPDF_VIEWERREF_GetDuplex", func() { + FPDF_VIEWERREF_GetDuplex, err := PdfiumInstance.FPDF_VIEWERREF_GetDuplex(&requests.FPDF_VIEWERREF_GetDuplex{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_VIEWERREF_GetDuplex).To(BeNil()) + }) + + It("returns an error when calling FPDF_VIEWERREF_GetName", func() { + FPDF_VIEWERREF_GetName, err := PdfiumInstance.FPDF_VIEWERREF_GetName(&requests.FPDF_VIEWERREF_GetName{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_VIEWERREF_GetName).To(BeNil()) + }) + + It("returns an error when calling FPDF_CountNamedDests", func() { + FPDF_CountNamedDests, err := PdfiumInstance.FPDF_CountNamedDests(&requests.FPDF_CountNamedDests{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_CountNamedDests).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetNamedDestByName", func() { + FPDF_GetNamedDestByName, err := PdfiumInstance.FPDF_GetNamedDestByName(&requests.FPDF_GetNamedDestByName{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetNamedDestByName).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetNamedDest", func() { + FPDF_GetNamedDest, err := PdfiumInstance.FPDF_GetNamedDest(&requests.FPDF_GetNamedDest{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetNamedDest).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetXFAPacketCount", func() { + FPDF_GetXFAPacketCount, err := PdfiumInstance.FPDF_GetXFAPacketCount(&requests.FPDF_GetXFAPacketCount{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetXFAPacketCount).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetXFAPacketName", func() { + FPDF_GetXFAPacketName, err := PdfiumInstance.FPDF_GetXFAPacketName(&requests.FPDF_GetXFAPacketName{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetXFAPacketName).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetXFAPacketContent", func() { + FPDF_GetXFAPacketContent, err := PdfiumInstance.FPDF_GetXFAPacketContent(&requests.FPDF_GetXFAPacketContent{}) + Expect(err).To(MatchError("document not given")) + Expect(FPDF_GetXFAPacketContent).To(BeNil()) + }) + }) + }) + + Context("no page", func() { + When("is opened", func() { + It("returns an error when calling FPDF_GetPageWidthF", func() { + FPDF_GetPageWidthF, err := PdfiumInstance.FPDF_GetPageWidthF(&requests.FPDF_GetPageWidthF{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_GetPageWidthF).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetPageHeightF", func() { + FPDF_GetPageHeightF, err := PdfiumInstance.FPDF_GetPageHeightF(&requests.FPDF_GetPageHeightF{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_GetPageHeightF).To(BeNil()) + }) + + It("returns an error when calling FPDF_GetPageBoundingBox", func() { + FPDF_GetPageBoundingBox, err := PdfiumInstance.FPDF_GetPageBoundingBox(&requests.FPDF_GetPageBoundingBox{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_GetPageBoundingBox).To(BeNil()) + }) + + It("returns an error when calling FPDF_RenderPageBitmap", func() { + FPDF_RenderPageBitmap, err := PdfiumInstance.FPDF_RenderPageBitmap(&requests.FPDF_RenderPageBitmap{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_RenderPageBitmap).To(BeNil()) + }) + + It("returns an error when calling FPDF_RenderPageBitmapWithMatrix", func() { + FPDF_RenderPageBitmapWithMatrix, err := PdfiumInstance.FPDF_RenderPageBitmapWithMatrix(&requests.FPDF_RenderPageBitmapWithMatrix{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_RenderPageBitmapWithMatrix).To(BeNil()) + }) + + It("returns an error when calling FPDF_DeviceToPage", func() { + FPDF_DeviceToPage, err := PdfiumInstance.FPDF_DeviceToPage(&requests.FPDF_DeviceToPage{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_DeviceToPage).To(BeNil()) + }) + + It("returns an error when calling FPDF_PageToDevice", func() { + FPDF_PageToDevice, err := PdfiumInstance.FPDF_PageToDevice(&requests.FPDF_PageToDevice{}) + Expect(err).To(MatchError("either page reference or index should be given")) + Expect(FPDF_PageToDevice).To(BeNil()) + }) + }) + }) + + Context("no bitmap", func() { + When("is opened", func() { + It("returns an error when calling FPDFBitmap_GetFormat", func() { + FPDFBitmap_GetFormat, err := PdfiumInstance.FPDFBitmap_GetFormat(&requests.FPDFBitmap_GetFormat{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_GetFormat).To(BeNil()) + }) + + It("returns an error when calling FPDFBitmap_FillRect", func() { + FPDFBitmap_FillRect, err := PdfiumInstance.FPDFBitmap_FillRect(&requests.FPDFBitmap_FillRect{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_FillRect).To(BeNil()) + }) + + It("returns an error when calling FPDFBitmap_GetBuffer", func() { + FPDFBitmap_GetBuffer, err := PdfiumInstance.FPDFBitmap_GetBuffer(&requests.FPDFBitmap_GetBuffer{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_GetBuffer).To(BeNil()) + }) + + It("returns an error when calling FPDFBitmap_GetWidth", func() { + FPDFBitmap_GetWidth, err := PdfiumInstance.FPDFBitmap_GetWidth(&requests.FPDFBitmap_GetWidth{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_GetWidth).To(BeNil()) + }) + + It("returns an error when calling FPDFBitmap_GetFormat", func() { + FPDFBitmap_GetHeight, err := PdfiumInstance.FPDFBitmap_GetHeight(&requests.FPDFBitmap_GetHeight{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_GetHeight).To(BeNil()) + }) + + It("returns an error when calling FPDFBitmap_GetStride", func() { + FPDFBitmap_GetStride, err := PdfiumInstance.FPDFBitmap_GetStride(&requests.FPDFBitmap_GetStride{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_GetStride).To(BeNil()) + }) + + It("returns an error when calling FPDFBitmap_Destroy", func() { + FPDFBitmap_Destroy, err := PdfiumInstance.FPDFBitmap_Destroy(&requests.FPDFBitmap_Destroy{}) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDFBitmap_Destroy).To(BeNil()) + }) + }) + }) + + Context("no page range", func() { + When("is opened", func() { + It("returns an error when calling FPDF_VIEWERREF_GetPrintPageRangeCount", func() { + FPDF_VIEWERREF_GetPrintPageRangeCount, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRangeCount(&requests.FPDF_VIEWERREF_GetPrintPageRangeCount{}) + Expect(err).To(MatchError("pageRange not given")) + Expect(FPDF_VIEWERREF_GetPrintPageRangeCount).To(BeNil()) + }) + + It("returns an error when calling FPDF_VIEWERREF_GetPrintPageRangeElement", func() { + FPDF_VIEWERREF_GetPrintPageRangeElement, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRangeElement(&requests.FPDF_VIEWERREF_GetPrintPageRangeElement{}) + Expect(err).To(MatchError("pageRange not given")) + Expect(FPDF_VIEWERREF_GetPrintPageRangeElement).To(BeNil()) + }) + }) + }) + + Context("a PDF file with an invalid cross reference table", func() { + var doc references.FPDF_DOCUMENT + + BeforeEach(func() { + file, err := os.Open(TestDataPath + "/testdata/bug_664284.pdf") + Expect(err).To(BeNil()) + + fileStat, err := file.Stat() + Expect(err).To(BeNil()) + + newDoc, err := PdfiumInstance.FPDF_LoadCustomDocument(&requests.FPDF_LoadCustomDocument{ + Reader: file, + Size: fileStat.Size(), + }) + Expect(err).To(BeNil()) + + doc = newDoc.Document + }) + + AfterEach(func() { + FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CloseDocument).To(Not(BeNil())) + }) + + When("is opened", func() { + It("returns that it has an invalid cross reference table", func() { + FPDF_DocumentHasValidCrossReferenceTable, err := PdfiumInstance.FPDF_DocumentHasValidCrossReferenceTable(&requests.FPDF_DocumentHasValidCrossReferenceTable{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_DocumentHasValidCrossReferenceTable).To(Equal(&responses.FPDF_DocumentHasValidCrossReferenceTable{ + DocumentHasValidCrossReferenceTable: false, + })) + }) + }) + }) + + Context("a PDF file with multiple trailer ends", func() { + var doc references.FPDF_DOCUMENT + + BeforeEach(func() { + file, err := os.Open(TestDataPath + "/testdata/annotation_stamp_with_ap.pdf") + Expect(err).To(BeNil()) + + fileStat, err := file.Stat() + Expect(err).To(BeNil()) + + newDoc, err := PdfiumInstance.FPDF_LoadCustomDocument(&requests.FPDF_LoadCustomDocument{ + Reader: file, + Size: fileStat.Size(), + }) + Expect(err).To(BeNil()) + + doc = newDoc.Document + }) + + AfterEach(func() { + FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CloseDocument).To(Not(BeNil())) + }) + + When("is opened", func() { + It("returns the correct trailer ends", func() { + FPDF_GetTrailerEnds, err := PdfiumInstance.FPDF_GetTrailerEnds(&requests.FPDF_GetTrailerEnds{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetTrailerEnds).To(Equal(&responses.FPDF_GetTrailerEnds{ + TrailerEnds: []int{441, 7945, 101719}, + })) + }) }) }) @@ -210,6 +486,746 @@ var _ = Describe("fpdfview", func() { Expect(err).To(MatchError("could not load page size by index")) Expect(pageCount).To(BeNil()) }) + + It("returns that it has a valid cross reference table", func() { + FPDF_DocumentHasValidCrossReferenceTable, err := PdfiumInstance.FPDF_DocumentHasValidCrossReferenceTable(&requests.FPDF_DocumentHasValidCrossReferenceTable{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_DocumentHasValidCrossReferenceTable).To(Equal(&responses.FPDF_DocumentHasValidCrossReferenceTable{ + DocumentHasValidCrossReferenceTable: true, + })) + }) + + It("returns the correct trailer ends", func() { + FPDF_GetTrailerEnds, err := PdfiumInstance.FPDF_GetTrailerEnds(&requests.FPDF_GetTrailerEnds{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetTrailerEnds).To(Equal(&responses.FPDF_GetTrailerEnds{ + TrailerEnds: []int{11616}, + })) + }) + + It("returns the correct page width in float32", func() { + FPDF_GetPageWidthF, err := PdfiumInstance.FPDF_GetPageWidthF(&requests.FPDF_GetPageWidthF{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetPageWidthF).To(Equal(&responses.FPDF_GetPageWidthF{ + PageWidth: 595.2755737304688, + })) + }) + + It("returns the correct page height in float32", func() { + FPDF_GetPageHeightF, err := PdfiumInstance.FPDF_GetPageHeightF(&requests.FPDF_GetPageHeightF{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetPageHeightF).To(Equal(&responses.FPDF_GetPageHeightF{ + PageHeight: 841.8897094726562, + })) + }) + + It("returns the correct page bounding box", func() { + FPDF_GetPageBoundingBox, err := PdfiumInstance.FPDF_GetPageBoundingBox(&requests.FPDF_GetPageBoundingBox{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetPageBoundingBox).To(Equal(&responses.FPDF_GetPageBoundingBox{ + Rect: structs.FPDF_FS_RECTF{ + Left: 0, + Top: 841.8897094726562, + Right: 595.2755737304688, + Bottom: 0, + }, + })) + }) + + It("returns the correct page size by index in float32", func() { + FPDF_GetPageSizeByIndexF, err := PdfiumInstance.FPDF_GetPageSizeByIndexF(&requests.FPDF_GetPageSizeByIndexF{ + Document: doc, + Index: 0, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetPageSizeByIndexF).To(Equal(&responses.FPDF_GetPageSizeByIndexF{ + Size: structs.FPDF_FS_SIZEF{ + Width: 595.2755737304688, + Height: 841.8897094726562, + }, + })) + }) + + It("returns the correct device to page calculations", func() { + FPDF_DeviceToPage, err := PdfiumInstance.FPDF_DeviceToPage(&requests.FPDF_DeviceToPage{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + StartX: 0, + StartY: 0, + SizeX: 1000, + SizeY: 1000, + Rotate: enums.FPDF_PAGE_ROTATION_NONE, + DeviceX: 500, + DeviceY: 500, + }) + Expect(err).To(BeNil()) + Expect(FPDF_DeviceToPage).To(Equal(&responses.FPDF_DeviceToPage{ + PageX: 297.6377868652344, + PageY: 420.9448547363281, + })) + }) + + It("returns the correct page to device calculations", func() { + FPDF_PageToDevice, err := PdfiumInstance.FPDF_PageToDevice(&requests.FPDF_PageToDevice{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + StartX: 0, + StartY: 0, + SizeX: 1000, + SizeY: 1000, + Rotate: enums.FPDF_PAGE_ROTATION_NONE, + PageX: 297.6377868652344, + PageY: 420.9448547363281, + }) + Expect(err).To(BeNil()) + Expect(FPDF_PageToDevice).To(Equal(&responses.FPDF_PageToDevice{ + DeviceX: 500, + DeviceY: 500, + })) + }) + + It("returns the correct print scaling", func() { + FPDF_VIEWERREF_GetPrintScaling, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintScaling(&requests.FPDF_VIEWERREF_GetPrintScaling{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetPrintScaling).To(Equal(&responses.FPDF_VIEWERREF_GetPrintScaling{ + PreferPrintScaling: true, + })) + }) + + It("returns the correct print number of copies", func() { + FPDF_VIEWERREF_GetNumCopies, err := PdfiumInstance.FPDF_VIEWERREF_GetNumCopies(&requests.FPDF_VIEWERREF_GetNumCopies{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetNumCopies).To(Equal(&responses.FPDF_VIEWERREF_GetNumCopies{ + NumCopies: 1, + })) + }) + + When("a print page range has been loaded", func() { + var pageRange references.FPDF_PAGERANGE + BeforeEach(func() { + FPDF_VIEWERREF_GetPrintPageRange, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRange(&requests.FPDF_VIEWERREF_GetPrintPageRange{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetPrintPageRange).To(Not(BeNil())) + pageRange = FPDF_VIEWERREF_GetPrintPageRange.PageRange + }) + + It("returns the correct print page range count", func() { + FPDF_VIEWERREF_GetPrintPageRangeCount, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRangeCount(&requests.FPDF_VIEWERREF_GetPrintPageRangeCount{ + PageRange: pageRange, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetPrintPageRangeCount).To(Equal(&responses.FPDF_VIEWERREF_GetPrintPageRangeCount{})) + }) + }) + + It("returns the correct print duplex", func() { + FPDF_VIEWERREF_GetDuplex, err := PdfiumInstance.FPDF_VIEWERREF_GetDuplex(&requests.FPDF_VIEWERREF_GetDuplex{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetDuplex).To(Equal(&responses.FPDF_VIEWERREF_GetDuplex{ + DuplexType: enums.FPDF_DUPLEXTYPE_UNDEFINED, + })) + }) + + When("no bitmap is given", func() { + It("returns an error when FPDF_RenderPageBitmap is called", func() { + FPDF_RenderPageBitmap, err := PdfiumInstance.FPDF_RenderPageBitmap(&requests.FPDF_RenderPageBitmap{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + }) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDF_RenderPageBitmap).To(BeNil()) + }) + + It("returns an error when FPDF_RenderPageBitmapWithMatrix is called", func() { + FPDF_RenderPageBitmapWithMatrix, err := PdfiumInstance.FPDF_RenderPageBitmapWithMatrix(&requests.FPDF_RenderPageBitmapWithMatrix{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + }, + }, + }) + Expect(err).To(MatchError("bitmap not given")) + Expect(FPDF_RenderPageBitmapWithMatrix).To(BeNil()) + }) + }) + + When("a bitmap has been created", func() { + var bitmap references.FPDF_BITMAP + BeforeEach(func() { + FPDFBitmap_Create, err := PdfiumInstance.FPDFBitmap_Create(&requests.FPDFBitmap_Create{ + Width: 1000, + Height: 1000, + Alpha: 1, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_Create).To(Not(BeNil())) + bitmap = FPDFBitmap_Create.Bitmap + }) + + AfterEach(func() { + FPDFBitmap_Destroy, err := PdfiumInstance.FPDFBitmap_Destroy(&requests.FPDFBitmap_Destroy{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_Destroy).To(Equal(&responses.FPDFBitmap_Destroy{})) + }) + + It("returns the correct bitmap format", func() { + FPDFBitmap_GetFormat, err := PdfiumInstance.FPDFBitmap_GetFormat(&requests.FPDFBitmap_GetFormat{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetFormat).To(Equal(&responses.FPDFBitmap_GetFormat{ + Format: enums.FPDF_BITMAP_FORMAT_BGRA, + })) + }) + + It("returns the correct bitmap width", func() { + FPDFBitmap_GetWidth, err := PdfiumInstance.FPDFBitmap_GetWidth(&requests.FPDFBitmap_GetWidth{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetWidth).To(Equal(&responses.FPDFBitmap_GetWidth{ + Width: 1000, + })) + }) + + It("returns the correct bitmap height", func() { + FPDFBitmap_GetHeight, err := PdfiumInstance.FPDFBitmap_GetHeight(&requests.FPDFBitmap_GetHeight{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetHeight).To(Equal(&responses.FPDFBitmap_GetHeight{ + Height: 1000, + })) + }) + + It("returns the correct bitmap stride", func() { + FPDFBitmap_GetStride, err := PdfiumInstance.FPDFBitmap_GetStride(&requests.FPDFBitmap_GetStride{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetStride).To(Equal(&responses.FPDFBitmap_GetStride{ + Stride: 4000, + })) + }) + + It("returns the correct bitmap buffer", func() { + FPDFBitmap_GetBuffer, err := PdfiumInstance.FPDFBitmap_GetBuffer(&requests.FPDFBitmap_GetBuffer{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetBuffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer).To(HaveLen(4000000)) + Expect(FPDFBitmap_GetBuffer.Buffer[0]).To(Equal(uint8(0))) + }) + + It("allows the bitmap to be filled by white", func() { + By("when the bitmap is filled") + FPDFBitmap_FillRect, err := PdfiumInstance.FPDFBitmap_FillRect(&requests.FPDFBitmap_FillRect{ + Bitmap: bitmap, + Color: 0xFFFFFFFF, + Left: 0, + Top: 0, + Width: 1000, + Height: 1000, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_FillRect).To(Equal(&responses.FPDFBitmap_FillRect{})) + + By("the first byte of the buffer is white") + FPDFBitmap_GetBuffer, err := PdfiumInstance.FPDFBitmap_GetBuffer(&requests.FPDFBitmap_GetBuffer{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetBuffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer[0]).To(Equal(uint8(255))) + }) + + It("allows a page to be rendered to the bitmap", func() { + By("when the page is rendered") + FPDF_RenderPageBitmap, err := PdfiumInstance.FPDF_RenderPageBitmap(&requests.FPDF_RenderPageBitmap{ + Bitmap: bitmap, + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + StartX: 0, + StartY: 0, + SizeX: 1000, + SizeY: 1000, + Rotate: enums.FPDF_PAGE_ROTATION_NONE, + Flags: 0, + }) + Expect(err).To(BeNil()) + Expect(FPDF_RenderPageBitmap).To(Equal(&responses.FPDF_RenderPageBitmap{})) + + By("the byte 212483 of the buffer is non-transparent") + FPDFBitmap_GetBuffer, err := PdfiumInstance.FPDFBitmap_GetBuffer(&requests.FPDFBitmap_GetBuffer{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetBuffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer[212483]).To(Equal(uint8(44))) + }) + + It("allows a page to be rendered to the bitmap by matrix and clipping", func() { + By("when the page is rendered") + FPDF_RenderPageBitmapWithMatrix, err := PdfiumInstance.FPDF_RenderPageBitmapWithMatrix(&requests.FPDF_RenderPageBitmapWithMatrix{ + Bitmap: bitmap, + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: doc, + Index: 0, + }, + }, + Matrix: structs.FPDF_FS_MATRIX{0.5, 0, 0, 0.5, 0, 0}, // Half scale + Clipping: structs.FPDF_FS_RECTF{0, 0, 1000, 1000}, + Flags: 0, + }) + Expect(err).To(BeNil()) + Expect(FPDF_RenderPageBitmapWithMatrix).To(Equal(&responses.FPDF_RenderPageBitmapWithMatrix{})) + + By("the byte 84143 of the buffer is non-transparent") + FPDFBitmap_GetBuffer, err := PdfiumInstance.FPDFBitmap_GetBuffer(&requests.FPDFBitmap_GetBuffer{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetBuffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer).To(Not(BeNil())) + Expect(FPDFBitmap_GetBuffer.Buffer[84143]).To(Equal(uint8(2))) + }) + }) + + When("an external bitmap has been created", func() { + if TestType == "multi" { + Skip("External bitmap is not supported on multi-threaded usage") + } + var bitmap references.FPDF_BITMAP + var buffer []byte + BeforeEach(func() { + buffer = make([]byte, (1000*4)*1000) // 1000 pixels in width * 4 bytes per pixel * 1000 pixels in height + + FPDFBitmap_CreateEx, err := PdfiumInstance.FPDFBitmap_CreateEx(&requests.FPDFBitmap_CreateEx{ + Width: 1000, + Height: 1000, + Format: enums.FPDF_BITMAP_FORMAT_BGRA, + Buffer: buffer, + Stride: 4000, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_CreateEx).To(Not(BeNil())) + bitmap = FPDFBitmap_CreateEx.Bitmap + }) + + AfterEach(func() { + FPDFBitmap_Destroy, err := PdfiumInstance.FPDFBitmap_Destroy(&requests.FPDFBitmap_Destroy{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_Destroy).To(Equal(&responses.FPDFBitmap_Destroy{})) + buffer = nil + }) + + It("returns the correct bitmap format", func() { + FPDFBitmap_GetFormat, err := PdfiumInstance.FPDFBitmap_GetFormat(&requests.FPDFBitmap_GetFormat{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetFormat).To(Equal(&responses.FPDFBitmap_GetFormat{ + Format: enums.FPDF_BITMAP_FORMAT_BGRA, + })) + }) + + It("returns the correct bitmap width", func() { + FPDFBitmap_GetWidth, err := PdfiumInstance.FPDFBitmap_GetWidth(&requests.FPDFBitmap_GetWidth{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetWidth).To(Equal(&responses.FPDFBitmap_GetWidth{ + Width: 1000, + })) + }) + + It("returns the correct bitmap height", func() { + FPDFBitmap_GetHeight, err := PdfiumInstance.FPDFBitmap_GetHeight(&requests.FPDFBitmap_GetHeight{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetHeight).To(Equal(&responses.FPDFBitmap_GetHeight{ + Height: 1000, + })) + }) + + It("returns the correct bitmap stride", func() { + FPDFBitmap_GetStride, err := PdfiumInstance.FPDFBitmap_GetStride(&requests.FPDFBitmap_GetStride{ + Bitmap: bitmap, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_GetStride).To(Equal(&responses.FPDFBitmap_GetStride{ + Stride: 4000, + })) + }) + + It("allows the bitmap to be filled by white", func() { + By("the first byte of the buffer is transparent") + Expect(buffer[0]).To(Equal(uint8(0))) + + By("when the bitmap is filled") + FPDFBitmap_FillRect, err := PdfiumInstance.FPDFBitmap_FillRect(&requests.FPDFBitmap_FillRect{ + Bitmap: bitmap, + Color: 0xFFFFFFFF, + Left: 0, + Top: 0, + Width: 1000, + Height: 1000, + }) + Expect(err).To(BeNil()) + Expect(FPDFBitmap_FillRect).To(Equal(&responses.FPDFBitmap_FillRect{})) + + By("the first byte of the buffer is white") + Expect(buffer[0]).To(Equal(uint8(255))) + }) + }) + }) + }) + + Context("a PDF file with named dests", func() { + var doc references.FPDF_DOCUMENT + var file *os.File + + BeforeEach(func() { + pdfFile, err := os.Open(TestDataPath + "/testdata/named_dests.pdf") + Expect(err).To(BeNil()) + + file = pdfFile + fileStat, err := file.Stat() + Expect(err).To(BeNil()) + + newDoc, err := PdfiumInstance.FPDF_LoadCustomDocument(&requests.FPDF_LoadCustomDocument{ + Reader: file, + Size: fileStat.Size(), + }) + Expect(err).To(BeNil()) + + doc = newDoc.Document + }) + + AfterEach(func() { + FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CloseDocument).To(Not(BeNil())) + file.Close() + }) + + When("is opened", func() { + It("returns the correct dest count", func() { + FPDF_CountNamedDests, err := PdfiumInstance.FPDF_CountNamedDests(&requests.FPDF_CountNamedDests{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CountNamedDests).To(Equal(&responses.FPDF_CountNamedDests{ + Count: 6, + })) + }) + + It("returns a dest by name", func() { + FPDF_GetNamedDestByName, err := PdfiumInstance.FPDF_GetNamedDestByName(&requests.FPDF_GetNamedDestByName{ + Document: doc, + Name: "First", + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetNamedDestByName).To(Not(BeNil())) + Expect(FPDF_GetNamedDestByName.Dest).To(Not(BeNil())) + }) + + It("returns an error when it can't find a dest by name", func() { + FPDF_GetNamedDestByName, err := PdfiumInstance.FPDF_GetNamedDestByName(&requests.FPDF_GetNamedDestByName{ + Document: doc, + Name: "Firstfake", + }) + Expect(err).To(MatchError("could not get named dest by name")) + Expect(FPDF_GetNamedDestByName).To(BeNil()) + }) + + It("returns the correct dest by index", func() { + FPDF_GetNamedDest, err := PdfiumInstance.FPDF_GetNamedDest(&requests.FPDF_GetNamedDest{ + Document: doc, + Index: 0, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetNamedDest).To(Not(BeNil())) + Expect(FPDF_GetNamedDest.Name).To(Equal("First")) + }) + + It("returns an error when getting a dest with an invalid index", func() { + FPDF_GetNamedDest, err := PdfiumInstance.FPDF_GetNamedDest(&requests.FPDF_GetNamedDest{ + Document: doc, + Index: 25, + }) + Expect(err).To(MatchError("could not get name of named dest")) + Expect(FPDF_GetNamedDest).To(BeNil()) + }) + }) + }) + + Context("a normal PDF file", func() { + It("can be loaded with FPDF_LoadMemDocument", func() { + pdfData, err := ioutil.ReadFile(TestDataPath + "/testdata/test.pdf") + Expect(err).To(BeNil()) + + newDoc, err := PdfiumInstance.FPDF_LoadMemDocument64(&requests.FPDF_LoadMemDocument64{ + Data: &pdfData, + }) + Expect(err).To(BeNil()) + + FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{ + Document: newDoc.Document, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CloseDocument).To(Not(BeNil())) + }) + }) + + Context("a PDF file with XFA data", func() { + var doc references.FPDF_DOCUMENT + var file *os.File + + BeforeEach(func() { + pdfFile, err := os.Open(TestDataPath + "/testdata/simple_xfa.pdf") + Expect(err).To(BeNil()) + + file = pdfFile + fileStat, err := file.Stat() + Expect(err).To(BeNil()) + + newDoc, err := PdfiumInstance.FPDF_LoadCustomDocument(&requests.FPDF_LoadCustomDocument{ + Reader: file, + Size: fileStat.Size(), + }) + Expect(err).To(BeNil()) + + doc = newDoc.Document + }) + + AfterEach(func() { + FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CloseDocument).To(Not(BeNil())) + file.Close() + }) + + When("is opened", func() { + It("returns the correct XFA packet count", func() { + FPDF_GetXFAPacketCount, err := PdfiumInstance.FPDF_GetXFAPacketCount(&requests.FPDF_GetXFAPacketCount{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetXFAPacketCount).To(Equal(&responses.FPDF_GetXFAPacketCount{ + Count: 5, + })) + }) + + It("returns the correct XFA packet name", func() { + FPDF_GetXFAPacketName, err := PdfiumInstance.FPDF_GetXFAPacketName(&requests.FPDF_GetXFAPacketName{ + Document: doc, + Index: 1, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetXFAPacketName).To(Equal(&responses.FPDF_GetXFAPacketName{ + Index: 1, + Name: "config", + })) + }) + + It("returns an error when requesting an incorrect XFA packet name", func() { + FPDF_GetXFAPacketName, err := PdfiumInstance.FPDF_GetXFAPacketName(&requests.FPDF_GetXFAPacketName{ + Document: doc, + Index: 25, + }) + Expect(err).To(MatchError("could not get name of the XFA packet")) + Expect(FPDF_GetXFAPacketName).To(BeNil()) + }) + + It("returns the correct XFA packet content", func() { + FPDF_GetXFAPacketContent, err := PdfiumInstance.FPDF_GetXFAPacketContent(&requests.FPDF_GetXFAPacketContent{ + Document: doc, + Index: 1, + }) + Expect(err).To(BeNil()) + Expect(FPDF_GetXFAPacketContent).To(Equal(&responses.FPDF_GetXFAPacketContent{ + Index: 1, + Content: []byte{60, 99, 111, 110, 102, 105, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 120, 102, 97, 46, 111, 114, 103, 47, 115, 99, 104, 101, 109, 97, 47, 120, 99, 105, 47, 51, 46, 48, 47, 34, 62, 10, 60, 97, 103, 101, 110, 116, 32, 110, 97, 109, 101, 61, 34, 100, 101, 115, 105, 103, 110, 101, 114, 34, 62, 10, 32, 32, 60, 100, 101, 115, 116, 105, 110, 97, 116, 105, 111, 110, 62, 112, 100, 102, 60, 47, 100, 101, 115, 116, 105, 110, 97, 116, 105, 111, 110, 62, 10, 32, 32, 60, 112, 100, 102, 62, 10, 32, 32, 32, 32, 60, 102, 111, 110, 116, 73, 110, 102, 111, 47, 62, 10, 32, 32, 60, 47, 112, 100, 102, 62, 10, 60, 47, 97, 103, 101, 110, 116, 62, 10, 60, 112, 114, 101, 115, 101, 110, 116, 62, 10, 32, 32, 60, 112, 100, 102, 62, 10, 32, 32, 32, 32, 60, 118, 101, 114, 115, 105, 111, 110, 62, 49, 46, 55, 60, 47, 118, 101, 114, 115, 105, 111, 110, 62, 10, 32, 32, 32, 32, 60, 97, 100, 111, 98, 101, 69, 120, 116, 101, 110, 115, 105, 111, 110, 76, 101, 118, 101, 108, 62, 56, 60, 47, 97, 100, 111, 98, 101, 69, 120, 116, 101, 110, 115, 105, 111, 110, 76, 101, 118, 101, 108, 62, 10, 32, 32, 32, 32, 60, 114, 101, 110, 100, 101, 114, 80, 111, 108, 105, 99, 121, 62, 99, 108, 105, 101, 110, 116, 60, 47, 114, 101, 110, 100, 101, 114, 80, 111, 108, 105, 99, 121, 62, 10, 32, 32, 32, 32, 60, 115, 99, 114, 105, 112, 116, 77, 111, 100, 101, 108, 62, 88, 70, 65, 60, 47, 115, 99, 114, 105, 112, 116, 77, 111, 100, 101, 108, 62, 10, 32, 32, 32, 32, 60, 105, 110, 116, 101, 114, 97, 99, 116, 105, 118, 101, 62, 49, 60, 47, 105, 110, 116, 101, 114, 97, 99, 116, 105, 118, 101, 62, 10, 32, 32, 60, 47, 112, 100, 102, 62, 10, 32, 32, 60, 120, 100, 112, 62, 10, 32, 32, 32, 32, 60, 112, 97, 99, 107, 101, 116, 115, 62, 42, 60, 47, 112, 97, 99, 107, 101, 116, 115, 62, 10, 32, 32, 60, 47, 120, 100, 112, 62, 10, 32, 32, 60, 100, 101, 115, 116, 105, 110, 97, 116, 105, 111, 110, 62, 112, 100, 102, 60, 47, 100, 101, 115, 116, 105, 110, 97, 116, 105, 111, 110, 62, 10, 32, 32, 60, 115, 99, 114, 105, 112, 116, 62, 10, 32, 32, 32, 32, 60, 114, 117, 110, 83, 99, 114, 105, 112, 116, 115, 62, 115, 101, 114, 118, 101, 114, 60, 47, 114, 117, 110, 83, 99, 114, 105, 112, 116, 115, 62, 10, 32, 32, 60, 47, 115, 99, 114, 105, 112, 116, 62, 10, 60, 47, 112, 114, 101, 115, 101, 110, 116, 62, 10, 60, 97, 99, 114, 111, 98, 97, 116, 62, 10, 32, 32, 60, 97, 99, 114, 111, 98, 97, 116, 55, 62, 10, 32, 32, 32, 32, 60, 100, 121, 110, 97, 109, 105, 99, 82, 101, 110, 100, 101, 114, 62, 114, 101, 113, 117, 105, 114, 101, 100, 60, 47, 100, 121, 110, 97, 109, 105, 99, 82, 101, 110, 100, 101, 114, 62, 10, 32, 32, 60, 47, 97, 99, 114, 111, 98, 97, 116, 55, 62, 10, 32, 32, 60, 118, 97, 108, 105, 100, 97, 116, 101, 62, 112, 114, 101, 83, 117, 98, 109, 105, 116, 60, 47, 118, 97, 108, 105, 100, 97, 116, 101, 62, 10, 60, 47, 97, 99, 114, 111, 98, 97, 116, 62, 10, 60, 47, 99, 111, 110, 102, 105, 103, 62, 10}, + })) + }) + + It("returns an error when requesting an incorrect XFA packet content", func() { + FPDF_GetXFAPacketContent, err := PdfiumInstance.FPDF_GetXFAPacketContent(&requests.FPDF_GetXFAPacketContent{ + Document: doc, + Index: 25, + }) + Expect(err).To(MatchError("could not get content of the XFA packet")) + Expect(FPDF_GetXFAPacketContent).To(BeNil()) + }) + }) + }) + + Context("a normal PDF file with multiple pages", func() { + var doc references.FPDF_DOCUMENT + var file *os.File + + BeforeEach(func() { + pdfFile, err := os.Open(TestDataPath + "/testdata/viewer_ref.pdf") + Expect(err).To(BeNil()) + + file = pdfFile + fileStat, err := file.Stat() + Expect(err).To(BeNil()) + + newDoc, err := PdfiumInstance.FPDF_LoadCustomDocument(&requests.FPDF_LoadCustomDocument{ + Reader: file, + Size: fileStat.Size(), + }) + Expect(err).To(BeNil()) + + doc = newDoc.Document + }) + + AfterEach(func() { + FPDF_CloseDocument, err := PdfiumInstance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_CloseDocument).To(Not(BeNil())) + file.Close() + }) + + When("is opened", func() { + It("returns the correct print duplex", func() { + FPDF_VIEWERREF_GetDuplex, err := PdfiumInstance.FPDF_VIEWERREF_GetDuplex(&requests.FPDF_VIEWERREF_GetDuplex{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetDuplex).To(Equal(&responses.FPDF_VIEWERREF_GetDuplex{ + DuplexType: enums.FPDF_DUPLEXTYPE_UNDEFINED, + })) + }) + + It("returns an error when requesting an invalid viewer ref name", func() { + FPDF_VIEWERREF_GetName, err := PdfiumInstance.FPDF_VIEWERREF_GetName(&requests.FPDF_VIEWERREF_GetName{ + Document: doc, + Key: "foo", + }) + Expect(err).To(MatchError("could not get name")) + Expect(FPDF_VIEWERREF_GetName).To(BeNil()) + }) + + It("returns the viewer ref name", func() { + FPDF_VIEWERREF_GetName, err := PdfiumInstance.FPDF_VIEWERREF_GetName(&requests.FPDF_VIEWERREF_GetName{ + Document: doc, + Key: "Direction", + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetName).To(Equal(&responses.FPDF_VIEWERREF_GetName{ + Value: "R2L", + })) + }) + + When("a print page range has been loaded", func() { + var pageRange references.FPDF_PAGERANGE + BeforeEach(func() { + FPDF_VIEWERREF_GetPrintPageRange, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRange(&requests.FPDF_VIEWERREF_GetPrintPageRange{ + Document: doc, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetPrintPageRange).To(Not(BeNil())) + pageRange = FPDF_VIEWERREF_GetPrintPageRange.PageRange + }) + + It("returns the correct print page range count", func() { + FPDF_VIEWERREF_GetPrintPageRangeCount, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRangeCount(&requests.FPDF_VIEWERREF_GetPrintPageRangeCount{ + PageRange: pageRange, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetPrintPageRangeCount).To(Equal(&responses.FPDF_VIEWERREF_GetPrintPageRangeCount{ + Count: 4, + })) + }) + + It("returns an error when requesting an invalid print page range element", func() { + FPDF_VIEWERREF_GetPrintPageRangeElement, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRangeElement(&requests.FPDF_VIEWERREF_GetPrintPageRangeElement{ + PageRange: pageRange, + Index: 25, + }) + Expect(err).To(MatchError("could not load page range element")) + Expect(FPDF_VIEWERREF_GetPrintPageRangeElement).To(BeNil()) + }) + + It("returns the correct print page range element", func() { + FPDF_VIEWERREF_GetPrintPageRangeElement, err := PdfiumInstance.FPDF_VIEWERREF_GetPrintPageRangeElement(&requests.FPDF_VIEWERREF_GetPrintPageRangeElement{ + PageRange: pageRange, + Index: 1, + }) + Expect(err).To(BeNil()) + Expect(FPDF_VIEWERREF_GetPrintPageRangeElement).To(Equal(&responses.FPDF_VIEWERREF_GetPrintPageRangeElement{ + Value: 2, + })) + }) + }) }) }) diff --git a/shared_tests/testdata/bug_664284.pdf b/shared_tests/testdata/bug_664284.pdf new file mode 100644 index 0000000000000000000000000000000000000000..126938a4c8367407154a16d4754d7c242f18e951 GIT binary patch literal 20874 zcmeI4&rTaL5XSF*in*-R9?JfK-4H24f`q72X&Z%AFNnj2ICN21N6totK1~mOf~rpd zFV-3Fnn36whf3+;ixMg8wZ}7`{r%*VgVA94F5c^?;Ni#PuZN$Hzg0{TnaK_HdWtB_ z?-!cFeo+^5b1e;{;#w~$;Z9?D{8H*~+K#NAX{)O%e&xpTo1rlj&Wzz+{Pez@>fD(5 zq_9-mm2O%GrPWt;X(|fG$yw7T5s$4dcvfo`C+4nc{# z(yZ*u`uTmY7Y<{JQ<;tvc8R;Bs+xy$Hi^hRzLbz3^|UOwUb=|5EsGQCbQAaHxT=hF z?smIP?{)0~4Gqs@+v)d|n`<*`=_6B|uO_uyP+3-|$w{%)E<$*0%VPdQjy{i)B4@_Z zLZo3$T)yk@XS%wszfvUQmNl>1tvbn-)SN_=&r}?7CH%_=^hVT;-{v>!G?$fYySHl? zP+MeSZE>%fN@X5duf&zDE}s@$p4UkX^s=V?jz}X#He1$(dsdEn?*qn8^>sk^ybjnz zkbEV;9dB+G5tkAv{uobh> z&+Qm!h5Z80I4gh~U?P~#U`fEVBec%e}MUVsyc=*n01vyaM0>cmN)FH{g5#9)Jhn0eIjQ01v Date: Sun, 6 Feb 2022 20:13:33 +0100 Subject: [PATCH 6/6] Properly skip --- shared_tests/fpdfview.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shared_tests/fpdfview.go b/shared_tests/fpdfview.go index 011b1510..93cdf387 100644 --- a/shared_tests/fpdfview.go +++ b/shared_tests/fpdfview.go @@ -848,12 +848,13 @@ var _ = Describe("fpdfview", func() { }) When("an external bitmap has been created", func() { - if TestType == "multi" { - Skip("External bitmap is not supported on multi-threaded usage") - } var bitmap references.FPDF_BITMAP var buffer []byte BeforeEach(func() { + if TestType == "multi" { + Skip("External bitmap is not supported on multi-threaded usage") + } + buffer = make([]byte, (1000*4)*1000) // 1000 pixels in width * 4 bytes per pixel * 1000 pixels in height FPDFBitmap_CreateEx, err := PdfiumInstance.FPDFBitmap_CreateEx(&requests.FPDFBitmap_CreateEx{ @@ -869,6 +870,10 @@ var _ = Describe("fpdfview", func() { }) AfterEach(func() { + if TestType == "multi" { + Skip("External bitmap is not supported on multi-threaded usage") + } + FPDFBitmap_Destroy, err := PdfiumInstance.FPDFBitmap_Destroy(&requests.FPDFBitmap_Destroy{ Bitmap: bitmap, })