Hi
We have a requirement to add watermark in XML file using Aspose PDF api for Java.
When tried using Aspose PDF it gives error "Exception in thread “main” class com.aspose.pdf.exceptions.InvalidPdfFileFormatException: Incorrect file header
"
Which library should we use for adding watermark to an XML file.
Would you please share the sample files and the code snippet using which you tried to add watermark in XML file using Aspose.PDF for Java? We will test the scenario in our environment and address it accordingly.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE import-log>
-<import-log>
<begin-import timestamp="03/03/2023 02:38:27 PM GMT">Begin import.</begin-import>
<record-summary ignored="0" rejected="0" accepted="1" import-type="Item <Created>"/>
<record-summary ignored="0" rejected="0" accepted="1" import-type="Item"/>
<record-summary ignored="0" rejected="0" accepted="1" import-type="Bill of Material"/>
<note>The 'Part' object 'P0008' which doesn't exist in system was created during import.</note>
<end-import timestamp="03/03/2023 02:38:27 PM GMT" fatal="false">Complete import.</end-import>
</import-log>
This was the xml which I was trying
Code snippet used was:
Document doc = new Document("d:\\result.xml");
// Create a formatted text
FormattedText formattedText = new FormattedText("Confidential Document", java.awt.Color.RED, FontStyle.Courier, EncodingType.Identity_h, true, 40.0F);
// Create watermark artifact and set its properties
WatermarkArtifact artifact = new WatermarkArtifact();
artifact.setText(formattedText);
artifact.setArtifactHorizontalAlignment (HorizontalAlignment.Center);
artifact.setArtifactVerticalAlignment (VerticalAlignment.Center);
artifact.setRotation (25);
artifact.setOpacity (0.5);
artifact.setBackground (false);
// Add watermark to the first page of PDF
doc.getPages().get_Item(1).getArtifacts().add(artifact);
// Save watermarked PDF document
doc.save("D:\\out_result.xml);
We noticed that you are initializing Document with an XML file. Please note that you can do so but you also need a second argument i.e. XmlLoadOptions. But then your XML should be according to the Aspose.Pdf XML Schema. We are afraid that it would not be possible to achieve what you are expecting. In case we misunderstood your requirements, please let us know.
We do not think that your requirements would be able to achieve using any Aspose API. Are you using this XML to further convert it into another file format? How will the watermark look? Can you share your expected output?