This project provides additional functionalities to work with PDF files (.NET and Java generators for GeneXus 9.0 or higher). To download this project go to GeneXus Marketplace
- Add password (ModifyPermissions)
- Digitally sign a document (AddSignature)
- Concatenate several pdf files (ConcatFiles)
- Modify permissions (printing and allow copying text) (ModifyPermissions)
- Add a watermark (AddWatermark)
- Get Text (GetText) (2)
- PDF pages count (PageCount)(1)
- Load fields (SetFields)(1)
- Generate a PDF from a Tiff file(TiffToPdf)(1)
- Add a text to a PDF(3)
- Convert Html in a PDF (Html2PDF)(4)
Check the detail here
// Concat Files EXAMPLE
&files.Add("…DocIn01.pdf") // &files is a character Collection variable
&files.Add("…DocIn02.pdf")
&files.Add("…DocIn03.pdf")
&res = &PDFTools.ConcatFiles(&files,"…DocOut.pdf") // &PDFTools is PDFTools type (External Object)
msg(&res)
Notice that if an incoming Pdf file is signed, the resulting PDF is not signed and will need to be signed again (for the complete content).
// Modify Permissions EXAMPLE
&permisson.Add(PDFpermission.AllowCopy) // &permisson is a numeric Collection
&permisson.Add(PDFpermission.AllowPrinting)
&res = &PDFTools.ModifyPermissions("…DocIn.pdf","…DocOut.pdf","pass",&permisson) // &PDFTools is PDFTools type (External Object)
msg(&res)
// Modify Add Signature EXAMPLE
&res = &PDFTools.AddSignature("…DocIn.pdf","…DocOut.pdf","…CertificatePath","pass",&IsVisible)
// Certificate in PFX format only – Password only if required
// isVisible = true -> show a mark in the PDF
Verify that you have the PDFManager External Object.
&PDFText = ""
&PDFText = &PDFManager.GetText(&PDFPath)
if (&PDFManager.Error)
msg(format("Type:%1 Dsc:%2",&PDFManager.ErrorType,&PDFManager.ErrorDescription))
endif
Verify that you have the PDFAddWatermark procedure.
PDFAddWatermark.Call(&PathSource,&PathTarget,&image,20,20)
where &PathSource references the origin file, &PathTarget the destination file, &image the image taken as a reference to the watermark.
When using the PDFAddWatermark option add the following to the C# compiler options
/r:bin\itextsharp.dll
&res = &PDFTools.PageCount(&PathSource)
msg(format("PageCount:%1",&res),status)
It is important to emphasize that the PDF using as input has to be generated with a tool that has already defined the controls in the Form. The SetFields method simply assigns values to controls by name. Examples of how to generate a PDF with controls can be seen here and here.
&AttId = !"CustomerNameField"
&AttValue = !"Joe Doe"
&properties.Set(&AttId.Trim(),&AttValue.Trim()) // &properties is based on GX Properties data type
&res = ""
&res = &PDFTools.SetFields(&SourcePDFPath,&TargetPDFPath,&properties)
if not (&res.IsEmpty())
msg(format("Error:%1",&res))
endif
&files.Add("C:\temp\sample1.tif")
&files.Add("C:\temp\sample2.tif")
&res = &PDFTools.TiffToPdf(&files,"C:\temp\sample3.pdf")
msg(format("Result:%1",&res),status)
&result = &PDFTools.AddText(&PDFIn, &PDFOut, &X, &Y, &PageNumber, &Text, &fontSize)
Based on a Variable containing Html code, it will generate a PDF file. You can use it as follows:
&result = &PDFTools.Html2PDF(&Content, &TargetPath, &FontPath)
where:
- &Content details the Html code.
- &TargetPath defies a full path location where the PDF will be generated.
- &FontPath defines a full path for a font location, such as "c:/windows/fonts/l_10646.ttf", if not specified the Arial Unicode font is selected ("c:/windows/fonts/ARIALUNI.TTF").
- &result defines possible error codes, empty if there is no error.
To be able to sign a pdf you must use a file with the pfx format, the following link details how to generate it http://www.tech-pro.net/export-to-pfx.html
When executing, the following error may occur in the document's signature:
java.io.IOException: exception unwrapping private key - java.security.InvalidKeyException: Illegal key size
It is necessary to update the security of the Virtual Machine Java as detailed here.
Download the jar that corresponds to "Unlimited Strength Jurisdiction Policy Files" from http://java.sun.com/javase/downloads/index.jsp in the section "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files" and apply it.
In some cases the following error can occur when using the C# generator:
Type:Exception Dsc:The invoked member is not supported in a dynamic assembly
change the machine.config file with the following:
<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
You can find machine.config here.
32-bit
%windir%\Microsoft.NET\Framework\[version]\config\machine.config
64-bit
%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
In some cases the following error can occur when using the getText method in Java:
java.lang.NoClassDefFoundError: org.bouncycastle.cms.CMSException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.pdfbox.pdmodel.encryption.SecurityHandlersManager.class$(SecurityHandlersManager.java:84)
Download the following .jar from bcmail-jdk15-140.jar and copy it to the lib directory of the WebApp.
If using the GetText function the error is detailed:
Type:Exception Dsc:null
Replace the PDFBox-0.7.3.jar file with the following file: http://www.apache.org/dyn/closer.cgi/pdfbox/1.7.0/pdfbox-app-1.7.0.jar
Compiling a C# project the following error occurs:
error CS0246: The type or namespace name 'SdtPDFManager' could not be found (are you missing a using directive or an assembly reference?)
Make sure the PDFManager.dll file is located on the target Environment Directory \bin folder.
Compiling a Java project the following error occurs:
SdtPDFManager.java:120: error: cannot find symbol
public pdftools.PDFTextHandler getExternalInstance( )
^
symbol: class PDFTextHandler
location: package pdftools
Make sure the pdfwrapper.jar and dependencies (Font*.jar, PDFBox*.jar) files are located on the target Environment Directory \web\drivers\ folder.
Compiling the PDFAddWatermark the following error is detailed:
error CS0234: The type or namespace name 'lowagie' does not exist in the namespace 'com' (are you missing an assembly reference?)
Make sure to update the PDFAddWatermark object to the latest version, use version 2.3.4 or higher (for example PDFTools_2.3.4_AddWatermark.xpz file)
Compiling in a Java environment the following error occurs:
com\proyecto\pdfaddwatermark.java:86: error: package com.lowagie.text.pdf does not exist
com.lowagie.text.pdf.PdfReader reader = new com.lowagie.text.pdf.PdfReader(AV12PathSource);
Add the iText.jar to the Classpath property.
Using GeneXus v16 upgrade #9 and the C# generator with IIS 32 bit enabled the following error appears
Type:Exception Dsc:No se admite el miembro invocado en un ensamblado dinámico
Modify the machine.config file for the 32 bits framework, add the followint entry within the <runtime> tag
<loadFromRemoteSources enabled="true" />
Since GeneXus 17 upgrade 8 the iTextsharp.dll was updated from 5.5.8.0 to 4.1.6.0 because of the license agreement (more information on SAC#50700). Use the PDFTools_2.3.7.1_Csharp.zip marketplace download which solves the case otherwise the following error will appear:
[FileLoadException: Could not load file or assembly 'itextsharp, Version=5.5.8.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
PDFTools_iTextSharpLib.iTextSharpUtil.ModifyPermissions(String PathSource, String PathTarget, String UserPassword, List`1 Permissons) in iTextSharpUtil.cs:301
GeneXus.Programs.SdtPDFTools.modifypermissions(String gxTp_PathSource, String gxTp_PathTarget, String gxTp_UserPassword, GxSimpleCollection`1 gxTp_Permissons) +124
https://github.com/ladrians/PDFTools_iTextSharpLib C# implementation
https://github.com/ladrians/PDFTools_iTextJavaLib Java implementation
NetCore generator is not supported, the following error appears
Could not load file or assembly 'itextsharp, Version=5.5.13.1, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'. The system cannot find the file specified.
(1) - Available since PDF Tools 2.2
(2) - Available since PDF Tools 2.3.2
(3) - Available since PDF Tools 2.3.4
(4) - Available since PDF Tools 2.3.6
Since Xev2u3 itext* dependencies for C# where updated in GeneXus forcing the regenerate the wrapper DLL.
- up to xev2u2 itextsharp.dll 4.0.2.0
- since xev2u3 itextsharp.dll 5.3.5.0
Use PDFTools_2.3.0_CsharpDependencies_xev2u3.xpz for Xev2u3 or higher versions and PDFTools_2.3.0_CsharpDependencies_xev2u2.xpz for Xev2u2 and lower versions. The error detailed:
Could not load file or assembly 'itextsharp, Version=4.0.2.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
AddSignature method added to declare the rectangle and page number.
AddText method added to insert a text in a specific PDF page and position.
Another AddText method to insert a text in a specific PDF page and position (angle and RGB).
Add Html2PDF new method.
The following error appears when using version 2.3.6 and GeneXus 16 Upgrade #9 with Java
javax.servlet.ServletException: java.lang.NoSuchMethodError: org.bouncycastle.util.encoders.Hex.toHexString([B)Ljava/lang/String;
...
java.lang.IllegalStateException: java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\PDFtoolsU9JavaSQLServer\WEB-INF\lib\bcprov-jdk15on-1.60.jar (The system cannot find the file specified)
...
java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\PDFtoolsU9JavaSQLServer\WEB-INF\lib\bcprov-jdk15on-1.60.jar (The system cannot find the file specified)
To solve the issue
- Import the PDFTools_2.3.7_JavaDependencies.xpz
- Remove the files bcpkix-jdk15on-1.60.jar, bcprov-jdk15on-1.60.jar or bcprov-ext-jdk14-145.jar, bcprov-jdk14-145.jar (this depends on the previous PDF tools version and GX used) from
- The Knowledge Base (File resources)
- \target environment folder\web\drivers
- \tomcat web application\WEB-INF\lib
- Since GeneXus 16 Upgrade #9 the valid files must be bcprov-jdk15on-1.64.jar and bcpkix-jdk15on-1.64.jar or higher.
Recompile the objects using the external object.
Download the PDFTools_2.3.7.1_Csharp.zip when using GeneXus 17 Upgrade #8 or higher with C#.