HI Support Team,
We have paid version of aspose PDF library, and we are generating PDF by adding content as Text and Images,
While adding large dimensions(example 3264x1838 and 3000x4000) images It is rotated. Same code snippet working for for rest of the images(small in dimensions).
How to resolve this issue.
And Is there any restriction of image dimensions for PDF like Word and what is the minimum image dimensions aspose PDF support.
@maheshpg17
There is no such limitation in the API about image dimensions. You can set page height and width as per image dimensions while adding image in the PDF like below code snippet:
private void AddImageInPDF()
{
BufferedImage readImage = null;
try
{
readImage = ImageIO.read(new File(dataDir + "chq.jpg"));
int h = readImage.getHeight();
int w = readImage.getWidth();
//java.io.InputStream stream3 = new java.io.FileInputStream(dataDir + "Annotation 2022-11-23 111626.png");
Document doc = new Document();
Page page = doc.getPages().add();
com.aspose.pdf.Image image = new Image();
image.setFile(dataDir + "chq.jpg");
page.getPageInfo().setHeight(h);
page.getPageInfo().setWidth(w);
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setRight(0);
page.getPageInfo().getMargin().setLeft(0);
page.getParagraphs().add(image);
//page.addImage(stream3 ,new com.aspose.pdf.Rectangle(0,0,200,200));
doc.save(dataDir + "ImagetoPDF.pdf");
}
catch (Exception e)
{
readImage = null;
e.printStackTrace();
}
}
Hi @asad.ali,
Thanks for the reply.
The Solution you suggested will not work, It will create issue with different dimensions of each page as Images have.
We need symmetricity among pages dimensions in pdf document.
We are resizing image dimensions by calculation ratio between page height & width and image height & width.
Note: In MSPaint, I have open the image which has rotation issue and just saved it, With no other action performed, and After that image started working fine like other images.
@maheshpg17
Would you please share your sample PDF and images with us along with the code snippet that you are using? Also, please share some screenshots of the issue that you are facing so that we can test the scenario in our environment and address it accordingly.
Hi @asad.ali,
Below is code, Image and OutputPdf
abc.jpg (1.1 MB)
public fun main() {
setAsposeLicense()
val imagePath = "applications/route-approval-pdf/abc.jpg"
val routeApprovalDocument = Document()
val imgRe = ImageIO.read(File(imagePath))
val page = routeApprovalDocument.pages.add()
page.pageInfo.height = imgRe.height.toDouble()
page.pageInfo.width = imgRe.width.toDouble()
val imageAsTable = Table()
val row: Row = imageAsTable.rows.add()
val img = Image().apply {
horizontalAlignment = HorizontalAlignment.Center
margin = MarginInfo(PAGE_MARGIN_LEFT, PAGE_MARGIN_BOTTOM, PAGE_MARGIN_RIGHT, PAGE_MARGIN_TOP)
file = imagePath
fixHeight = imgRe.height.toDouble()
fixWidth = imgRe.width.toDouble()
}
val cell = row.cells.add()
cell.apply {
width = imgRe.width.toDouble()
paragraphs.add(img)
}
page.apply {
paragraphs.add(imageAsTable)
}
routeApprovalDocument.save("applications/route-approval-pdf/output.pdf")
}
output.pdf (5.2 MB)
@maheshpg17
We tested the scenario in our environment using 23.4 version of the API and obtained similar output that you have shared. However, we could not notice the image was rotated in the PDF. It was shrunk though. Is it the original issue that you are facing? You want image to be fit on the entire page?
@asad.ali, Please have a look at attached Image and PDF
In Pdf Image rotated 180 degree i.e. Top becomes bottom and bottom become top.
I have tested with the updated version i.e. 23.4 as well as with 22.8 result is same as attached in above comment output.pdf.
@maheshpg17
Please check the attached PDF generated in our environment. The image is not rotated in it. Can you please share your environment details like OS Name and Version, Application Type, Java Version, etc. We will further proceed with the investigation. output.pdf (2.1 MB)
Hi @asad.ali, I am unable to send/upload the actual Image it seems, The image above attached is modified while uploading and its actual size is reduced from 2.59MB to 1.06MB.
Can you please give your email Id so that I can send this Image as attachment. and What time you are available to get sync and resolve the issue.
mine: mahesh.gupta@openreach.co.uk.
Thanks,
Mahesh
@maheshpg17
We appreciate providing support and communicate through our dedicated support forum. In case image size is getting modified while uploading, please upload it to Google Drive or Dropbox and share the link with us. We will again test the case in our environment and share our feedback with you accordingly.
It would not be possible to attend to your issue only as we have to take care of other inquiries as well form our other customers. Furthermore, we follow a policy of first come first serve here and you can feel free to post. We will try our best to reach you as soon as possible while following our schedule.
@maheshpg17
We are sending you a private message where you can share a public link to access the image. The image link you shared requires a valid login. As we mentioned earlier, it would not be possible for us to share email address as we appreciate communication via our dedicated forums.
@maheshpg17
We have received your image files in private message. We are testing the scenario and will get back to you shortly.
Hi @asad.ali,
Any update on this, it is a critical live issue. Need your support on urgent basis please help us.
I found few things based on its EXIF info it is rotating.
Thanks,
Mahesh Gupta.
@maheshpg17
We were able to reproduce the issue with one of the images you shared (i.e. WIN_20230221_13_49_49_Pro.jpg) while using 23.5 version of the API.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-42867
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Hi @asad.ali,
We already have a licence of Aspose PDF,
Is is require to purchases support service too?
Please let us know, What we have to purchase else apart from Aspose PDF lincence?
@maheshpg17
The subscription to paid support service is purchased separately. In case the issue is a showstopper for you and it needs to be resolved on urgent basis, you can please contact in our Purchase forum in order to purchase paid support subscription.
Once you have paid support access, you can create a topic there with the reference to the Ticket ID logged here and your issue will be escalated to the highest priority accordingly.
Hi @asad.ali,
Any update when it will fix or fix version date for this issue?
@maheshpg17
We are afraid that the ticket has not been yet resolved due to other pending issues in the queue. We will surely inform you once we make some progress towards ticket resolution. Please spare us some time.
We are sorry for the inconvenience.
Hi @asad.ali,
Any update on this issue please?
Thanks
Mahesh.
@maheshpg17
The issue with image rotation was fixed. But there is an issue with the width of an image in the table. This issue is blocked by PDFNET-55284.
Now your can get the desired result with imageAsTable.setColumnWidths(Integer.toString(imgRe.getWidth()))
String imagePath = dataDir + "WIN_20230221_13_49_49_Pro.jpg";
Document routeApprovalDocument = new Document();
BufferedImage imgRe = ImageIO.read(new File(imagePath));
Page page = routeApprovalDocument.getPages().add();
page.getPageInfo().setHeight(imgRe.getHeight());
page.getPageInfo().setWidth(imgRe.getWidth());
Table imageAsTable = new Table();
imageAsTable.setColumnWidths(Integer.toString(imgRe.getWidth()));
Row row = imageAsTable.getRows().add();
Image img = new Image();
img.setHorizontalAlignment(HorizontalAlignment.Center);
img.setMargin(new MarginInfo(0,0,0,0));
img.setFile(imagePath);
img.setFixHeight(imgRe.getHeight());
img.setFixWidth(imgRe.getWidth());
Cell cell = row.getCells().add();
//cell.setWidth(imgRe.getWidth());
cell.getParagraphs().add(img);
page.getParagraphs().add(imageAsTable);
routeApprovalDocument.save(dataDir + "output_WIN_20230221_13_49_49_Pro.pdf");
output_WIN_20230221_13_49_49_Pro.pdf (1.1 MB)