Hello,
Hi Hiren,
//source PDF file <o:p></o:p>
java.io.File file = new java.io.File("C:\\pdftest\\aspose_html_content\\aspose_html_content.html");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
//System.out.println(file.exists() + "!!");
//InputStream in = resource.openStream();
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
//Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
System.out.println("read " + readNum + " bytes,");
}
} catch (java.io.IOException ex) {
}
byte[] bytes = bos.toByteArray();
//instantiate Document Object with ByteArrayInputStream while passing byte array as argument
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(new java.io.ByteArrayInputStream(bytes), new com.aspose.pdf.HtmlLoadOptions());
//get the page count of PDF file
System.out.println(doc.getPages().size());
doc.save(“C:\pdftest\aspose_html_content.pdf”);
Thanks for providing the code snippet. It worked and PDF file was generated.
Hi Hiren,
Please share some details regarding your requirement on setting styles and formatting of PDF document. Meanwhile you may consider exploring API document for further details on Working with Document Object
Now as per your requirement on rendering PDF file on client side, you need to save the output in Stream object and then pass the stream to client browser.
Hello,
Hi Hiren,
Thanks for sharing the resource files.
As per my understanding, in order to generate required document, you need to place Image and text in Header and Footer section, create table object with Text and a graphic object to show current assets. You can also define the formatting (Font Face, Font size, Color etc) of text when placing it inside table object. Please visit the following links for required information on
- Add Text to an existing PDF file
- Working with Tables (DOM)
- Adding Text in Header or Footer of PDF File
- Add Image Stamp in PDF File
- Control Image Quality when Adding Stamp
In case of any further query, please feel free to contact.
PS, in order to define text formatting, you may consider adding HTML text inside PDF file where text will be rendered in native HTML tag instead it appears as static HTML tags. For more information, please visit Add HTML String using DOM