Skip to content

Commit

Permalink
Added global namespace \ to class names
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianKresse committed Jun 23, 2023
1 parent e593f5a commit e2b53e7
Show file tree
Hide file tree
Showing 170 changed files with 723 additions and 723 deletions.
8 changes: 4 additions & 4 deletions public/demos/1-Core/actions/add-a-javascript/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
$path = displayFiles($files, false);

// create a writer instance
$writer = new SetaPDF_Core_Writer_Http('AddJavaScript.pdf', false);
$writer = new \SetaPDF_Core_Writer_Http('AddJavaScript.pdf', false);
// create a document instance
$document = SetaPDF_Core_Document::loadByFilename($path, $writer);
$document = \SetaPDF_Core_Document::loadByFilename($path, $writer);

// this is our JavaScript we want to inject - we check for an
// existing JavaScript variable in the document to show some logic.
$js = 'var msg = typeof(SetaPDF) != "undefined" ? SetaPDF : "Hello from SetaPDF!"; app.alert(msg);';
// create an action
$jsAction = new SetaPDF_Core_Document_Action_JavaScript($js);
$jsAction = new \SetaPDF_Core_Document_Action_JavaScript($js);

// get names
$names = $document->getCatalog()->getNames();
// get the JavaScript name tree
$javaScriptTree = $names->getTree(SetaPDF_Core_Document_Catalog_Names::JAVA_SCRIPT, true);
$javaScriptTree = $names->getTree(\SetaPDF_Core_Document_Catalog_Names::JAVA_SCRIPT, true);

// make sure we've an unique name
$name = 'SetaPDF';
Expand Down
6 changes: 3 additions & 3 deletions public/demos/1-Core/actions/delete-javascript/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
$path = displayFiles($files);

// create a document
$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);

// get names
$names = $document->getCatalog()->getNames();
// get the JavaScript name tree
$javaScriptTree = $names->getTree(SetaPDF_Core_Document_Catalog_Names::JAVA_SCRIPT);
$javaScriptTree = $names->getTree(\SetaPDF_Core_Document_Catalog_Names::JAVA_SCRIPT);

$out = '';

Expand All @@ -33,7 +33,7 @@
}

if ($shouldSave) {
$writer = new SetaPDF_Core_Writer_Http();
$writer = new \SetaPDF_Core_Writer_Http();
$document->setWriter($writer);
$document->save()->finish();
die();
Expand Down
6 changes: 3 additions & 3 deletions public/demos/1-Core/actions/get-javascript/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
$path = displayFiles($files);

// create a document
$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);

// get names
$names = $document->getCatalog()->getNames();
// get the JavaScript name tree
$javaScriptTree = $names->getTree(SetaPDF_Core_Document_Catalog_Names::JAVA_SCRIPT);
$javaScriptTree = $names->getTree(\SetaPDF_Core_Document_Catalog_Names::JAVA_SCRIPT);

if ($javaScriptTree) {
$allJavaScripts = $javaScriptTree->getAll(false, SetaPDF_Core_Document_Action_JavaScript::class);
$allJavaScripts = $javaScriptTree->getAll(false, \SetaPDF_Core_Document_Action_JavaScript::class);

foreach ($allJavaScripts as $name => $jsAction) {
echo $name . '<br />------------------';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$path = displayFiles($files);

// create a document
$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);

$catalog = $document->getCatalog();
$dictionary = $catalog->getDictionary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@

$path = displayFiles($files);

$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);
$terminalFields = $document->getCatalog()->getAcroForm()->getTerminalFieldsObjects();

$signatureFieldFound = false;

foreach ($terminalFields as $fieldData) {
$fieldData = $fieldData->ensure();

$ft = SetaPDF_Core_Type_Dictionary_Helper::resolveAttribute($fieldData, 'FT');
$ft = \SetaPDF_Core_Type_Dictionary_Helper::resolveAttribute($fieldData, 'FT');
if (!$ft || $ft->getValue() !== 'Sig') {
continue;
}

$fieldName = SetaPDF_Core_Document_Catalog_AcroForm::resolveFieldName($fieldData);
$fieldName = \SetaPDF_Core_Document_Catalog_AcroForm::resolveFieldName($fieldData);
echo sprintf('Signature Field "%s" found! ', $fieldName);
$signatureFieldFound = true;

$v = SetaPDF_Core_Type_Dictionary_Helper::resolveAttribute($fieldData, 'V');
if (!$v || !$v->ensure() instanceof SetaPDF_Core_Type_Dictionary) {
$v = \SetaPDF_Core_Type_Dictionary_Helper::resolveAttribute($fieldData, 'V');
if (!$v || !$v->ensure() instanceof \SetaPDF_Core_Type_Dictionary) {
echo ' But not digital signed.<br /><br />';
continue;
}
Expand All @@ -43,7 +43,7 @@
$signatureData = $v->ensure()->getValue('Contents')->ensure()->getValue();
$signatureData = rtrim($signatureData, "\0");

echo '<a href="https://lapo.it/asn1js/#' . SetaPDF_Core_Type_HexString::str2hex($signatureData) . '" ' .
echo '<a href="https://lapo.it/asn1js/#' . \SetaPDF_Core_Type_HexString::str2hex($signatureData) . '" ' .
'target="_blank">asn1js</a> | ';
echo '<a href="data:application/pkcs7-mime;base64,' . base64_encode($signatureData) . '" ' .
'download="signature.pkcs7">download</a><br />';
Expand All @@ -59,9 +59,9 @@

$propertyValue = $value->getValue($property)->ensure()->getValue();
if ($property === SetaPDF_Signer::PROP_TIME_OF_SIGNING) {
$propertyValue = SetaPDF_Core_DataStructure_Date::stringToDateTime($propertyValue);
$propertyValue = \SetaPDF_Core_DataStructure_Date::stringToDateTime($propertyValue);
} else {
$propertyValue = SetaPDF_Core_Encoding::convertPdfString($propertyValue);
$propertyValue = \SetaPDF_Core_Encoding::convertPdfString($propertyValue);
}

$signatureProperties[$property] = $propertyValue;
Expand Down
30 changes: 15 additions & 15 deletions public/demos/1-Core/analyze/check-for-encryption/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$path = displayFiles($files);

$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);

if (!$document->hasSecHandler()) {
echo 'Document is not encrypted.';
Expand All @@ -21,53 +21,53 @@
$data = [];

$secHandler = $document->getSecHandler();
if ($secHandler instanceof SetaPDF_Core_SecHandler_PublicKey) {
if ($secHandler instanceof \SetaPDF_Core_SecHandler_PublicKey) {
$data['Security Method'] = 'Public Key Security';

} elseif ($secHandler instanceof SetaPDF_Core_SecHandler_Standard) {
} elseif ($secHandler instanceof \SetaPDF_Core_SecHandler_Standard) {
$data['Security Method'] = 'Password Security';
$data['Document Open Password'] = ($secHandler->auth() ? 'No' : 'Yes');
$data['Permissions Password'] = ($secHandler->getAuthMode() === SetaPDF_Core_SecHandler::OWNER ? 'No' : 'Yes');
$data['Permissions Password'] = ($secHandler->getAuthMode() === \SetaPDF_Core_SecHandler::OWNER ? 'No' : 'Yes');

if (!$secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_PRINT)) {
if (!$secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_PRINT)) {
$data['Printing'] = 'No';
} elseif ($secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_DIGITAL_PRINT)) {
} elseif ($secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_DIGITAL_PRINT)) {
$data['Printing'] = 'High Resolution';
} else {
$data['Printing'] = 'Low Resolution (150 dpi)';
}

$modify = $secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_MODIFY);
$modify = $secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_MODIFY);
$data['Changing the Document'] = $modify ? 'Allowed' : 'Not Allowed';

$annot = $secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_ANNOT);
$annot = $secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_ANNOT);
$data['Commenting'] = $modify || $annot ? 'Allowed' : 'Not Allowed';

$data['Form Field Fill-in or Signing'] =
(
$modify
|| $annot
|| $secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_FILL_FORM)
|| $secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_FILL_FORM)
) ? 'Allowed' : 'Not Allowed';

$data['Document Assembly'] =
($modify || $secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_ASSEMBLE))
($modify || $secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_ASSEMBLE))
? 'Allowed' : 'Not Allowed';

$copy = $secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_COPY);
$copy = $secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_COPY);
$data['Content Copying'] = $copy ? 'Allowed' : 'Not Allowed';

$data['Content Accessibility Enabled'] =
($copy || $secHandler->getPermission(SetaPDF_Core_SecHandler::PERM_ACCESSIBILITY))
($copy || $secHandler->getPermission(\SetaPDF_Core_SecHandler::PERM_ACCESSIBILITY))
? 'Allowed' : 'Not Allowed';

$data['Page Extraction'] =
$secHandler->getAuthMode() === SetaPDF_Core_SecHandler::OWNER ? 'Allowed' : 'Not Allowed';
$secHandler->getAuthMode() === \SetaPDF_Core_SecHandler::OWNER ? 'Allowed' : 'Not Allowed';

list($algorithm, $keyLength) = $secHandler->getStringAlgorithm();
if ($algorithm & SetaPDF_Core_SecHandler::ARCFOUR) {
if ($algorithm & \SetaPDF_Core_SecHandler::ARCFOUR) {
$data['Encryption Level'] = ($keyLength * 8) . '-bit RC4';
} elseif ($algorithm & SetaPDF_Core_SecHandler::AES) {
} elseif ($algorithm & \SetaPDF_Core_SecHandler::AES) {
$data['Encryption Level'] = ($keyLength * 8) . '-bit AES';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

$path = displayFiles($files);

$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);
$metadata = $document->getInfo()->getMetadata();

$xpath = new DOMXPath($metadata);
$xpath = new \DOMXPath($metadata);
$xpath->registerNamespace('x', 'adobe:ns:meta/');
$xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
$xpath->registerNamespace('pdfaid', 'http://www.aiim.org/pdfa/ns/id/');
Expand Down
2 changes: 1 addition & 1 deletion public/demos/1-Core/analyze/check-for-text/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once $classesDirectory . '/ContentStreamProcessor/TextProcessor.php';

// load a document instance
$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);
// get access to the pages object
$pages = $document->getCatalog()->getPages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// require the text processor class
require_once $classesDirectory . '/Inspector/TransparencyInspector.php';

$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);

$inspector = new TransparencyInspector($document);
$transparencyElements = $inspector->process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This script extracts all color related information from an existing PDF file.
</p>
<p>
It makes use of the <code>SetaPDF_Core_Parser_Content</code> class which encapsulate a content stream,
It makes use of the <code>\SetaPDF_Core_Parser_Content</code> class which encapsulate a content stream,
process it and call registered callback methods on specific operators.
</p>
<p>
Expand Down
8 changes: 4 additions & 4 deletions public/demos/1-Core/analyze/get-color-spaces/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require_once $classesDirectory . '/ContentStreamProcessor/ColorProcessor.php';
require_once $classesDirectory . '/Inspector/ColorInspector.php';

$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);
$inspector = new ColorInspector($document);
$colors = $inspector->getColors();

Expand All @@ -39,18 +39,18 @@
echo $color['colorSpace'] . ': ' . $className . "\n";

switch (true) {
case ($data instanceof SetaPDF_Core_ColorSpace_Separation):
case ($data instanceof \SetaPDF_Core_ColorSpace_Separation):
echo ' Name: ' . $data->getName() . "\n";
echo ' Alt: ' . $data->getAlternateColorSpace()->getFamily() . "\n";
break;

case ($data instanceof SetaPDF_Core_ColorSpace_IccBased):
case ($data instanceof \SetaPDF_Core_ColorSpace_IccBased):
$parser = $data->getIccProfileStream()->getParser();
echo ' Description: ' . $parser->getDescription() . "\n";
echo ' Number of components: ' . $parser->getNumberOfComponents() . "\n";
break;

case ($data instanceof SetaPDF_Core_ColorSpace_DeviceN):
case ($data instanceof \SetaPDF_Core_ColorSpace_DeviceN):
echo ' Names: ' . implode(', ', $data->getNames()) . "\n";
echo ' Alt: ' . $data->getAlternateColorSpace()->getFamily() . "\n";
break;
Expand Down
2 changes: 1 addition & 1 deletion public/demos/1-Core/analyze/get-fonts/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

foreach ($fontObjects AS $fontObject) {
try {
$font = SetaPDF_Core_Font::get($fontObject);
$font = \SetaPDF_Core_Font::get($fontObject);
} catch (Exception $e) {
echo $e->getMessage();
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if (!isset($_GET['p'])) {

// load a document instance
$document = SetaPDF_Core_Document::loadByFilename($path);
$document = \SetaPDF_Core_Document::loadByFilename($path);
// get access to the pages object
$pages = $document->getCatalog()->getPages();

Expand Down Expand Up @@ -60,8 +60,8 @@
} else {

// let's create a writer and document instance
$writer = new SetaPDF_Core_Writer_Http('marked.pdf', true);
$document = SetaPDF_Core_Document::loadByFilename($path, $writer);
$writer = new \SetaPDF_Core_Writer_Http('marked.pdf', true);
$document = \SetaPDF_Core_Document::loadByFilename($path, $writer);

// get access to the pages object
$pages = $document->getCatalog()->getPages();
Expand All @@ -70,8 +70,8 @@
$page = $pages->getPage($_GET['p']);

// set an open action, so that the page is shown when opened (requires support of the reader application)
$dest = SetaPDF_Core_Document_Destination::createByPage($page);
$document->getCatalog()->setOpenAction(new SetaPDF_Core_Document_Action_GoTo($dest));
$dest = \SetaPDF_Core_Document_Destination::createByPage($page);
$document->getCatalog()->setOpenAction(new \SetaPDF_Core_Document_Action_GoTo($dest));

// get access to the pages canvas
$canvas = $page->getCanvas();
Expand Down
14 changes: 7 additions & 7 deletions public/demos/1-Core/annotations/add-link/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
// load and register the autoload function
require_once '../../../../../bootstrap.php';

$writer = new SetaPDF_Core_Writer_Http('link.pdf', true);
$document = new SetaPDF_Core_Document($writer);
$writer = new \SetaPDF_Core_Writer_Http('link.pdf', true);
$document = new \SetaPDF_Core_Document($writer);

// get access to the pages
$pages = $document->getCatalog()->getPages();
// create a new page
$page = $pages->create(SetaPDF_Core_PageFormats::A4);
$page = $pages->create(\SetaPDF_Core_PageFormats::A4);
// access its canvas
$canvas = $page->getCanvas();

// create a font instance
$font = SetaPDF_Core_Font_Standard_Helvetica::create($document);
$font = \SetaPDF_Core_Font_Standard_Helvetica::create($document);

// use the text block helper to draw the text
$text = new SetaPDF_Core_Text_Block($font, 12);
$text = new \SetaPDF_Core_Text_Block($font, 12);
$text->setText('This is a link to www.setasign.com!');
$x = $page->getWidth() / 2 - $text->getWidth() / 2;
$y = $page->getHeight() - 100;
$text->draw($canvas, $x, $y);

// create the link annotation
$link = new SetaPDF_Core_Document_Page_Annotation_Link(
$link = new \SetaPDF_Core_Document_Page_Annotation_Link(
[$x, $y, $x + $text->getWidth(), $y + $text->getHeight()],
new SetaPDF_Core_Document_Action_Uri('https://www.setasign.com')
new \SetaPDF_Core_Document_Action_Uri('https://www.setasign.com')
);
// and add it
$page->getAnnotations()->add($link);
Expand Down
Loading

0 comments on commit e2b53e7

Please sign in to comment.