Hello,
We have a dxf file with raster image inserted.
We change the image dynamically as per the requirement and then convert dxf to pdf using our java application.
The image size will change when we create it. The current dxf to pdf prints the image to actual size
We need that the image should be fitted to its original length and width. How can we achieve the same
dxf with image.zip (612.8 KB)
@plunavat,
Can you please provide the used sample code that you have used to reproduce the issue. Please also first try using latest Aspose.CAD for .NET 20.6 on your end as well.
I have saved all the files from the zip file provided earlier in WebContent/DXFDrawings folder
Please find code below
public class ExportDXFDrawingToPDF {
public static void main(String[] args) {
System.out.println("start time:"+new Date());
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportDXFDrawingToPDF.class) + "DXFDrawings/";
//ExStart:ExportDXFDrawingToPDF
String srcFile = dataDir + "with logo.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(210);
rasterizationOptions.setPageHeight(297);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "with logo.pdf", pdfOptions);
//ExEnd:ExportDXFDrawingToPDF
System.out.println("end time:"+new Date());
}
@plunavat,
I can observe the issue in generated PDF and ticket with ID CADJAVA-751 has been created to further investigate and resolve the issue. We will share notification with you once issue will be fixed.
Hello,
Thanks for your feedback
This feature is very much important to us. We are looking to purchase the library, provided this feature is resolved
Thanks & Regards,
Pranav C Lunavat
@plunavat,
The issue has just been added in our issue tracking system. We request for your patience and will share feedback with you as soon as the issue will be fixed.
@plunavat,
We have verified the requirements w.r.t AutoCad 2019 behavior. It seems that the attached sample is has some incorrect internal data as different Autocad applications display it differently. Some even don’t display the image at all as well as rendering that. Therefore, we have the identical result as AutoCad 2019.
There is no dynamic option to achieve this. You will have to explicitly set bounds.
@mudassir.fayyaz
Thanks for your reply.
Could you please give some example of setting bounds using aspose code in java
@plunavat,
You may consider using following sample code on your end to serve the purpose.
using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
//get rasterimage entity for which we want to change export
CadRasterImage entity = (CadRasterImage) cadImage.Entities[cadImage.Entities.Length - 1];
//set clipping and boundaries
entity.ClippingState = 1;
entity.ClipBoundaryVertexList = new List<Cad2DPoint>() { new Cad2DPoint((double) 0,0), new Cad2DPoint(300,0), new Cad2DPoint(300,500), new Cad2DPoint(0,500) };
//now export
// cadImage.Save() ....
}
@mudassir.fayyaz
The above code is not solving my problem.
I need to fit the new image completely within my original space.
It can be done if we can set the width, height and scale of the image. Could you please let me know if we have the property in api for the same
RasterImage.PNG (246.7 KB)
if(entity.getTypeName()==CadEntityTypeName.IMAGE) {
CadRasterImage entity2 = (CadRasterImage) entity;
System.out.println(entity2.getInsertionPoint().getX());
}
In the above code we can get the insertion point of the image. similar can we set the length, width and scale of image
@velotech
I have added the feedback shared in our issue tracking system and will share the further response with you as soon as it will be shared after investigation.
Hello,
Any updates. we want to purchase the library provided this issue is solved
@velotech
At present the issue is still not fixed based on last observations shared by you. We will get back to you with feedback as soon as issue will be addressed.
@velotech
Can you please try using following sample code on your end.
//For example, we have raterimage entity:
CadRasterImage rasterImage = ((CadRasterImage) cadImage.Entities[0]);
//origin image file size is:
//Width = rasterImage.ImageSizeU
//Height = rasterImage.ImageSizeV
//Total width and Height displayed in Autocad is:
var autocadDisplayedWidth = rasterImage.UVector.X * rasterImage.ImageSizeU;
var autocadDisplayedHeight = rasterImage.VVector.Y * rasterImage.ImageSizeV;
//To change it on rendering, please apply the folowing code, for example:
rasterImage.UVector.X *= 2;
rasterImage.VVector.Y *= 2;
Hello @mudassir.fayyaz
Thanks for your response. I have tried the code and it works.
Just one more query how to get the image name
RasterImage name.PNG (35.8 KB)
In the attached image, “logo-n”
As i have multiple images in the file, I need to apply scale factor based on image name
This will solve all my issues
Thanks & Regards,
Pranav C Lunavat
Hello,
It would be of great help if you could let me know the code to get the rasterimage name
Thanks & Regards,
Pranav C Lunavat
@velotech
Actually, there is no property for this. Isn’t the same raster image file that you have loaded in your application.
Hello @mudassir.fayyaz
I have different (multiple) images in one dxf file.
Based on the image file name, I need to set the scale of the image as per the ratio of the dxf image width to actual image width.
In the attached dxf file i have 2 image.
- client.jpg
- billOfMaterial.jpg
now i want to set scale based on image name
CadImage cadImage = (CadImage) image;
for (CadBaseEntity entity : cadImage.getEntities()) {
if (entity.getTypeName() == CadEntityTypeName.IMAGE) {
CadRasterImage entity2 = (CadRasterImage) entity;
if (entity2.getImageName().equals("Client.jpg")) {
entity2.getUVector().setX(entity2.getUVector().getX() * 2);
entity2.getVVector().setY(entity2.getVVector().getY() * 2);
} else {
entity2.getUVector().setX(entity2.getUVector().getX() * 5);
entity2.getVVector().setY(entity2.getVVector().getY() * 5);
}
}
}
How can i get image name or image reference name something like entity2.getImageName().equals(“Client.jpg”)
multiple images.png (145.9 KB)
billOfMaterial.jpg (6.3 KB)
client.jpg (26.0 KB)
multiple images.zip (80.1 KB)
@velotech
I have added an issue with ID CADJAVA-826 in our issue tracking system to investigate the requirement further and make provision in API for this. We will get back to you feedback as soon as it will be shared.
Hello,
Apart from the image name, there should also be provision to set the path of the image.
I have attached the image of the autocad window for the same
considering the previous code. something like
entity2.setPath("c:/newfile.jpg")
Image Path.jpg (212.0 KB)