<template>
<tr v-bind:class="{ 'table-primary': current }">
<th>{{item.day}}</th>
<td>{{item.title}}</td>
<td align="center">{{item.unit}}</td>
<td align="right">{{item.count.toFixed(3)}}</td>
<td align="right" width="120">{{item.price.toFixed(2)}} руб.</td>
<td align="right" width="120"><span v-if="item.type == 'work'">{{(item.count * item.price).toFixed(2)}} руб.</span></td>
<td align="right" width="120"><span v-if="item.type == 'material'">{{(item.count * item.price).toFixed(2)}} руб.</span></td>
<td align="right" width="120">{{(item.count * item.price).toFixed(2)}} руб.</td>
</tr>
</template>
<script>
export default {
name: "WorkDay",
props: {
item: {
type: Object,
required: true
},
current: {
type: Boolean,
required: true
}
}
}
</script>
<style scope>
.table td, .table th {
padding: 5px;
font-size: 14px;
}
</style>
await this.client.executeScript(`arguments[0].setAttribute("download", "card.pdf")`, loadCardElement);
import * as hummus from "hummus";
type tPDFReplace = {
source: string,
target: string,
page: number,
findText: string,
replaceText: string
};
const replaceTextPDF = function (options: tPDFReplace) {
const writer = hummus.createWriterToModify(options.source, {
modifiedFilePath: options.target
});
new hummus.PDFPageModifier(writer, options.page);
const sourceParser = writer.createPDFCopyingContextForModifiedFile().getSourceDocumentParser();
const pageObject = sourceParser.parsePage(options.page);
const textObjectId = pageObject.getDictionary().toJSObject().Contents.getObjectID();
const textStream = sourceParser.queryDictionaryObject(pageObject.getDictionary(), "Contents");
//read the original block of text data
let data = [];
const readStream = sourceParser.startReadingFromStream(textStream);
while (readStream.notEnded()) {
Array.prototype.push.apply(data, readStream.read(10000));
}
const dataStr = new Buffer(data).toString();
console.log(dataStr);
let str = dataStr.replace(options.findText, options.replaceText);
//Create and write our new text object
const objectsContext = writer.getObjectsContext();
objectsContext.startModifiedIndirectObject(textObjectId);
const stream = objectsContext.startUnfilteredPDFStream();
stream.getWriteStream().write(strToByteArray(str));
objectsContext.endPDFStream(stream);
objectsContext.endIndirectObject();
writer.end();
};
const strToByteArray = function (str: string) {
let myBuffer = [];
let buffer = new Buffer(str);
for (let i = 0; i < buffer.length; i++) {
myBuffer.push(buffer[i]);
}
return myBuffer;
};
(() => {
replaceTextPDF({
source: "/root/sk/src/test/test.pdf",
target: "/root/sk/src/test/test_new.pdf",
page: 0,
findText: "2121",
replaceText: "5555"
});
})();