How to Apply Hatch Patterns to DXF Polyline Layers Using Aspose.CAD and Ensure They Are Visible in Output PDF

Hello Aspose Support Team,

I am using Aspose.CAD for Java to process a DXF file, and I want to apply hatch patterns (like SOLID or ANSI31) to specific polyline layers (e.g., "BLK_1_COVERED_AREA", "CONCRETE" etc.). My goal is to:

  1. Programmatically add hatch patterns to polylines in the DXF.
  2. Convert the modified DXF to PDF and visually verify that hatches are applied in the resulting PDF.

I’ve attempted this using the CadHatch class and attached it to polyline entities, but the hatch patterns are not visible in the output PDF or saved DXF.

My questions are:

  1. Is this the correct approach to programmatically apply hatches to CadLwPolyline entities in a DXF using Aspose.CAD?
  2. If yes, what properties or method calls must be correctly set to ensure the hatches are rendered in the output?
  3. Is hatch rendering in DXF-to-PDF conversion fully supported by Aspose.CAD?
  4. If not, is there any recommended workaround (e.g., layering hatch via Aspose.PDF after conversion)?
  5. Can you provide a working code sample that demonstrates visible hatch application to DXF polyline entities and conversion to PDF?

Any guidance would be greatly appreciated.

Thank you,

@johnhedo,
Hello.
1.Yes, it is correct, but hatch is an entity complex enough to create.
2-3. I’m afraid there is no ready answer. Hatches are supported well for export. But if some properties for them are not set - they could be ignored as malformed for instance.
4. There is no workaround, it is hard to predict the reason as hatches could be just ignored or failed when saved to DXF or during export, I guess you can do nothing with PDF in this case.
5. The example here could be useful, please check.

It is the best if you can create some simple DXF file with polyline, show us code sample how you add hatch and export it and attach everything here, so we can test creation, saving and export on our side to see the problem directly and propose a solution or fix the bug.

ok here is zip file with sample java code and sample Dxf file.
Hatch.zip (332.1 KB)

@johnhedo,
We are able to create SOLID hatches with the following modifications, could you please check on your side.

Switch to work with DxfImage instead of CadImage:

// Load DXF
DxfImage cadImage = (DxfImage) Image.load(dxfPath);

Use adding entities with existing method instead of modification Entities collection directly:

for (CadEntityBase newHatch : newHatches)
{
	cadImage.addEntity(newHatch);
}

Switch type of hatch to solid:

hatch.setPatternName("SOLID"); // Try "SOLID" to test

But this is not helpful for ANSI31 type, so we have created CADJAVA-11975 to investigate this better.

which specific version are you using…?

Loading DXF file…

DXF file loaded successfully.

Original entity count: 2

Entities count: 0

Layer name: 0

Layer name: 0

Total entities after adding hatches: 4

Saving to PDF…
this are my logs but hatching is not reflecting in PDF

I recently upgraded to Aspose.CAD version 25.3. After the upgrade, I observed the following:

  1. Hatching is now rendering properly, which is a positive improvement.
  2. However, I’m facing two issues:
  • I am able to access only 100 entities from my DWG/DXF file, despite the file containing more than 100. This limitation did not exist before the upgrade.
  • The generated PDF contains cross marks (X-marks) over the entire page, which were not present before.

Could you please clarify the following:

  • Is there a default limit on the number of entities that can be accessed in version 25.3? If so, how can I remove or configure it?
  • Are these issues related to evaluation or license limitations?
  • What steps should I take to generate a clean PDF output without cross marks and to access all entities in the CAD file?

@johnhedo,
yes, these are license limitations. You need to apply at least free evaluation license to process more than 100 entities in Entities collection and remove crosses.