-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdfConvertr.php
159 lines (120 loc) · 4.82 KB
/
pdfConvertr.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
//code for conversion of various file fomats to PDF
global $dPath, $docClass, $dPathclone;
//for wordDoc documents and other text Applications.
$fileParts = explode(".", $dPath);
$Exts = end($fileParts);
$Exts = strtolower($Exts);
$mumPath = str_replace("/","\\", $dPath);
$fileckr = str_replace("/","\\", $dPath);
$fileckr = str_replace($Exts, 'pdf', $fileckr);
$fileckr = str_replace('..', '.', $fileckr);
/**--------------------------------------------------------------------------------------------------------------------
CONVERSION ROUTINE USING UNIVERSAL DOCUMENT CONVERTER (UDC)
-----------------------------------------------------------------------------------------------------------------------**/
if(($Exts == "doc" || $Exts == "docx") && !file_exists($fileckr)){
//Creating Universal Document Converter object
$objUDC = new COM("UDC.APIWrapper");
//Setting up Universal Document Converter
$itfPrinter = $objUDC->Printers("Universal Document Converter");
$itfProfile = $itfPrinter->Profile;
$itfProfile->PageSetup->ResolutionX = 300;
$itfProfile->PageSetup->ResolutionY = 300;
$itfProfile->PageSetup->Orientation = 0;
$itfProfile->FileFormat->ActualFormat = 7; //PDF
$itfProfile->FileFormat->PDF->Multipage = 2; //Multipage mode
$itfProfile->OutputLocation->Mode = 1;
$dPathclone = $dPath;
$lowPath = str_replace("/","\\", $dPath);
$lowPathparts= explode('\\', $lowPath );
$clippedLowPath = $lowPathparts[0].'\\'.$lowPathparts[1];
$fpath = $itfProfile->OutputLocation->FolderPath = 'C:\xampp\htdocs\www.example.com\\'.$clippedLowPath; //'&[Documents]\UDC Output Files\\';
$fname = $itfProfile->OutputLocation->FileName = '&[DocName(0)].&[ImageType]';
$itfProfile->OutputLocation->OverwriteExistingFile = 1;
$itfProfile->PostProcessing->Mode = 0;
//Create MS Word object
$file = 'C:\xampp\htdocs\www.example.com\\'. $lowPath;
$WordApp = new COM("Word.Application");
//Print the document
$WordDoc = $WordApp->Documents->Open($file,0,1);
$WordApp->ActivePrinter = "Universal Document Converter";
$WordApp->PrintOut(False);
//Close the document and MS Word
$WordDoc->Close();
$WordApp->Quit();
$dPath = str_replace($Exts, 'pdf', $lowPath);
//setting up file path for access over network
$dPath = str_replace('\\', '/', $dPath);
$dPath = str_replace('..', '.', $dPath);
//time gap for created document to be ready for modification.
sleep(3);
}
else{
//setting file path for original document
$dPathclone = $dPath;
}
/**----------------------------------------------------------------------------------------------------------------------
Adding watermark to created or existing PDF files Using FPDF
------------------------------------------------------------------------------------------------------------------------**/
//preping for modification PDF files.
define('FPDF_FONTPATH', 'font/');
require('rotation.php');
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
//If original or modified file now exist as a PDF document.
if(file_exists($fileckr)){
//Altering working file path
$dPath = $fileckr;
//setting up file path for file access over network
$dPath = str_replace('\\', '/', $dPath);
$dPath = str_replace('..', '.', $dPath);
//specifying, specifically, the file extension of current working file.
global $Exts;
$Exts = 'pdf';
class PDF extends PDF_Rotate
{
function Header()
{
global $docClass;
//Put watermark
$this->SetFont('Arial', 'B', 50);
$this->SetTextColor(255, 192, 203);
$this->RotatedText(70, 170, $docClass, 45);//PLACEHOLDER:'W a t e r m a r k d e m o'
}
function RotatedText($x, $y, $txt, $angle)
{
//Text rotated around its origin
$this->Rotate($angle, $x, $y);
$this->Text($x, $y, $txt);
$this->Rotate(0);
}
}
$pdf = new PDF();
$pdf->Open();
$pdf->SetFont('Arial', '', 12);
//Setting the source PDF file
$pagecount = $pdf->setSourceFile($dPath);
//Importing the page(s) of the file
for($i = 1; $i <= $pagecount; $i++){
//$pdf->AddPage();
$pdfTpl = $pdf->importPage($i);
//checking for PDF document layout
$docspecs = $pdf->getTemplateSize($pdfTpl);
$pdf->AddPage($docspecs['h'] > $docspecs['w'] ? "P" : "L");
//Use this page as template
$pdf->useTemplate($pdfTpl);
}
//Print watermark
$pdf->Output(str_replace('.pdf', '(Modified).pdf', $dPath), "F");
$dPath = str_replace('.pdf', '(Modified).pdf', $dPath);
//echo $dPath;
}
else{
$dPath = $mumPath;
//setting up file path for access over network
$dPath = str_replace('\\', '/', $dPath);
$dPath = str_replace('..', '.', $dPath);
//setting file path for original document
$dPathclone = $dPath;
}
?>