Open pdf directly

Hello,

I have a file upload in a form (database).
The icons are also displayed correctly. So a pdf is also recognized as a pdf.

Normally every pdf is downloaded.
Time consuming and annoying.
Is there a way to open the pdf directly in a new window, for example?
The names of the pdf are never the same.
Haven’t found anything yet - can anyone help?

I was battling with the same some time ago. Try this:

1 Like

Thx Nico.
But as i can see there is a file location (i am using the database)
and a filename.

This will not work.

Opps, sorry did not see that you where using the database to store the files

There are some ways to do it.

You can use services from Google or Adobe to integrate the PDF into a Webpage.
But be aware, that there might be issues with availability and DSVGO / GDPR, cause for this you have to send confidential PDF to external servers.

Therefore I’m using the library pdf.js for my projects.
Everything can be on your server (external Scriptcase library).
Plus you can call the library and send the PDF as string from you database.

With some lines of code you can also display the PDF inside every form / control by replacing a label-field.

If you need that solution, send me your email-address via privat message and I’ll make a ZIP-file available to you.

Gunter Eibl

Sample:

Hello Gunter,
I don’t want to integrate Google or Adobe.
That makes no sense :wink:
If you have a idea! You welcome!

Hello gomi,
did send you an email with files and further info.
Best
Gunter

I am using pdf.js as well and I am curious how you were able to get this to work. Please let me know! Thanks

I did load pdf.js as an external library and wrote a small blank application, which you can use as modal, or so.

Please send me your email address as privat message and I’ll be happy to send you that application.
Best
Gunter

1 Like

Another easy solution is to use ViewerJS Home and choose to view a pdf in iframe.

1 Like

Hi Gunter,
I am trying to do thus too. Can you pls help? You can email me clarence@tomms.com.my

Hi There, I am trying to do this and you pls provide some instructions? Thanks

About ViewerJs

Create a field of type Label on a form or a control

OnLoad
{label} = ‘<iframe src = "…/wwwdph/js/ViewerJS/#’.$filepath.’" width=‘566’ height=‘810’ style=“text-align:center;” allowfullscreen webkitallowfullscreen>’;

Instead of wwwdph… change the path where ViewerJs is located and in $filepath variable the complete path of pdf file.

I am getting error forbidden. You don’t hv permission to access this resource

Have you download and installed ViewerJs?
If yes, check permissions on JS folder

1 Like

The content of the folder should look like:

-rw-r--r-- 1 www-data www-data   34520 Jun 28  2018 AGPL-3.0.txt
-rw-r--r-- 1 www-data www-data   17617 Jun 28  2018 compatibility.js
-rw-r--r-- 1 www-data www-data    1082 Jun 28  2018 example.local.css
drwxr-xr-x 2 www-data www-data    4096 Feb 28  2020 images
-rw-r--r-- 1 www-data www-data    6250 Jun 28  2018 index.html
-rw-r--r-- 1 www-data www-data     960 Jun 28  2018 ODFViewerPlugin.css
-rw-r--r-- 1 www-data www-data    7472 Jun 28  2018 ODFViewerPlugin.js
-rw-r--r-- 1 www-data www-data  253972 Jun 28  2018 pdf.js
-rw-r--r-- 1 www-data www-data      52 Jun 28  2018 pdfjsversion.js
-rw-r--r-- 1 www-data www-data     802 Jun 28  2018 PDFViewerPlugin.css
-rw-r--r-- 1 www-data www-data   11312 Jun 28  2018 PDFViewerPlugin.js
-rw-r--r-- 1 www-data www-data 1226846 Jun 28  2018 pdf.worker.js
-rw-r--r-- 1 www-data www-data    8364 Jun 28  2018 PluginLoader.js
-rw-r--r-- 1 www-data www-data   13463 Jun 28  2018 text_layer_builder.js
-rw-r--r-- 1 www-data www-data   10788 Jun 28  2018 ui_utils.js
-rw-r--r-- 1 www-data www-data   24150 Jun 28  2018 viewer.css
-rw-r--r-- 1 www-data www-data    8867 Jun 28  2018 viewer.js
-rw-r--r-- 1 www-data www-data  356518 Jun 28  2018 webodf.js
1 Like

Hello Giorgio,
as I can see it is probably possible to open the pdf in a separate window.
I have Documents uploads in most applications - but multiple and always in the database. So I don’t have a filepath here.
Is this also possible here or do I missing the forest though the trees?..

Yo manejo el problema de mostrar los pdf una vez ya estan realizada la carga, renombrardo el archivo y subiendo este un una carperta del servidor.

Debes de tener claros los path de desarrollo y produccion para controlar desde donde debe de mostrar el boton el archivo en forma correcta.

Debes de identificar y hacer un manejo de permisos y niveles de seguridad para evitar que usuarios puedan ver contenido no permitido. (User Security Level)

En el grid coloco un boton de pdf con el evento onClik busco y muestro el archivo que requiere el usuario.


The view file button lets you see the last file uploaded to the server in a php called viewer.

The grid with the pdf button creates the link to show the file that corresponds to each record.

Implemented app code

User security level is an array with the data of the user’s permissions, each document must have a permission level to confront against the user’s permissions and in this way define if the file can see it or not.






Implemented app code

------------- Boton Ver Archivo Redir --------------


// Redirection parameters
$redir_app    = 'control_visor';  // Application name
$redir_test   = [lastad] != '';  // Redirection test
$redir_target = '_self';  // Target window (_blank, _self, _parent or modal)
$redir_param  = array(     // Param list, add as many as needed

);

// Redirection
if ($redir_test)
{
sc_redir($redir_app, $redir_param, $redir_target);
}

--------------- Control visor ---------------------------

// onLoad  control_visor

{ad_buscar} = [lastad];


if($this->Ini->path_prod == "/scriptcase/prod")
	{
		$path = "../../../file/doc/up_files/";
		$path_ad = "../../../file/doc/uploads/scanner/le/";
	}
else
	{
		$path = "../_lib/file/doc/up_files/";
		$path_ad = "../_lib/file/doc/uploads/scanner/le/";
	}


$d = date('YmdHis');

$fname = {ad_buscar};
$img = "https://xxx.domino.com/images/sc_menu_pdf2_e.png";
$lx = 'https://xxx.domino.com/test3.php?desc=1&path='.$fname;
$ll = 'https://xxx.domino.com/sv/blank_acceso_denegado/';

	
$archivo_nuevo = $path . $fname;

$testf = file_exists($archivo_nuevo);

	if( ($testf == 1) )
		{
			$fn = "<iframe src='$archivo_nuevo' width='1000' height='500'> </iframe>";
			{visor} = $fn;			
		}
	else
		{
			$fn = "<iframe src='https://apps.coassist.com.co/test3.php?desc=1&path=".$fname."' width='1000' height='500'> </iframe>";
			{visor} = $fn;
		}
---------------------------------- form_upload_ad ---------------
// onLoad

if($this->Ini->path_prod == "/scriptcase/prod")
	{
		$path = "../../../file/doc/up_files/";
		$path_ad = "../../../file/doc/uploads/scanner/le/";
	}
else
	{
		$path = "../_lib/file/doc/up_files/";
		$path_ad = "../_lib/file/doc/uploads/scanner/le/";
	}


$d = date('YmdHis');
{radicado} = $d;
$fname = {ad_file};
$img = "https://xxx.domino.com/images/sc_menu_pdf2_e.png";
$lx = 'https://xxx.domino.com/test3.php?desc=1&path='.$fname;
$ll = 'https://xxx.domino.com/sv/blank_acceso_denegado/';

	
$archivo_nuevo = $path . {ad_file};

$testf = file_exists($archivo_nuevo);

	if( ($testf == 1) )
		{
			$fn = "<iframe src='$archivo_nuevo' width='1000' height='700'> </iframe>";
			{visor} = $fn;			
		}
	else
		{
			$fn = "<iframe src='https://apps.coassist.com.co/test3.php?desc=1&path=".$fname."' width='1000' height='700'> </iframe>";
			{visor} = $fn;
		}
	
-----------------------------------------------
//onValidate

if ( empty({tipo_ad}) )
	{
		sc_error_message('Error: Debe de seleccionar tipo de archivo digital !');
	}

if ( empty({ccnit}) )
	{
		sc_error_message('Error: Debe de seleccionar cedula o nit relacionado al documento !');
	}

if ( empty({ofn}) )
	{
		sc_error_message('Error: Debe de seleccionar algun archivo a cargar !');
	}


$check_sql = "SELECT id_tercero"
   . " FROM ticker.terceros"
   . " WHERE ccnit = '" . {ccnit} . "'";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]}))     // Row found
{
{id_tercero} = {rs[0][0]};
}
		else     // No row found
{
	sc_error_message('Error: Tercero no esta registrado por favor ingresarlo !');
}

--------------------------------------------------------

// onBeforeInsert

$nombre_actual = {ofn};
$trozos = explode(".", {ofn});
$extension = strtolower(end($trozos));

$str = {ofn};
// $pattern = "/[0-9]{14}_[0-9A-Z]{2}_[0-9a-zA-Z]{20}.[a-zA-Z]{3}/";
$pattern = "/[0-9]{14}_[0-9A-Z]{2}_[0-9a-zA-Z]{20}/";
// echo "Si el vaor es 1 es un nombre valido de AD: ".preg_match($pattern, $str);

if(preg_match($pattern, $str) == 1)
	{
		$nombre_nuevo = $nombre_actual;
		{tipo_ad} = substr($str,15,2);
		{radicado} = substr($str,0,14);
		{ccnit} = abs(substr($str,18,20));
		{ad_file} = $nombre_actual;
		{ext} = $extension;
		{caracteres} = strlen($nombre_nuevo);
	}
else
	{
		$nombre_nuevo = {radicado} . "_" . {tipo_ad} . "_" . str_pad({ccnit}, 20, "0", STR_PAD_LEFT) . "." . $extension;
		{ad_file} = $nombre_nuevo;
		{ext} = $extension;
		{caracteres} = strlen($nombre_nuevo);	
	}
-------------------------------------------------------------

// onAfterInsert

// Define si se esta en produccion o desarrollo para fijar el path correcto

if($this->Ini->path_prod == "/scriptcase/prod")
	{
		$path = "../../../file/doc/up_files/";
		$path_ad = "/opt/lampp/htdocs/sv/_lib/file/doc/uploads/scanner/le/";
	}
else
	{
		$path = "../_lib/file/doc/up_files/";
		$path_ad = "/opt/lampp/htdocs/sv/_lib/file/doc/uploads/scanner/le/";
	}

$archivo_actual = $path.{ofn};
$nombre_actual = {ofn};
$trozos = explode(".", {ofn});
$extension = strtolower(end($trozos));

$str = {ofn};
// $pattern = "/[0-9]{14}_[0-9A-Z]{2}_[0-9a-zA-Z]{20}.[a-zA-Z]{3}/";
$pattern = "/[0-9]{14}_[0-9A-Z]{2}_[0-9a-zA-Z]{20}/";
// echo "Si el vaor es 1 es un nombre valido de AD: ".preg_match($pattern, $str).'<br>';

if(preg_match($pattern, $str) == 1)
	{
		$nombre_nuevo = $nombre_actual;
		$archivo_nuevo = $path . $nombre_actual;
	}
else
	{
		$nombre_nuevo = {radicado} . "_" . {tipo_ad} . "_" . str_pad({ccnit}, 20, "0", STR_PAD_LEFT) . "." . $extension;
		$archivo_nuevo = $path . {radicado} . "_" . {tipo_ad} . "_" . str_pad({ccnit}, 20, "0", STR_PAD_LEFT) . "." . $extension;
	}

// echo $nombre_nuevo.'<br>';
[lastad] = $nombre_nuevo;

$testf = file_exists($archivo_actual);

if($testf == 1) 
	if($nombre_actual != $nombre_nuevo)
		{
			rename($archivo_actual, $archivo_nuevo);
			copy($archivo_nuevo, $path_ad . $nombre_nuevo);
			sc_exec_sql("UPDATE log_ad SET ad_file = '$nombre_nuevo', ext = '$extension' WHERE id = " . {id} . ";");  // Actualiza nombre de archivo digital 
		}
	else
		{
			copy($archivo_nuevo, $path_ad . $nombre_nuevo);
		}
else
	{
		sc_alert('Error: Archivio cargado no encontrado en servidor !');		
	}

$testf = file_exists($archivo_nuevo);


if($testf != 1)
	{
		sc_exec_sql("DELETE FROM BD_AD.log_ad WHERE id = " . {id} . " AND ad_file = '';");
		sc_alert('Error Archivo no fue renombrado correctamente, registro invalido trate de cargar de nuevo el archivo!');
	}
else
	{
		sc_alert('Archivo Digital ' . $nombre_nuevo . ' cargado y creado con exito. Gracias!!');

	/*
		sleep(10);

		// Redirection parameters
		$redir_app    = 'control_visor';  // Application name
		$redir_test   = {ad_file} != '';  // Redirection test
		$redir_target = '_self';  // Target window (_blank, _self, _parent or modal)
		$redir_param  = array(     // Param list, add as many as needed

		);

		// Redirection
		if ($redir_test)
		{
			sc_redir($redir_app, $redir_param, $redir_target);
		}	
	*/
	
	
	}

I have check it and now it is working only with file path. What us I store as type Document(Database) and I want to view it. How do I go abt viewing it without download?. When I select the pdf and save as type (Document Database) it give the filetype wt hyperlink. When click it goes to download.

You should not use Document(Database) if there are many files that are loaded in the database, that is not a good idea.

Work with Document(Filename) and with this you can create links to view the file in browsers without downloading them to view them.

1 Like