Hii
I have pdf scaling
tinyPdf.pdf (2.4 MB)
SampleExpected Pdf.pdf (6.1 MB)
issue with some cad files like when i try to convert from Dxf to Pdf
- I am getting tiny pdf images i have attached 2 pdfs one is tiny and other with expected.
- And for some cad files objImage.save(outputStream, pdfOptions); method takes too much time that gives this error :
18:41:55,584 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffffc0a8c865:-49bad931:66990ae5:132 in state RUN
18:41:55,585 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffffc0a8c865:-49bad931:66990ae5:132 invoked while multiple threads active within it.
18:41:55,586 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012381: Action id 0:ffffc0a8c865:-49bad931:66990ae5:132 completed with multiple threads - thread default task-9 was in progress with sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
com.aspose.cad.system.Threading.WaitHandle.waitAny(Unknown Source)
com.aspose.cad.system.Threading.WaitHandle.waitAny(Unknown Source)
com.aspose.cad.internal.b.d.a(Unknown Source)
com.aspose.cad.Image.a(Unknown Source)
com.aspose.cad.Image.save_internalized(Unknown Source)
com.aspose.cad.w.a(Unknown Source)
com.aspose.cad.internal.eK.b.a(Unknown Source)
com.aspose.cad.internal.eK.c.a(Unknown Source)
com.aspose.cad.Image.save(Unknown Source)
my code:
// Load the source CAD file
Image objImage = Image.load(filePath);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Create rasterization options and configure scaling
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite()); // Set background color if needed
rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor); // Ensure object colors are used
// Set the page size (A0) size in points)
rasterizationOptions.setPageWidth(3370); // A0 width in points
rasterizationOptions.setPageHeight(2384); // A0 height in points
// Ensure content fits within the page size
rasterizationOptions.setAutomaticLayoutsScaling(true);
rasterizationOptions.setNoScaling(false);
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Export CAD to PDF
objImage.save(outputStream, pdfOptions);
byte[] pdfBytes = outputStream.toByteArray();
try (PDDocument document = PDDocument.load(pdfBytes)) {
// Get the first page to set the view
PDPageTree pages = document.getPages();
PDPage page = pages.get(0);
// Set the destination to center of the page
PDPageXYZDestination dest = new PDPageXYZDestination();
dest.setPage(page);
// Calculate the center coordinates
float pageWidth = page.getMediaBox().getWidth();
float pageHeight = page.getMediaBox().getHeight();
int centerX = (int) (pageWidth / 2.0f);
int centerY = (int) (pageHeight / 2.0f);
System.out.println("CenterX: " + centerX + ", CenterY: " + centerY);
dest.setLeft(centerX);
dest.setTop(centerY);
dest.setZoom(1.0f); // Adjust the zoom level if necessary
// Set the open action
PDDocumentCatalog catalog = document.getDocumentCatalog();
catalog.setOpenAction(dest);
// Save the modified PDF
ByteArrayOutputStream modifiedOutputStream = new ByteArrayOutputStream();
document.save(modifiedOutputStream);