Preserve DPI Resolution of Images during Word DOCX Document to PDF Conversion using Java | Down Sample Images

Dear Aspose Team,
I have issue in converting from doc\docx to pdf .
Issue 1::roll_eyes:
The input contains images and it converts the PDF file but during the conversion image DPI value is changed. How to solve the issue?
eg,
input Doc file image DPI value is :600 (horizontal resolution)
output pdf file image DPI value is : 299 (horizontal resolution)

Attached a sample input and actual output
Issue 1: Samples
DPI Issue.zip (4.6 MB)

@rjnick,

I have converted your DOCX to PDF format by using MS Word 2019 and Aspose.Words for .NET 19.8 versions and attached both the output PDF files here for your reference:

On what page in 19.8.pdf, the image has this problem? What steps did you perform to verify that the image in Aspose.Words generated PDF file has different DPI?

Also, I had used the following simple code to produce 19.8.pdf on my end.

Document doc = new Document(@"E:\DPI Issue\Input file.docx");
doc.Save(@"E:\DPI Issue\19.8.pdf");

Dear team,
i using aspose.words in java

@rjnick,

Sure, please provide Aspose.Words generated PDF file showing the undesired behavior here for our reference.

Please also provide answers to the following questions:

Dear @awais.hafeez
i use some code to verify the dpi value
String dataDir=“C:\Users\0015947\Desktop\Sample\DPI\Aspose output.pdf”;
// Open document
Document document = new Document(dataDir);

	// Create ImagePlacementAbsorber object to perform image placement search
	ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

	// Accept the absorber for first page
	document.getPages().accept(abs);

	// Display image placement properties for all placements
	for (Object imagePlacement : abs.getImagePlacements())
	{     
	    ImagePlacement placement = (ImagePlacement) imagePlacement;
	    System.out.println("image width:" + placement.getRectangle().getWidth());
	    System.out.println("image height:" + placement.getRectangle().getHeight());
	    System.out.println("image horizontal resolution:" + placement.getResolution().getX());
	    System.out.println("image vertical resolution:" + placement.getResolution().getY());
	}

@rjnick,

Aspose.PDF for Java 19.7 returns the following values for msw-2019.pdf (when running your code):

image width:231.60000610351562
image height:236.39999389648438
image horizontal resolution:220
image vertical resolution:219
image width:312.0
image height:231.60000610351562
image horizontal resolution:199
image vertical resolution:199
image width:311.989990234375
image height:231.35000610351562
image horizontal resolution:199
image vertical resolution:199

And the following values for awjava-19.8.pdf (791.0 KB)

image width:231.60000610351562
image height:236.40000915527344
image horizontal resolution:220
image vertical resolution:219
image width:312.0
image height:231.60000610351562
image horizontal resolution:300
image vertical resolution:299
image width:312.0
image height:231.36000061035156
image horizontal resolution:219
image vertical resolution:219

The numbers in bold are different. Please confirm, if this is the issue you are asking about?

Dear @awais.hafeez
the input file contains 3 images (dpi value is 600,300,600) .
after the conversion the pdf file contain 3 images but the dpi value is not same to the original source(doc file)

source image
300 DPI COLOR.jpg (234.8 KB)
600 DPI BW.jpg (108.7 KB)
600 DPI COLOR.jpg (1.6 MB)
input file input.zip (4.6 MB)

1 Like

@rjnick,

We have logged your problem in our issue tracking system. Your ticket number is WORDSNET-19057. We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for your inconvenience.

@rjnick,

Regarding WORDSNET-19057, by default Aspose.Words down-samples the images to 220 ppi resolution. It could be controlled by PdfSaveOptions.DownsampleOptions. To keep the images as is, you can disable down sampling with DownsampleOptions.DownsampleImages flag.

P.S. There may be misunderstanding. By down sampling resolution Aspose.Words means the ratio of the image size in pixel to the image size on document the page in inches. But by the DPI resolution you may mean the value stored in the image file. Aspose.Words tries to preserve the resolution value from the source image but it is not always possible due to PDF format peculiarity.

@rjnick,

Please check my previous message for analysis details and if there will be no other questions from your end then we will close this issue (WORDSNET-19057) as ‘Not a Bug’.

Dear @awais.hafeez
i tried above method but the result is not same

1 Like

@rjnick,

Can you please elaborate your question? What do you mean when saying ‘result is not same’?

Dear @awais.hafeez
i tried above method but the result is not same(original file dpi != output file dpi)

1 Like

@rjnick,

I am afraid, we do not see the DPI difference. Aspose.PDF returns the same values as in original images: 220 (despite your claim it is 600 the actual value in file is 220), 300 and 600. Please let us know if we can be of any further assistance.

Dear @awais.hafeez
Please check the below file with dpi 600 . The converted pdf do not gives the original dpi value.
Attached samples for your references,
Sample:
DPI ERROR.zip (5.9 MB)

1 Like

@rjnick,

We have converted your ‘input.docx’ document to PDF format by using the following Aspose.Words for Java code and attached the output PDF here for your reference: awjava-19.8.pdf (791.3 KB)

Document doc = new Document("E:\\Temp\\DPI Issue\\Input file.docx");
doc.save("E:\\Temp\\DPI Issue\\awjava-19.8.pdf"); 

Also, the ‘Actual Output.pdf’ was generated by using Aspose.PDF for Java 19.6 API. It may be because of that you are processing/saving PDF file with Aspose.PDF for Java.

1 Like

Dear @awais.hafeez

Above Code working fine but same issue is occur,
output pdf dpi value:

IMAGE 1
image width:231.60000610351562
image height:236.40000915527344
image horizontal resolution:220
image vertical resolution:219
IMAGE 2
image width:312.0
image height:231.60000610351562
image horizontal resolution:300
image vertical resolution:299
IMAGE 3 ====> Issue Occur
image width:312.0
image height:231.36000061035156
image horizontal resolution:219 ===>Original Value:600
image vertical resolution:219 ===>Original Value:600

1 Like

@rjnick,

Please try using the following code that will give correct DPI result in Aspose.PDF. Sorry for any misunderstanding.

Document doc = new Document("E:\\Temp\\DPI ERROR\\input.docx");
PdfSaveOptions opts = new PdfSaveOptions();
opts.getDownsampleOptions().setDownsampleImages(false);

doc.save("E:\\Temp\\DPI ERROR\\awjava-19.8-opts.pdf", opts);

com.aspose.pdf.Document document = new com.aspose.pdf.Document("E:\\Temp\\DPI ERROR\\awjava-19.8-opts.pdf");

// Create ImagePlacementAbsorber object to perform image placement search
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

// Accept the absorber for first page
document.getPages().accept(abs);

// Display image placement properties for all placements
for (Object imagePlacement : abs.getImagePlacements())
{
    ImagePlacement placement = (ImagePlacement) imagePlacement;
    System.out.println("image width:" + placement.getRectangle().getWidth());
    System.out.println("image height:" + placement.getRectangle().getHeight());
    System.out.println("image horizontal resolution:" + placement.getResolution().getX());
    System.out.println("image vertical resolution:" + placement.getResolution().getY());
}
2 Likes

Dear @awais.hafeez
it works fine for me, Thanks for Your Response.

1 Like

@rjnick,

Thanks for your feedback. In case you have further inquiries or need any help in future, please let us know.

1 Like