diff --git a/.vscode/settings.json b/.vscode/settings.json index 97714d5..13498c2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { "basexTools.xquery.profile": "basex-10", - "basexTools.xquery.showHovers": "false", + "basexTools.xquery.showHovers": false, } \ No newline at end of file diff --git a/docs/pdfbox.xqbk b/docs/pdfbox.xqbk index 9fbb506..9ae5918 100644 --- a/docs/pdfbox.xqbk +++ b/docs/pdfbox.xqbk @@ -1 +1 @@ -{"cells":[{"kind":1,"language":"markdown","value":"# PDFBox3 \r\nA BaseX 10+ interface to Apache PDFBox® library version 3 \r\n## Apache PDFBox® - A Java PDF Library\r\n\r\nThe Apache PDFBox® library is an open source Java tool for working with PDF documents. This project allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents. Apache PDFBox also includes several command-line utilities. Apache PDFBox is published under the Apache License v2.0.\r\nhttps://pdfbox.apache.org/"},{"kind":1,"language":"markdown","value":"It comes with the useful PDF debug tool `java -jar debugger-app-3.0.1.jar`"},{"kind":1,"language":"markdown","value":"## Set up XQuery context for following code..."},{"kind":2,"language":"xquery","value":"(:<:)(: XQuery Context :)\r\nimport module namespace pdfbox = \"urn:expkg-zone58:pdfbox3\" at \"../src/lib/pdfbox3.xqm\";\r\nimport module namespace bookpages = 'urn:bookpages' at \"../src/lib/bookpages.xqm\";\r\nimport module namespace config = 'urn:abc-clio:config' at 'C:\\Users\\mrwhe\\git\\bloomsbury\\content-architecture\\xquery\\ABC-CLIO/lib/abc-config.xqm';\r\n\r\ndeclare variable $samples:= map{\r\n \"climate\": \"drop-01d\\set\\2-6-1\\A5579C_1\\271989---Book_File-Web_PDF_9798400627484_486728.pdf\",\r\n \"women\": \"drop-01d\\set\\2-6-1\\A6229C_1\\257334---Book_File-Web_PDF_9798216172628_486742.pdf\",\r\n \"genocide\": \"drop1-pdf\\GR2967-TRD\\272791---Book_File-Web_PDF_9798400640216_486366.pdf\",\r\n \"world\": \"drop-01c\\gpg-book\\2-6\\A3506C-TRD\\256186---Book_File-Web_PDF_9798216038955_486148.pdf\"\r\n};\r\ndeclare variable $PDF:= (: $samples?women=>file:resolve-path($config:data) :)\r\n\"C:\\Users\\mrwhe\\git\\bloomsbury\\content-architecture\\xquery\\ABC-CLIO\\data\\drop-01e\\set\\2-6-1\\A5690C_1\\257107---Book_File-Web_PDF_9798400691218_486731.pdf\";"},{"kind":1,"language":"markdown","value":"# Version"},{"kind":1,"language":"markdown","value":" ## pdfbox version"},{"kind":2,"language":"xquery","value":"pdfbox:version()"},{"kind":1,"language":"markdown","value":"PDF specification version used by document"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:pdfVersion()"},{"kind":1,"language":"markdown","value":"# Page count for PDF"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:page-count()"},{"kind":1,"language":"markdown","value":"## save range to new pdf"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:extract(2,12,\"c:\\tmp\\a.pdf\")"},{"kind":1,"language":"markdown","value":"## Outline / bookmarks"},{"kind":1,"language":"markdown","value":"### sequence of maps"},{"kind":2,"language":"xquery","value":"\r\npdfbox:open($PDF)=>pdfbox:outline()"},{"kind":1,"language":"markdown","value":"XML"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:outline()=>pdfbox:outline-xml()"},{"kind":1,"language":"markdown","value":"## Page labels"},{"kind":2,"language":"xquery","value":"\r\npdfbox:open($PDF)=>pdfbox:getPageLabels()"},{"kind":1,"language":"markdown","value":"# getText from page index"},{"kind":2,"language":"xquery","value":"let $doc:=pdfbox:open($PDF)\r\nreturn pdfbox:getText($doc,56)"},{"kind":1,"language":"markdown","value":"## PageNo text analysis"},{"kind":2,"language":"xquery","value":"let $doc:=pdfbox:open($PDF)\r\nreturn pagenos:page-report($doc)\r\n"},{"kind":1,"language":"markdown","value":"# Inverted pageno map"},{"kind":2,"language":"xquery","value":"let $doc:=pdfbox:open($PDF)\r\nreturn pagenos:page-report($doc)=>pagenos:inverted-map()"},{"kind":1,"language":"markdown","value":"## report"},{"kind":2,"language":"xquery","value":"declare variable $a:=file:resolve-path(\"../data/1e/\",file:base-dir());\r\n\r\nfor $f in file:list($a,true(),\"*.pdf\") \r\nwhere not(contains($f,\"outputs\"))\r\nlet $doc:=pdfbox:open(file:resolve-path($f,$a))\r\n(: let $outline:=pdfbox:outline($doc) :)\r\nlet $count:=pdfbox:page-count($doc)\r\norder by $count \r\nreturn ``[`{$f}`: `{ $count }`]``"}]} \ No newline at end of file +{"cells":[{"kind":1,"language":"markdown","value":"# PDFBox3 \r\nA BaseX 10+ interface to Apache PDFBox® library version 3 \r\n## Apache PDFBox® - A Java PDF Library\r\n\r\nThe Apache PDFBox® library is an open source Java tool for working with PDF documents. This project allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents. Apache PDFBox also includes several command-line utilities. Apache PDFBox is published under the Apache License v2.0.\r\nhttps://pdfbox.apache.org/"},{"kind":1,"language":"markdown","value":"It comes with the useful PDF debug tool `java -jar debugger-app-3.0.1.jar`"},{"kind":1,"language":"markdown","value":"## Set up XQuery context for following code..."},{"kind":2,"language":"xquery","value":"(:<:)(: XQuery Context :)\r\nimport module namespace pdfbox = \"urn:expkg-zone58:pdfbox3\" at \"../src/lib/pdfbox3.xqm\";\r\nimport module namespace bookpages = 'urn:bookpages' at \"../src/lib/bookpages.xqm\";\r\nimport module namespace config = 'urn:abc-clio:config' at 'C:\\Users\\mrwhe\\git\\bloomsbury\\content-architecture\\xquery\\ABC-CLIO/lib/abc-config.xqm';\r\n\r\ndeclare variable $samples:= map{\r\n \"climate\": \"drop-01d\\set\\2-6-1\\A5579C_1\\271989---Book_File-Web_PDF_9798400627484_486728.pdf\",\r\n \"women\": \"drop-01d\\set\\2-6-1\\A6229C_1\\257334---Book_File-Web_PDF_9798216172628_486742.pdf\",\r\n \"genocide\": \"drop1-pdf\\GR2967-TRD\\272791---Book_File-Web_PDF_9798400640216_486366.pdf\",\r\n \"world\": \"drop-01c\\gpg-book\\2-6\\A3506C-TRD\\256186---Book_File-Web_PDF_9798216038955_486148.pdf\"\r\n};\r\ndeclare variable $PDF:= (: $samples?women=>file:resolve-path($config:data) :)\r\n\"C:\\Users\\mrwhe\\git\\bloomsbury\\content-architecture\\xquery\\ABC-CLIO\\data\\drop-01e\\set\\2-6-1\\A5690C_1\\257107---Book_File-Web_PDF_9798400691218_486731.pdf\";"},{"kind":1,"language":"markdown","value":"# Version"},{"kind":1,"language":"markdown","value":" ## pdfbox version"},{"kind":2,"language":"xquery","value":"pdfbox:version()"},{"kind":1,"language":"markdown","value":"PDF specification version used by document"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:pdfVersion()"},{"kind":1,"language":"markdown","value":"# Page count for PDF"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:page-count()"},{"kind":1,"language":"markdown","value":"## save range to new pdf"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:extract(2,12,\"c:\\tmp\\a.pdf\")"},{"kind":1,"language":"markdown","value":"## Outline / bookmarks"},{"kind":1,"language":"markdown","value":"### sequence of maps"},{"kind":2,"language":"xquery","value":"\r\npdfbox:open($PDF)=>pdfbox:outline()"},{"kind":1,"language":"markdown","value":"XML"},{"kind":2,"language":"xquery","value":"pdfbox:open($PDF)=>pdfbox:outline()=>pdfbox:outline-xml()"},{"kind":1,"language":"markdown","value":"## Page labels"},{"kind":2,"language":"xquery","value":"\r\npdfbox:open($PDF)=>pdfbox:pageLabels()"},{"kind":1,"language":"markdown","value":"# getText from page index"},{"kind":2,"language":"xquery","value":"let $doc:=pdfbox:open($PDF)\r\nreturn pdfbox:getText($doc,56)"},{"kind":1,"language":"markdown","value":"## PageNo text analysis"},{"kind":2,"language":"xquery","value":"let $doc:=pdfbox:open($PDF)\r\nreturn pagenos:page-report($doc)\r\n"},{"kind":1,"language":"markdown","value":"# Inverted pageno map"},{"kind":2,"language":"xquery","value":"let $doc:=pdfbox:open($PDF)\r\nreturn pagenos:page-report($doc)=>pagenos:inverted-map()"},{"kind":1,"language":"markdown","value":"## report"},{"kind":2,"language":"xquery","value":"declare variable $a:=file:resolve-path(\"../data/1e/\",file:base-dir());\r\n\r\nfor $f in file:list($a,true(),\"*.pdf\") \r\nwhere not(contains($f,\"outputs\"))\r\nlet $doc:=pdfbox:open(file:resolve-path($f,$a))\r\n(: let $outline:=pdfbox:outline($doc) :)\r\nlet $count:=pdfbox:page-count($doc)\r\norder by $count \r\nreturn ``[`{$f}`: `{ $count }`]``"}]} \ No newline at end of file diff --git a/samples.pdf/icelandic-dictionary.pdf b/samples.pdf/icelandic-dictionary.pdf new file mode 100644 index 0000000..85c4114 Binary files /dev/null and b/samples.pdf/icelandic-dictionary.pdf differ diff --git a/samples.pdf/page-numbers.pdf b/samples.pdf/page-numbers.pdf new file mode 100644 index 0000000..e17e69b Binary files /dev/null and b/samples.pdf/page-numbers.pdf differ diff --git a/samples.pdf/readme.md b/samples.pdf/readme.md new file mode 100644 index 0000000..b33483d --- /dev/null +++ b/samples.pdf/readme.md @@ -0,0 +1 @@ +Examples with pageLabels and outlines \ No newline at end of file diff --git a/src/lib/pdfbox3.xqm b/src/lib/pdfbox3.xqm index 5702198..9a26b6b 100644 --- a/src/lib/pdfbox3.xqm +++ b/src/lib/pdfbox3.xqm @@ -3,8 +3,8 @@ xquery version '3.1'; pdfbox 3.0 https://pdfbox.apache.org/ BaseX 10.7+ interface library, requires pdfbox jar on classpath 3.02+ required tested with pdfbox-app-3.0.2.jar -@see https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.2-SNAPSHOT/ -@javadoc https://javadoc.io/static/org.apache.pdfbox/pdfbox/3.0.0/ +@see download https://pdfbox.apache.org/download.cgi +@javadoc https://javadoc.io/static/org.apache.pdfbox/pdfbox/3.0.2/ :) module namespace pdfbox="urn:expkg-zone58:pdfbox3"; @@ -31,11 +31,11 @@ declare namespace PageExtractor ="java:org.apache.pdfbox.multipdf.PageExtractor" declare namespace PDPageTree ="java:org.apache.pdfbox.pdmodel.PDPageTree"; (:~ -@see https://javadoc.io/static/org.apache.pdfbox/pdfbox/3.0.0/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDDocumentOutline.html +@see https://javadoc.io/static/org.apache.pdfbox/pdfbox/3.0.2/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDDocumentOutline.html :) declare namespace PDDocumentOutline ="java:org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline"; - +declare namespace PDDocumentInformation ="java:org.apache.pdfbox.pdmodel.PDDocumentInformation"; (:~ @see https://javadoc.io/static/org.apache.pdfbox/pdfbox/3.0.0/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.html :) @@ -80,26 +80,53 @@ as xs:integer{ PDDocument:getNumberOfPages($doc) }; +(:~ map with document metadata :) +declare function pdfbox:information($doc as item()) +as map(*){ + let $info:=PDDocument:getDocumentInformation($doc) + return map{ + "title": PDDocumentInformation:getTitle($info), + "creator": PDDocumentInformation:getCreator($info), + "producer": PDDocumentInformation:getProducer($info), + "subject": PDDocumentInformation:getSubject($info), + "keywords": PDDocumentInformation:getKeywords($info), + "creationdate": pdfbox:gregToISO(PDDocumentInformation:getCreationDate($info)), + "author": PDDocumentInformation:getAuthor($info) + } +}; + + (:~ convert date :) +declare +function pdfbox:gregToISO($item as item()) +as xs:string{ + Q{java:java.util.GregorianCalendar}toZonedDateTime($item)=>string() +}; (:~ outline for $doc as map()* :) declare function pdfbox:outline($doc as item()) as map(*)*{ (# db:wrapjava some #) { - let $bookmark:= + let $outline:= PDDocument:getDocumentCatalog($doc) =>PDDocumentCatalog:getDocumentOutline() - =>PDOutlineItem:getFirstChild() - - let $bk:=pdfbox:outline($doc,$bookmark) - return $bk + + return if(exists($outline)) + then pdfbox:outline($doc,PDOutlineItem:getFirstChild($outline)) } }; -(: return bookmark info for children of $outlineItem as seq of maps :) +(:~ return bookmark info for children of $outlineItem as seq of maps :) declare function pdfbox:outline($doc as item(),$outlineItem as item()?) -as map(*)* -{ - let $find:=hof:until( + +as map(*)*{ + let $find as map(*):=pdfbox:_outline($doc ,$outlineItem) + return map:get($find,"list") +}; + +(: BaseX bug 10.7? error if inlined in outline :) +declare function pdfbox:_outline($doc as item(),$outlineItem as item()?) +as map(*){ + hof:until( function($output) { empty($output?this) }, function($input ) { let $bk:= pdfbox:bookmark($input?this,$doc) @@ -112,10 +139,9 @@ as map(*)* "this": PDOutlineItem:getNextSibling($input?this)} }, map{"list":(),"this":$outlineItem} - ) - return $find?list + ) }; - +(:~ outline as xml :) declare function pdfbox:outline-xml($outline as map(*)*) as element(outline){ element outline { @@ -175,19 +201,26 @@ as xs:string }; -(:~ pageLabel for every page +(:~ pageLabel info @see https://www.w3.org/TR/WCAG20-TECHS/PDF17.html#PDF17-examples @see https://codereview.stackexchange.com/questions/286078/java-code-showing-page-labels-from-pdf-files :) declare function pdfbox:getPageLabels($doc as item()) +as item() +{ + PDDocument:getDocumentCatalog($doc) + =>PDDocumentCatalog:getPageLabels() +}; + +(:~ pageLabel for every page:) +declare function pdfbox:pageLabels($doc as item()) as xs:string* { PDDocument:getDocumentCatalog($doc) =>PDDocumentCatalog:getPageLabels() =>PDPageLabels:getLabelsByPageIndices() }; - -(: text on $pageNo :) +(:~ return text on $pageNo :) declare function pdfbox:getText($doc as item(), $pageNo as xs:integer) as xs:string{ let $tStripper := (# db:wrapjava instance #) { @@ -198,4 +231,19 @@ as xs:string{ return (# db:checkstrings #) {PDFTextStripper:getText($tStripper,$doc)} }; +declare function pdfbox:report($pdfpath as xs:string) +as map(*){ + let $doc:=pdfbox:open($pdfpath) + return (map{ + "file": $pdfpath, + "pages": pdfbox:page-count($doc), + "outline": pdfbox:outline($doc)=>count() + },pdfbox:information($doc) +)=>map:merge() +}; +(: @TODO :) +declare function pdfbox:pageAsImage($doc as item(), $pageNo as xs:integer) +as item(){ +(: BufferedImage image = pdfRenderer.renderImageWithDPI(i, 200, ImageType.RGB) :) +}; diff --git a/src/scratch/abc.xq b/src/scratch/abc.xq index 2ff4ef1..ec55204 100644 --- a/src/scratch/abc.xq +++ b/src/scratch/abc.xq @@ -1,6 +1,6 @@ (: test use of pageIndex :) -import module namespace pdfbox="urn:expkg-zone58:pdfbox:3" at "../src/lib/pdfbox3.xqm"; -import module namespace pagenos = 'urn:pageno' at "../src/lib/pageno.xqm"; +import module namespace pdfbox="urn:expkg-zone58:pdfbox3" at "../lib/pdfbox3.xqm"; + declare variable $base:=file:base-dir(); declare function local:go($doc,$pdf as element(pdf)){ let $range:=$pdf/@pages/tokenize(.,"–") @@ -11,7 +11,7 @@ declare function local:go($doc,$pdf as element(pdf)){ }; let $src:="257107---Book_File-Web_PDF_9798400691218_486731.pdf"=>file:resolve-path($base) let $doc:=pdfbox:open($src) -let $labels:= pdfbox:getPageLabels($doc) +let $labels:= pdfbox:pageLabels($doc) let $pdfs:=doc("pdfs\chunks-docbook.xml")/chunks/pdf for $pdf in $pdfs let $range:=$pdf/@pages/tokenize(.,"–") diff --git a/src/scratch/pdfbox.xq b/src/scratch/pdfbox.xq index db0ebca..36c67a5 100644 --- a/src/scratch/pdfbox.xq +++ b/src/scratch/pdfbox.xq @@ -8,15 +8,17 @@ declare variable $samples:= map{ "climate": "data\drop-01d\set\2-6-1\A5579C_1\271989---Book_File-Web_PDF_9798400627484_486728.pdf", "women": "data\drop-01d\set\2-6-1\A6229C_1\257334---Book_File-Web_PDF_9798216172628_486742.pdf", "genocide": "data\drop1-pdf\GR2967-TRD\272791---Book_File-Web_PDF_9798400640216_486366.pdf", - "world": "data\drop-01c\gpg-book\2-6\A3506C-TRD\256186---Book_File-Web_PDF_9798216038955_486148.pdf", - "dummy": "lib\abc-clio-dummy.pdf" + "world": "data\drop-01c\gpg-book\2-6\A3506C-TRD\256186---Book_File-Web_PDF_9798216038955_486148.pdf" }; declare variable $base:= "C:\Users\mrwhe\git\bloomsbury\content-architecture\xquery\ABC-CLIO\data"; (:~ resolve :) -declare variable $PDF:= $samples?women=>file:resolve-path($base); +declare variable $PDF:= +$samples?world=>file:resolve-path($base) +(: "C:\Users\mrwhe\git\expkg-zone58\pdfbox\samples.pdf\icelandic-dictionary.pdf" :) +; let $doc:=pdfbox:open($PDF) -return pdfbox:outline($doc)=>pdfbox:outline-xml() -(: return pdfbox:extract($doc,"c:\tmp\junk3.pdf",1,pdfbox:page-count($doc)) :) \ No newline at end of file + +return pdfbox:information($doc) \ No newline at end of file diff --git a/src/test/test.xqm b/src/test/test.xqm new file mode 100644 index 0000000..f7a57a1 --- /dev/null +++ b/src/test/test.xqm @@ -0,0 +1,69 @@ +(:~ tests for pdfbox3 + + :) +module namespace test="urn:expkg-zone58:pdfbox3:tests"; +import module namespace pdfbox="urn:expkg-zone58:pdfbox3" at "../lib/pdfbox3.xqm"; + +declare variable $test:base:=file:base-dir()=>file:parent()=>file:parent(); + +declare %unit:test +function test:pdfbox-version(){ + unit:assert(starts-with(pdfbox:version(),"3.0")) +}; + +declare %unit:test +function test:page-count(){ + let $PDF:="samples.pdf/BaseX100.pdf"=>test:resolve() + let $pages:=pdfbox:open($PDF)=>pdfbox:page-count() + return unit:assert-equals($pages,521) +}; + +declare %unit:test +function test:outline-none(){ + let $PDF:="samples.pdf/BaseX100.pdf"=>test:resolve() + let $outline:=pdfbox:open($PDF)=>pdfbox:outline() + return unit:assert(empty($outline)) +}; + +declare %unit:test +function test:outline-present(){ + let $PDF:="samples.pdf/icelandic-dictionary.pdf"=>test:resolve() + let $outline:=pdfbox:open($PDF)=>pdfbox:outline() + return unit:assert(exists($outline)) +}; + +declare %unit:test +function test:outline-xml(){ + let $PDF:="samples.pdf/icelandic-dictionary.pdf"=>test:resolve() + let $outline:=pdfbox:open($PDF)=>pdfbox:outline()=>pdfbox:outline-xml() + return unit:assert-equals(count($outline/bookmark),31) +}; + +declare %unit:test +function test:pagelabels(){ + let $PDF:="samples.pdf/BaseX100.pdf"=>test:resolve() + let $labels:=pdfbox:open($PDF)=>pdfbox:pageLabels() + return ( + unit:assert($labels[1]="i") , + unit:assert($labels[27]="1") + ) +}; + +declare %unit:test +function test:save(){ + let $dest:=file:create-temp-file("test",".pdf")=>trace("DEST: ") + let $PDF:="samples.pdf/BaseX100.pdf"=>test:resolve() + let $outline:=pdfbox:open($PDF)=>pdfbox:extract(2,12,$dest) + return unit:assert(true()) +}; + +declare %unit:test +function test:page-text(){ + let $PDF:="samples.pdf/BaseX100.pdf"=>test:resolve() + let $text:=pdfbox:open($PDF)=>pdfbox:getText(1) + return unit:assert(starts-with($text,"BaseX Documentation")) +}; + +declare function test:resolve($file as xs:string){ + file:resolve-path($file,$test:base) +}; diff --git a/src/webapp/pdf/api.xqm b/src/webapp/pdf/api.xqm index 5e35c0b..1519946 100644 --- a/src/webapp/pdf/api.xqm +++ b/src/webapp/pdf/api.xqm @@ -8,7 +8,7 @@ declare %rest:path('/pdf/api/sources') %output:method("json") %output:json("format=xquery") -function api:apt() +function api:apt() as map(*) { let $base:="C:/Users/mrwhe/git/expkg-zone58/pdfbox/data/" let $d:="1e/" @@ -18,6 +18,7 @@ function api:apt() "items": array{$f!api:path-info(.)} } }; + declare function api:path-info($file as xs:string) as map(*) { diff --git a/src/webapp/pdf/readme.md b/src/webapp/pdf/readme.md index 33c5a17..46fbfa5 100644 --- a/src/webapp/pdf/readme.md +++ b/src/webapp/pdf/readme.md @@ -1,6 +1,13 @@ Uses * https://github.com/blikblum/slick-router#readme * https://dev.to/blikblum/slick-router-a-powerful-router-for-web-components-3fck + +## Sync +``` +cd C:\Users\mrwhe\git\expkg-zone58\pdfbox\src\webapp\pdf + +c:\DeltaCopy\rsync -rlptz --progress --exclude=.git --exclude=.vscode . andy@localhost::basexserv/ +``` ## random html in markdown + +
+ + + +
+ `; + } connectedCallback() { this.innerHTML = `
@@ -222,4 +256,35 @@ customElements.define('profile-index-view', } } ) +customElements.define('fetch-json', + class FetchJson extends HTMLElement { + static observedAttributes = ["src", "size"]; + connectedCallback() { + this.getModel(); + } + getModel() { + const src = this.getAttribute('src') + + "?" + new URLSearchParams({ foo: 'value', bar: 2, }); + return new Promise((res, rej) => { + fetch(src) + .then(data => data.json()) + .then((json) => { + this.data=data; + this.renderPosts(json); + res(); + }) + .catch((error) => rej(error)); + }) + } + renderPosts(data) { + this.innerHTML = `${this.getAttribute('src')} : ${data.count}`; + + this.dispatchEvent(new CustomEvent("load", { + detail: data, + composed: true, + bubbles: true + })); + } + } +) diff --git a/src/webapp/pdf/static/index.html b/src/webapp/pdf/static/index.html index bd6e8fd..699f72a 100644 --- a/src/webapp/pdf/static/index.html +++ b/src/webapp/pdf/static/index.html @@ -18,7 +18,6 @@ - diff --git a/src/webapp/pdf/static/styles.css b/src/webapp/pdf/static/styles.css index eeeeb6a..327c763 100644 --- a/src/webapp/pdf/static/styles.css +++ b/src/webapp/pdf/static/styles.css @@ -73,3 +73,21 @@ html { router-outlet > * { display: block; } + +.card-header { + max-width: 300px; +} + +.card-header [slot='header'] { + display: flex; + align-items: center; + justify-content: space-between; +} + +.card-header h3 { + margin: 0; +} + +.card-header sl-icon-button { + font-size: var(--sl-font-size-medium); +} \ No newline at end of file