Skip to content

Commit

Permalink
Merge pull request #18 from floxdeveloper/4-extracted-highlights-some…
Browse files Browse the repository at this point in the history
…times-omit-final-characters

Fix for Issue #4: extracted highlights sometimes omit final characters
  • Loading branch information
floxdeveloper authored Aug 8, 2024
2 parents 4191635 + 5820885 commit 289867a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ As such, you can relate comments for your topics (here 'Hello World') from sever

## Versions

1.2.1 improved annotation extraction

1.2.0 added template settings

1.1.0 add new function `Extract PDF Annotations from single file from path in clipboard` to extract annotations from PDFs outside Obsidian vault
Expand Down Expand Up @@ -84,7 +86,7 @@ This plugin builds on ideas from Alexis Rondeaus Plugin https://github.com/akaal

## Author

Franz Achermann
Franz Achermann and Florian Stöckl



2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-extract-pdf-annotations",
"name": "Extract PDF Annotations",
"version": "1.2.0",
"version": "1.2.1",
"minAppVersion": "1.1.1",
"description": "Extract PDF Annotations (Notes and Highlights) and sort them by topics",
"author": "Franz Achermann",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-extract-pdf-annotations",
"version": "1.2.0",
"version": "1.2.1",
"description": "Extract notes and highlights from PDF Files in Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions src/extractHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function searchQuad(minx: number, maxx: number, miny: number, maxy: number, item
if (x.transform[4] > maxx) return txt // start of text after highlight ends

const start = (x.transform[4] >= minx ? 0 : // start at pos 0, when text starts after hightlight start
Math.floor(x.str.length * (minx - x.transform[4]) / x.width)) // otherwise, rule of three: start proportional
Math.round(x.str.length * (minx - x.transform[4]) / x.width)) // otherwise, rule of three: start proportional
if (x.transform[4] + x.width <= maxx) { // end of txt ends before highlight ends
return txt + x.str.substr(start) //
} else { // else, calculate proporation end to get the expected length
const lenc = Math.floor(x.str.length * (maxx - x.transform[4]) / x.width) - start
const lenc = Math.round(x.str.length * (maxx - x.transform[4]) / x.width) - start
return txt + x.str.substr(start, lenc)
}
}, '')
Expand Down Expand Up @@ -52,7 +52,6 @@ export function extractHighlight(annot: any, items: any) {
// accumulate all annotations in the array total
async function loadPage(page, pagenum: number, file: PDFFile, containingFolder: string, total: object[]) {
let annotations = await page.getAnnotations()
// console.log('Annotations', annotations)

annotations = annotations.filter(function (anno) {
return SUPPORTED_ANNOTS.indexOf(anno.subtype) >= 0;
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export default class PDFAnnotationPlugin extends Plugin {
const filePathWithoutQuotes = filePathFromClipboard.replace(/"/g, '');
const stats = fs.statSync(filePathWithoutQuotes);
if (stats.isFile()) {
const pdfjsLib = await loadPdfJs()
const binaryContent = await FileSystemAdapter.readLocalFile(filePathWithoutQuotes)
const pdfjsLib = await loadPdfJs();
const binaryContent = await FileSystemAdapter.readLocalFile(filePathWithoutQuotes);
const filePathWithSlashs: string = filePathWithoutQuotes.replace(/\\/g, '/');
const filePathSplits: string[] = filePathWithSlashs.split('/');
const fileName = filePathSplits.last();
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"1.0.3": "0.12.0",
"1.0.4": "0.12.0",
"1.1.0": "1.1.1",
"1.2.0": "1.1.1"
"1.2.0": "1.1.1",
"1.2.1": "1.1.1"
}

0 comments on commit 289867a

Please sign in to comment.