Skip to content

Commit

Permalink
fix: opening PDF fix
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Dec 9, 2024
1 parent 85e1216 commit 8cb077f
Show file tree
Hide file tree
Showing 8 changed files with 1,573 additions and 1,597 deletions.
2 changes: 1 addition & 1 deletion app/components/list/MainList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
}
function unselectItem(item: Item) {
DEV_LOG && console.log('unselectItem', item);
// DEV_LOG && console.log('unselectItem', item);
if (item.selected) {
if (item.folder) {
folderItems?.some((d, index) => {
Expand Down
7 changes: 6 additions & 1 deletion app/components/pdf/PDFPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { hideLoading, showLoading, showPopoverMenu, showSettings, showSliderPopover, showSnack } from '~/utils/ui';
import { colors, fonts, screenHeightDips, screenRatio, screenWidthDips, windowInset } from '~/variables';
import PageIndicator from '../common/PageIndicator.svelte';
import { SilentError } from '@shared/utils/error';
// let bitmapPaint: Paint;
// const textPaint = new Paint();
const bgPaint = new Paint();
Expand Down Expand Up @@ -108,7 +109,11 @@
showLoading(l('exporting'));
const filePath = await exportPDFAsync({ pages, document });
hideLoading();
openFile(filePath);
if (filePath) {
openFile(filePath);
} else {
throw new SilentError(lc('no_pages_in_pdf'));
}
} catch (error) {
showError(error);
}
Expand Down
1 change: 1 addition & 0 deletions app/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
"no_document_found": "no document found",
"no_document_yet": "add a document using the camera or import one from an image",
"no_network": "no network",
"no_pages_in_pdf": "there was no pages to export in the PDF",
"no_qrcode": "no QRCode found",
"no_qrcode_found": "no QRCode found",
"no_space_left": "your device seems to be running out of free storage",
Expand Down
3 changes: 2 additions & 1 deletion app/services/pdf/PDFCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default class PDFCanvas {
const canvas = this.canvas;
const w = canvas.getWidth() - 2;
const h = canvas.getHeight() - 2;
DEV_LOG && console.log('drawPages', pages.length, this.options, canvas.getWidth(), canvas.getHeight(), w, h);
DEV_LOG && console.log('drawPages', pages.length, JSON.stringify(this.options), canvas.getWidth(), canvas.getHeight(), w, h);

const nbItems = pages.length;
// console.log('drawPDFPage', w, h, nbItems, srcs);
Expand Down Expand Up @@ -364,5 +364,6 @@ export default class PDFCanvas {
}
return hasPages;
}
return true;
}
}
2 changes: 1 addition & 1 deletion app/services/pdf/PDFExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export async function exportPDFAsync({ compress, document, filename, folder = kn
});
}
// DEV_LOG && console.log('export message sent to worker', { pages, folder, filename, compress });
const result = await sendMessageToWorker('export', { pages: pages.map((p) => p.page), folder, filename, compress }, Date.now());
const result = await sendMessageToWorker('export', { pages: pages.map((p) => ({ page: p.page })), folder, filename, compress }, Date.now());
// DEV_LOG && console.log('result', result);
return result.messageData;
}
Expand Down
10 changes: 7 additions & 3 deletions app/utils/ui/index.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { get } from 'svelte/store';
import type OptionSelect__SvelteComponent_ from '~/components/common/OptionSelect.svelte';
import type BottomSnack__SvelteComponent_ from '~/components/widgets/BottomSnack.svelte';
import BottomSnack from '~/components/widgets/BottomSnack.svelte';
import { cleanFilename, getFileNameForDocument, getFormatedDateForFilename, getLocaleDisplayName, l, lc } from '~/helpers/locale';
import { getFileNameForDocument, getFormatedDateForFilename, getLocaleDisplayName, l, lc } from '~/helpers/locale';
import { DocFolder, ImportImageData, OCRDocument, OCRPage, PageData } from '~/models/OCRDocument';
import { OCRLanguages, ocrService } from '~/services/ocr';
import { getTransformedImage } from '~/services/pdf/PDFExportCanvas.common';
Expand Down Expand Up @@ -95,7 +95,7 @@ import {
} from '~/utils/constants';
import { recycleImages } from '~/utils/images';
import { showToast } from '~/utils/ui';
import { colors, fontScale, screenHeightDips, screenWidthDips } from '~/variables';
import { colors, fontScale, screenWidthDips } from '~/variables';
import { MatricesTypes, Matrix } from '../color_matrix';
import { saveImage } from '../utils';

Expand Down Expand Up @@ -651,7 +651,11 @@ export async function showPDFPopoverMenu(pages: { page: OCRPage; document: OCRDo
const filePath = await exportPDFAsync({ pages, document });
hideLoading();
DEV_LOG && console.log('opening pdf', filePath);
openFile(filePath);
if (filePath) {
openFile(filePath);
} else {
throw new SilentError(lc('no_pages_in_pdf'));
}
break;
}
case 'share': {
Expand Down
2 changes: 1 addition & 1 deletion app/workers/PDFExportWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PDFExportWorker extends BaseWorker {

async export(id, type, { pages, folder, filename, compress }) {
try {
DEV_LOG && console.log(TAG, 'export', id, type, pages.length, folder, filename, compress);
DEV_LOG && console.log(TAG, 'export', id, type, pages.length, folder, filename, compress, JSON.stringify(pages));
const exporter = new PDFExportCanvas();
const filePath = await exporter.export({ pages, folder, filename, compress });
// const filePath = 'test';
Expand Down
Loading

0 comments on commit 8cb077f

Please sign in to comment.