Hello Aspose Team,
When lines are drawn using the PDFContentEditor, user was able to move the line when rendered in Acrobat Version 11.
Please help us in getting this issue resolved.
The code we use is as below,
InputStream is = new ByteArrayInputStream(baos.toByteArray());
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf(is);
Rectangle rect=new Rectangle();
int []dashArray={};
String []LEArray={}; editor.createLine(rect,"",x1,y1,x2,y2,pageNum,2,āsā,dashArray,LEArray,Color.BLACK);
editor.save(os);
Thanks,
Ashok
Hi Ashok,
Hello Aspose Team,
Thanks for your response.
We have to restrict both selction and movement.
Kindly help us on that regard.
Immediate response would be appreciated.
Thanks,
Ashok
Hi Ashok,
Thanks for sharing the details.
In order to restrict the modification of contents (movement of line annotations), you can apply security restrictions over PDF file. In order to fulfill this requirement, PdfFileSecurity class can be used. However in recent release of Aspose.Pdf for Java, PdfPrivilege enumeration is not ported which exists in legacy Aspose.Pdf.Kit for Java.
For the sake of correction, I have logged this issue as PDFNEWJAVA-33831 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.
For your reference, I have also attached the resultant PDF file generated with the following code snippet, based on Aspose.Pdf.Kit for Java.
[Java]
// input PDF file
String inFile = "c:/pdftest/LineAdded.pdf";
// resultant PDF file
String outFile = "c:/pdftest/FileSecurity_kitOut.pdf";
// instantiate PdfFile Security object
com.aspose.pdf.kit.PdfFileSecurity fileSecurity = new com.aspose.pdf.kit.PdfFileSecurity(inFile, outFile);
// set restrictions over PDF file. **Pdf** Contents cannot be modified
fileSecurity.setPrivilege(com.aspose.pdf.kit.PdfPrivilege.ModifyContents | com.aspose.pdf.kit.PdfPrivilege.ScreenReaders);
Hello Aspose Team,
I used the above lines of code.
But still we were able to move the lines.
Following are the lines of code we used,
if(null==pdfDocument){
pdfDocument = new Document();
}
System.out.println("Pdf document existing page count " + pdfDocument.getPages().size());
for(int i=0; i<totalPage;i++){
pdfDocument.getPages().add().setPageSize(PDFGenConstants.pageWidth, PDFGenConstants.pageHeight);
}
pdfDocument.save(tempPdfFileName);
com.aspose.pdf.kit.PdfFileSecurity fileSecurity = new com.aspose.pdf.kit.PdfFileSecurity(tempPdfFileName, tempPdfFileName);
// set restrictions over PDF file. Pdf Contents cannot be modified
try {
fileSecurity.setPrivilege(com.aspose.pdf.kit.PdfPrivilege.ModifyContents);
} catch (PdfKitException e) {
throw new ServiceException(PDFGenErrorConstants.RBUILDER_PDFGEN_FAILED, "Setting Security Previlage Failed " + e.getMessage(), e);
} catch (IOException e) {
throw new ServiceException(PDFGenErrorConstants.RBUILDER_PDFGEN_FAILED, "Settign Security Previlage Failed " + e.getMessage(), e);
}
For your reference am attaching the pdf generated.
Please open the pdf in X1 version.
Hi Ashok,
Thanks for sharing the resource file.
I have tried viewing the PDF document which you have shared in Adobe Reader 11.0.3 and I am able to move the line annotations. However, I have used the following code snippet to apply restrictions over the PDF document while using Aspose.Pdf.Kit for Java 4.7.0 and, as per my observations, the restrictions are properly being applied and I am unable to move the lines. For your reference, I have also attached the resultant PDF generated on my end.
[Java]
// load input PDF file
FileInputStream in = new FileInputStream(new File("c:/pdftest/aspose(1).pdf"));
// instantiate PdfContentEditor instance
com.aspose.pdf.facades.PdfContentEditor editor = new com.aspose.pdf.facades.PdfContentEditor();
// bind the source PDF file
editor.bindPdf(in);
Rectangle rect = new Rectangle();
int[] dashArray = {};
String[] LEArray = {};
editor.createLine(rect, "", 100, 100, 200, 200, 1, 2, Color.BLACK, "s", dashArray, LEArray);
// instantiate ByteArray OutputStream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// save the file to Stream object
editor.save(baos);
// instantiate Object OutputStream so that contents of ByteArray can be loaded
ObjectOutputStream os = new ObjectOutputStream(baos);
os.writeObject(new java.util.Date());
os.close();
// save the contents into Byte array object
byte[] data = baos.toByteArray();
// load the contents of Byte array to ByteInput Stream
ByteArrayInputStream bis = new ByteArrayInputStream(data);
// instantiate PdfFile Security object
com.aspose.pdf.kit.PdfFileSecurity fileSecurity = new com.aspose.pdf.kit.PdfFileSecurity(bis, new FileOutputStream(new File("c:/pdftest/SecureFile.pdf")));
// set restrictions over PDF file. Pdf Contents cannot be modified
fileSecurity.setPrivilege(com.aspose.pdf.kit.PdfPrivilege.ModifyContents | com.aspose.pdf.kit.PdfPrivilege.ScreenReaders);
Hi Ashok,
Thanks for your patience.
As the autported MergedAPI of Aspose.Pdf for Java is ported from Aspose.Pdf for .NET, so there has been a change in class names and enumerations. PdfPrivilege came to DocumentPrivilege according to .NET version.
[String inFile = "c:/pdftest/Alignment_DOM.pdf";
[String outFile1 = "c:/pdftest/TestEncrypt1.pdf";
com.aspose.pdf.facades.PdfFileSecurity fileSecurity =
[new com.aspose.pdf.facades.PdfFileSecurity(inFile, outFile1);
// PdfPrivilege came to DocumentPrivilege, true -> KeySize.x128
fileSecurity.[encrypt](null, "mypassword",
[com.aspose.pdf.facades](Class).DocumentPrivilege.getScreenReaders(), [com.aspose.pdf.facades](Class).KeySize.x128);
fileSecurity.close();
[String outFile2 = "c:/pdftest/TestEncrypt2.pdf";
com.aspose.pdf.facades.PdfFileSecurity fileSecurity2 =
[new com.aspose.pdf.facades.PdfFileSecurity]([inFile, outFile2]);
fileSecurity2.[encryptFile]("", "owner",
[com.aspose.pdf.facades](Class).DocumentPrivilege.getAllowAll(), [com.aspose.pdf.facades](Class).KeySize.x128);
// was PdfPrivilege.AllowAll
fileSecurity2.close();
[String outFile4 = "c:/pdftest/TestEncrypt4.pdf";
com.aspose.pdf.facades.PdfFileSecurity fileSecurity4 =
[new com.aspose.pdf.facades.PdfFileSecurity]([inFile, outFile4]);
fileSecurity4.[encryptFile]("user", "owner",
[com.aspose.pdf.facades](Class).DocumentPrivilege.getCopy(), [com.aspose.pdf.facades](Class).KeySize.x40);
// was PdfPrivilege.Copy
fileSecurity4.close();