Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve file naming and pathing #104

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bookbinder",
"version": "1.3.4",
"version": "1.3.5",
"description": "An app to rearrange PDF pages for printing for bookbinding",
"type": "module",
"scripts": {
Expand Down
27 changes: 17 additions & 10 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ export class Book {
// create a directory named after the input pdf and fill it with
// the signatures
this.zip = new JSZip();
var origFileName = this.inputpdf.replace(/\s|,|\.pdf/, '');
var origFileName = this.inputpdf;
origFileName = origFileName
.replace(/[-\s,_]+/g, '_')
.replace(/_*\.pdf/g, '')
.toLowerCase();
this.filename = origFileName;

if (
Expand Down Expand Up @@ -341,7 +345,7 @@ export class Book {
embeddedPages: generateAggregate ? [embeddedPages0, embeddedPages1] : null,
aggregatePdfs: generateAggregate ? [aggregatePdf0, aggregatePdf1] : null,
pageIndexDetails: signature,
id: generateSignatures ? `signature${i}` : null,
id: generateSignatures ? `${this.filename}_signature${i}` : null,
isDuplex: this.duplex,
fileList: this.filelist,
});
Expand All @@ -351,17 +355,20 @@ export class Book {

if (aggregatePdf1 != null) {
await aggregatePdf1.save().then((pdfBytes) => {
if (!isPreview) this.zip.file('aggregate_side2.pdf', pdfBytes);
if (!isPreview) this.zip.file(`${this.filename}_typeset_side2.pdf`, pdfBytes);
});
}
if (aggregatePdf0 != null) {
await aggregatePdf0.save().then((pdfBytes) => {
if (!isPreview)
this.zip.file(this.duplex ? 'aggregate_book.pdf' : 'aggregate_side1.pdf', pdfBytes);
this.zip.file(
this.duplex ? `${this.filename}_typeset.pdf` : `${this.filename}_typeset_side1.pdf`,
pdfBytes
);
});
}
var rotationMetaInfo =
(this.paper_rotation_90 ? '_paperRotated' : '') +
(this.paper_rotation_90 ? 'paper_rotated' : '') +
(this.source_rotation == 'none' ? '' : `_${this.source_rotation}`);
this.filename = `${origFileName}${rotationMetaInfo}`;
resultPDF = aggregatePdf0;
Expand Down Expand Up @@ -525,7 +532,7 @@ export class Book {

if (printSignatures) {
await outPDF.save().then((pdfBytes) => {
this.zip.file(config.outname, pdfBytes);
this.zip.file(`signatures/${config.outname}`, pdfBytes);
});
}
}
Expand Down Expand Up @@ -795,7 +802,7 @@ export class Book {
const pages = config.pageIndexDetails;
// duplex printers print both sides of the sheet,
if (config.isDuplex) {
const outduplex = printSignatures ? `${config.id}duplex.pdf` : null;
const outduplex = printSignatures ? `${config.id}_duplex.pdf` : null;
await this.writepages({
outname: outduplex,
pageList: pages[0],
Expand All @@ -810,8 +817,8 @@ export class Book {
} else {
// for non-duplex printers we have two files, print the first, flip
// the sheets over, then print the second
const outname1 = printSignatures ? `${config.id}side1.pdf` : null;
const outname2 = printSignatures ? `${config.id}side2.pdf` : null;
const outname1 = printSignatures ? `${config.id}_side1.pdf` : null;
const outname2 = printSignatures ? `${config.id}_side2.pdf` : null;

await this.writepages({
outname: outname1,
Expand Down Expand Up @@ -851,7 +858,7 @@ export class Book {
this.bundleSettings();
return this.zip.generateAsync({ type: 'blob' }).then((blob) => {
console.log(' calling saveAs on ', this.filename);
saveAs(blob, `${this.filename}.zip`);
saveAs(blob, `${this.filename}_bookbinder.zip`);
});
}

Expand Down
Loading