This thread is a compilation of common How to... questions in order to hopefully assist answering some frequently asked questions and explanations
Embedded 2.0
How do I render a small section of a PDF only in Embedded 2.0?
For example:
a. Given that you want to render a small section of a PDF page that is 595 width by 842 height
b. Given that the small section you want to render is a rectangle that is defined (left =85, top=764, right = 250, bottom=689)
c. The bitmap FS_BITMAP was created with the size that matches the rectangle (width = right-left=165, height=top-bottom=75).
d. FPDF_Page has been loaded
e. FPDF_Document has been loaded.
User would make the following call:
1. FPDF_RenderPage_Start(dib, page,-85,-764,165,75, rotate, flags, rectangle, pause)
The reason the start x and start y value are negative is because the render function must start off the bitmap and not on the top left corner of the bitmap. By starting to render off the bitmap of -85 and -764, it will adjust the rendering so that the small section defined by the rectangle.
The same logic applies to Foxit PDF SDK DLL and WinRT. However, the API may differ.
How do I get link data with Embedded 2.0?
1. Call FPDF_Annot_GetLinkCount to get the numbers of links on the page so when you call FPDF_Annot_GetLink you do not go out of bounds.
2. Call FPDF_Annot_GetLink to get a FPDF_ANNOT to a specific link handle
3. Get the user touch location and send to FPDF_Page_DeviceToPageRectF
4. Call FPDF_Annot_GetLinkArea compare you link to the user touch location, if location is within the link's rectangle proceed with the following steps, else quit
5. Call FPDF_Annot_GetLinkAction to get its Action
6. Call FPDF_Action_GetType to get the type and size of the Action type
7. Alloc memory for the buffer
8. Call FPDF_Action_GetData to get the Action information to store to the buffer
9. Reader buffer data and use it accordingly.
External website links are FPDF_URLDEST.
Page actions are FPDF_DOCDEST.
Both FPDF_URLDEST and FPDF_DOCDEST are structure that contains the link information.
How do I work with bookmarks in Embedded 2.0?
1. Call FPDF_Bookmark_GetFirstChild to get the handle of the first Bookmark.
2. Call FPDF_Bookmark_GetTitle to get its title
3. Call FPDF_Bookmark_GetPage the page index it is pointing to.
4. If the bookmark is not pointing to a page, it may have some other action. If so, use FPDF_Bookmark_GetAction to get the handle to the bookmark action and proceed to step 5, else skip to step 7.
5. Call FPDF_Action_GetType to figure out what type that bookmark is and proceed to step 6.
6. Call FPDF_Action_GetData to get the action information, for example, if it's and External URL, it will provide the URL.
7. Call FPDF_Bookmark_GetNextSibling to get the handle of the next bookmark.
8. Repeat steps 2-4 to get all information about the other bookmarks.
9. Once completed, you can store this information for later use. Like when you compose a bookmark navigation panel.
How do I do Text Selection or Highlighting in Embedded 2.0?
a. Get the user touch down and touch up coordinates
b. Translate those coordinates to PDF coordinates using FPDF_Page_DeviceToPagePoint
c. Call FPDF_Text_CountChars to parse the page.
d. Call FPDF_Text_GetCharIndexAtPos to get the index of the touch down and touch up characters
e. Call FPDF_Text_GetText to get the selected text.
Here you can copy the text.
If you want to get the rectangle to do highlighting, you must proceed with the following.
f. Call FPDF_Text_CountRects to get count of rectangles needed.
g. Call FPDF_Text_GetRect to get the rectangles.
h. From here you can use the rectangle to do highlighting
How to support CJK fonts files?
a. Try loading the supported font files first if the PDF is not rendering the fonts correctly. The interface can be found in fs_base.h and the naming convention is FS_FontCMap_LoadXXXX. ie. FS_FontCMap_LoadCNS, FS_FontCMap_LoadJapan, FS_FontCMap_LoadKorea.
b. Define the FS_FONT_FILE_MAPPER. Note: it will provide the charset info, you will need to map it accordingly to what the charset returns. For example, if charset==FS_CHARSET_JIS then path=the font file path.
c. Call FS_Font_SetFontFileMapper set the defined FS_FONT_FILE_MAPPER
Embedded 2.0
How do I render a small section of a PDF only in Embedded 2.0?
For example:
a. Given that you want to render a small section of a PDF page that is 595 width by 842 height
b. Given that the small section you want to render is a rectangle that is defined (left =85, top=764, right = 250, bottom=689)
c. The bitmap FS_BITMAP was created with the size that matches the rectangle (width = right-left=165, height=top-bottom=75).
d. FPDF_Page has been loaded
e. FPDF_Document has been loaded.
User would make the following call:
1. FPDF_RenderPage_Start(dib, page,-85,-764,165,75, rotate, flags, rectangle, pause)
The reason the start x and start y value are negative is because the render function must start off the bitmap and not on the top left corner of the bitmap. By starting to render off the bitmap of -85 and -764, it will adjust the rendering so that the small section defined by the rectangle.
The same logic applies to Foxit PDF SDK DLL and WinRT. However, the API may differ.
How do I get link data with Embedded 2.0?
1. Call FPDF_Annot_GetLinkCount to get the numbers of links on the page so when you call FPDF_Annot_GetLink you do not go out of bounds.
2. Call FPDF_Annot_GetLink to get a FPDF_ANNOT to a specific link handle
3. Get the user touch location and send to FPDF_Page_DeviceToPageRectF
4. Call FPDF_Annot_GetLinkArea compare you link to the user touch location, if location is within the link's rectangle proceed with the following steps, else quit
5. Call FPDF_Annot_GetLinkAction to get its Action
6. Call FPDF_Action_GetType to get the type and size of the Action type
7. Alloc memory for the buffer
8. Call FPDF_Action_GetData to get the Action information to store to the buffer
9. Reader buffer data and use it accordingly.
External website links are FPDF_URLDEST.
Page actions are FPDF_DOCDEST.
Both FPDF_URLDEST and FPDF_DOCDEST are structure that contains the link information.
How do I work with bookmarks in Embedded 2.0?
1. Call FPDF_Bookmark_GetFirstChild to get the handle of the first Bookmark.
2. Call FPDF_Bookmark_GetTitle to get its title
3. Call FPDF_Bookmark_GetPage the page index it is pointing to.
4. If the bookmark is not pointing to a page, it may have some other action. If so, use FPDF_Bookmark_GetAction to get the handle to the bookmark action and proceed to step 5, else skip to step 7.
5. Call FPDF_Action_GetType to figure out what type that bookmark is and proceed to step 6.
6. Call FPDF_Action_GetData to get the action information, for example, if it's and External URL, it will provide the URL.
7. Call FPDF_Bookmark_GetNextSibling to get the handle of the next bookmark.
8. Repeat steps 2-4 to get all information about the other bookmarks.
9. Once completed, you can store this information for later use. Like when you compose a bookmark navigation panel.
How do I do Text Selection or Highlighting in Embedded 2.0?
a. Get the user touch down and touch up coordinates
b. Translate those coordinates to PDF coordinates using FPDF_Page_DeviceToPagePoint
c. Call FPDF_Text_CountChars to parse the page.
d. Call FPDF_Text_GetCharIndexAtPos to get the index of the touch down and touch up characters
e. Call FPDF_Text_GetText to get the selected text.
Here you can copy the text.
If you want to get the rectangle to do highlighting, you must proceed with the following.
f. Call FPDF_Text_CountRects to get count of rectangles needed.
g. Call FPDF_Text_GetRect to get the rectangles.
h. From here you can use the rectangle to do highlighting
How to support CJK fonts files?
a. Try loading the supported font files first if the PDF is not rendering the fonts correctly. The interface can be found in fs_base.h and the naming convention is FS_FontCMap_LoadXXXX. ie. FS_FontCMap_LoadCNS, FS_FontCMap_LoadJapan, FS_FontCMap_LoadKorea.
b. Define the FS_FONT_FILE_MAPPER. Note: it will provide the charset info, you will need to map it accordingly to what the charset returns. For example, if charset==FS_CHARSET_JIS then path=the font file path.
c. Call FS_Font_SetFontFileMapper set the defined FS_FONT_FILE_MAPPER
Comment