This Elm module contains the necessary machinery for communicating with javascript, where the actual pdf wrangling will take place. Use the Cmds to open and close documents, listen for Msgs indicating the Cmd results, and display the document pages with pdfPage.
Specify the size of the pdf document. If you specify height or width, the scale will be computed to fit.
PdfCmds go from from elm out to javascript to be processed. Each pdf document should have a unique name. You can make multiple pdfPage controls that reference a single pdf document.
PdfMsgs are responses from javascript to elm after PdfCmd operations. The name should be the same string you used in OpenUrl or OpenString.
make a subscription function with receive and a port, like so:
port receivePdfMsg : (JD.Value -> msg) -> Sub msg
pdfreceive : Sub Msg
pdfreceive =
receivePdfMsg <| PdfElement.receive PdfMsgWhere PdfMessage is defined in your app like this:
type Msg
= PdfMsg (Result JD.Error PdfElement.PdfMsg)
| <other message types>then in your application subscriptions:
subscriptions =
\_ -> pdfreceiveuse send to make a websocket convenience function, like so:
port sendPdfCommand : JE.Value -> Cmd msg
pdfsend =
PdfElement.send sendPdfCommandthen you can call (makes a Cmd):
pdfsend <|
PdfElement.OpenString
{ name = "mypdf"
, string = dta
}
pdfPage makes a 'custom element' that displays the pdf for the document indicated by 'name'. Before calling this function, you should open the document with a PdfCmd and wait for a Loaded msg.