Announcement

Collapse
No announcement yet.

How to... with Embedded PDF SDK

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts

  • How to... with Embedded PDF SDK

    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

  • #2
    Android Embedded SDK
    How do I fix scrolling encounter memory problem in Android scrolling demo?

    Make the following changes in examples\demos\demo_view_scrolling\src\com\foxitsa mple\view_scrolling\PDFView.java ->SetMartix

    public void SetMartix(float CurrentoffsetX,float CurrentoffsetY)
    {
    nStartX = nCurDisplayX - (int)CurrentoffsetX;
    nStartY = nCurDisplayY - (int)CurrentoffsetY;
    if(nStartX < 0) nStartX = 0;
    if(nStartX > (m_map.getWidth() - nDisplayX)) nStartX = (int) (m_map.getWidth() - nDisplayX);
    if(nStartY < 0) nStartY = 0;
    if(nStartY > (m_map.getHeight() - nDisplayY)) nStartY = (int) (m_map.getHeight() - nDisplayY);
    nCurDisplayX = nStartX;
    nCurDisplayY = nStartY;
    scrollTo(nStartX,nStartY);
    //CurrentBitmap = Bitmap.createBitmap(m_map, nStartX, nStartY,m_map.getWidth() - nStartX, m_map.getHeight()- nStartY);
    }

    How can I Android Embedded SDK support PDF in a buffer?

    The file access is handled by the JNI layer in the Foxit Demo. Attach is the JNI layer that support reading PDF file to buffer.
    See the following:

    void FileAccessHelper(void* fileAccessHandle, void* user)
    {
    struct FPDFEMB_FILE_ACCESS fileaccess;
    memcpy(&fileaccess, fileAccessHandle,sizeof(fileaccess));
    fileaccess.GetSize = File_GetSize;
    fileaccess.ReadBlock = File_ReadBlock;
    fileaccess.user = user;
    memcpy(fileAccessHandle, &fileaccess, sizeof(fileaccess));
    }


    void BufAccessHelper(void* bufaccesshandle, void* buffer, unsigned int buffer_size)
    {
    struct user_data bufaccess;
    memcpy(&bufaccess,bufaccesshandle,sizeof(bufaccess ));
    bufaccess.buffer=buffer;
    bufaccess.buffer_size=buffer_size;
    memcpy(bufaccesshandle, &bufaccess, sizeof(bufaccess));
    }


    How can I set Android background transparency?

    Application should convert FPDFEMB_BITMAP(after FPDFEMB_StartRender) to Android Bitmap like this,

    unsigned char* pBuf = pixels;
    int row;
    int col;
    unsigned char alpha = 0;
    for (row = 0; row < info.height; row ++)
    {
    pBuf = (unsigned char*)pixels + info.stride * row;
    for (col = 0; col < info.width; col ++)
    {
    alpha = pBuf[3];
    pBuf[0] = (pBuf[0] * alpha) / 0xff; //multiply the alpha to color channel
    pBuf[1] = (pBuf[0] * alpha) / 0xff;
    pBuf[2] = (pBuf[0] * alpha) / 0xff;
    pBuf += 4;
    }
    }

    I'm getting multiple definition errors when building the Android demo library with ndk-build -B.

    If you receive the following error ../bin/libfpdfemb_android.a(dll_main.o): multiple definition of 'std::exception::exception()' when building the JNI layer with ndk-build -B
    Please try the following.

    1. Locate Application.mk. For the annotation demo it can be found here
    "examples\demos\demo\jni\Application.mk" Each demo has its own Application.mk
    2. Change the following line "APP_STL := stlport_static" to "APP_STL := stlport_shared"
    3. Locate the EMBJavaSupport.java. For the annotation demo it is located at "examples\demos\demo_annotations\src\FoxitEMBS DK\E MBJavaSupport.java"
    4. Locate

    static{
    System.loadLibrary("fpdfembedsdk");
    }

    And add the following line System.loadLibrary("stlport_shared");
    For example, it should look like this:

    static{
    System.loadLibrary("stlport_shared");
    System.loadLibrary("fpdfembedsdk");
    }

    Comment


    • #3
      Windows RT Embedded SDK
      How do I print in the Windows Store App?

      Foxit does not have a sample of how to print. However, Foxit Render PDF can render it to a bitmap. Windows Store provides a Printing API, which you can use to print bitmap.

      If you go to FoxitEmbeddedPDFSDK\Samples\CSharp\demos\demo_view \demo_view\BasicPage.xaml.cs you can see that there is a link where a bitmap is created and is rendered to. (ie. View.RenderPageAsync(bitmap, page, 0, 0, nWidth, nHeight, m_iRotateFlag, (int)(Foxit.General.RenderFlags.Annot | Foxit.General.RenderFlags.LCDText), null)

      Microsoft provides some sample code of how to print a bitmap. Please go to http://code.msdn.microsoft.com/windo...thId=298223712

      Look at the source for ScenarioInput6.xaml.cs

      How can Embedded SDK for Windows RT support thumbnails?

      Thumbnails are handled by rendering images as small images.
      Foxit::General::PDF::View::StartRender (PixelSource^ dib, PageHandle page, int32 start_x, int32 start_y, int32 size_x, int32 size_y, int32 rotate, int32 flags, RectI^ clip, Pause^ pause)

      The parameter size_x and size_y is where you can define the size.

      How do I work with link annotations on Embedded SDK for Windows RT?

      Here is the workflow to get annotations links when it is clicked.
      1. Call Foxit::General::PDF::Annot::GetLinkCount to check if Annotations links are present.
      2. If annotations are present, call Foxit::General::PDF::Annot::GetLink to get the AnnotHandle
      3. Call Foxit::General::PDF::Annot::GetLinkAreaCount to get count of the area
      4. Call Foxit::General::PDF::Annot::GetLinkArea to get the AnnotQuad
      5. Compare the AnnotQuad with the user coordinate selection (remember to use Foxit::General::PDF::View::TransformPointFromDevic eToPage to confirm device to PDF page point).
      6. If point is not within the quadrilateral(quad) repeat step 2-5 to see if point exist. If the point does not exist at all, ignore it. Application can also store quadrilateral data with it being associated with Annotation data.
      If point is within the quadrilateral proceed to step 7.
      7. Call Foxit::General::PDF::Annot::GetLinkAction
      8. Call Foxit::General::PDF:: Document::GetActionType to check if the action type is a Foxit::General::PageDest
      9. If it is call Foxit::General::PDFocument::GetActionData to get its data.
      10. Use the structure of PageDest to render the page with its zoom level.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎