How to insert a specified size image at a specified position on each page of an xps file

  • How to insert a specified size image at a specified position on each page of an xps file. I now need to insert images at specified locations on each page of the xps file with no loss of image resolution. Thank you all for your answers !

@good_luck

Please go through the below blog post in order to get the code snippet and examples of inserting image/text inside XPS documents:

I know the example, but the explanation of the API is too vague and some of the coordinate parameters are too abstract.

When I converted the xps files to images, I set the images to 300 and 600 resolutions, respectively, but the images were all saved the same size and at the same resolution.image.png (53.7 KB)

@good_luck

Can you please share your sample XPS and code snippet for our reference so that we can test the scenario in our environment and address it accordingly?

This is my code :
License license = new License();
license.setLicense(“E:\AIImageSys\newLineV2\AIImageSys\src\main\resources\license\AsposeLicense.lic”);

    String path = "C:\\Users\\86182\\Desktop\\BDD-E01600186222.xps";

    XpsDocument xpsDocument = new XpsDocument(path);
    PngSaveOptions pngSaveOptions = new PngSaveOptions();
    pngSaveOptions.setSmoothingMode(SmoothingMode.HighQuality);
    pngSaveOptions.setResolution(300);
    ImageDevice imageDevice = new ImageDevice();
    xpsDocument.save(imageDevice, pngSaveOptions);

    int count = xpsDocument.getPageCount();
    List<String> list = new ArrayList<>(count);
    for (int i = 0; i < imageDevice.getResult().length; i++){
        for (int j = 0; j < imageDevice.getResult()[i].length; j++){
            String fullPath = "C:\\Users\\86182\\Desktop\\xps-png\\" + "XPStoPNG400" + "_" + (i + 1) + "_" + (j + 1) + ".png";
            FileOutputStream imageStream = new FileOutputStream(fullPath);
            // Write image
            imageStream.write(imageDevice.getResult()[i][j], 0, imageDevice.getResult()[i][j].length);
            list.add(fullPath);
            imageStream.close();
        }
    }

@good_luck

At the moment, there is no way to change the size, but resolution can be changes as follows:

ImageSaveOptions options = new PngSaveOptions() { Resolution = 150; }

Furthermore, we request you please share your sample XPS and an expected output Image as well for our reference? We will log an investigation ticket and share the ID with you.

I set the resolution to 150,300,600. However, the resolution of the generated pictures is the same, and the pictures do not become clearer because of the change of the value. The picture generated by the three resolutions has the same effect of frame loss when enlarged to 150%, so it is not useful to set 150,300,600. Can you tell the reason?

@good_luck

We need to perform investigation for this case. Can you please share the sample source file for our reference? We will log an investigation ticket and share the ID with you.