-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemp.c
More file actions
61 lines (48 loc) · 1.59 KB
/
temp.c
File metadata and controls
61 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define BUFFER_SIZE 4096*10
// Function to create a new PDF file from an existing PDF file
void createNewPDF(const char *inputFilename, const char *outputFilename) {
int input_fd, output_fd;
ssize_t nread;
char buffer[BUFFER_SIZE];
// Open the input PDF file for reading
input_fd = open(inputFilename, O_RDONLY);
if (input_fd == -1) {
perror("Error opening input file");
exit(EXIT_FAILURE);
}
// Create the output PDF file for writing
output_fd = open(outputFilename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (output_fd == -1) {
perror("Error creating output file");
exit(EXIT_FAILURE);
}
// Read from the input file and write to the output file
while ((nread = read(input_fd, buffer, BUFFER_SIZE)) > 0) {
printf("Reading\n");
if (write(output_fd, buffer, nread) != nread) {
perror("Error writing to output file");
exit(EXIT_FAILURE);
}
}
// Close the files
if (close(input_fd) == -1) {
perror("Error closing input file");
exit(EXIT_FAILURE);
}
if (close(output_fd) == -1) {
perror("Error closing output file");
exit(EXIT_FAILURE);
}
}
int main() {
const char *inputFile = "./serverDir/temp.pdf";
const char *outputFile = "output.pdf";
// Create a new PDF file based on the input PDF file
createNewPDF(inputFile, outputFile);
printf("New PDF file created: %s\n", outputFile);
return 0;
}