espresso3389/pdfrx

Large Size Contribution of pdfrx Framework in iOS Build

Opened this issue · 3 comments

Hello,

First of all, thank you for this great plugin and for the effort you’ve put into maintaining it!

I’ve noticed that the pdfrx.framework contributes significantly to the size of my iOS app bundle (approximately 5 MB), making it one of the largest dependencies in my project.

image

Is there any way to optimize the framework’s size? Any guidance or recommendations would be greatly appreciated.

Currently, pdfrx uses only a part of pdfium and we can "potentially" remove unused functions.
But I didn't try it and don't know how much I can reduce the total size anyway.

The key is the table defined here.

I'm just grepped pdfrx_pdfium.dart with pdfium.FPDF[^(]+ and it lists the following functions actually used so far:

FPDF_InitLibraryWithConfig
FPDF_LoadDocument
FPDF_LoadMemDocument
FPDF_LoadCustomDocument
FPDF_GetLastError
FPDF_GetLastError
FPDF_GetPageCount
FPDF_GetDocPermissions
FPDF_GetSecurityHandlerRevision
FPDFDOC_InitFormFillEnvironment
FPDF_LoadPage
FPDF_GetPageWidthF
FPDF_GetPageHeightF
FPDFPage_GetRotation
FPDF_ClosePage
FPDFDOC_ExitFormFillEnvironment
FPDFDOC_ExitFormFillEnvironment
FPDF_CloseDocument
FPDFBookmark_GetFirstChild
FPDFBookmark_GetTitle
FPDFBookmark_GetTitle
FPDFBookmark_GetDest
FPDFBookmark_GetFirstChild
FPDFBookmark_GetNextSibling
FPDFBitmap_CreateEx
FPDF_LoadPage
FPDFBitmap_FillRect
FPDF_RenderPageBitmap
FPDF_FFLDraw
FPDF_ClosePage
FPDFBitmap_Destroy
FPDF_LoadPage
FPDFText_LoadPage
FPDFLink_LoadWebLinks
FPDFLink_CountWebLinks
FPDFLink_CountRects
FPDFLink_GetRect
FPDFLink_CloseWebLinks
FPDFText_ClosePage
FPDF_ClosePage
FPDFLink_GetURL
FPDFLink_GetURL
FPDF_LoadPage
FPDFPage_GetAnnotCount
FPDFPage_GetAnnot
FPDFAnnot_GetRect
FPDFPage_CloseAnnot
FPDF_ClosePage
FPDFAnnot_GetLink
FPDFLink_GetDest
FPDFLink_GetAction
FPDFAction_GetType
FPDFAction_GetDest
FPDFAnnot_GetLink
FPDFLink_GetAction
FPDFAction_GetType
FPDFAction_GetURIPath
FPDFAction_GetURIPath
FPDF_LoadPage
FPDFText_LoadPage
FPDFText_CountChars
FPDFText_ClosePage
FPDF_ClosePage
FPDFText_GetCharBox
FPDFText_GetText
FPDFDest_GetDestPageIndex
FPDFDest_GetView

I'll test how much we can reduce the size by referencing only these functions.

Contrary to my expectations, the result is not so good; 5051528 -> 5000904. It does not reduce the size...
So, it's too hard to reduce the binary size... pdfium itself is large.

The other way to reduce the total size of pdfrx is to replace pdfium with CGPDFDocument. But is's hard way. I should rewrite almost all pdfium related code for iOS/macOS...