Converting DWG file to PDF file

Where can we reach the maximum limits (Width, Height) when we convert the DWG file to pdf, tiff, jpg, png? I have a large dwg file and when I create a PDF I can’t get past 5 meters

@ugur.acarr1453
Maybe it just hangs for some document? Please attach the document and code used for which the conversion does not work.

Hi,
Sample code is as follows;
After getting the height and width of the DWG, CadRasterizationOptions.PageWidth and PageHeight
I define

string sourceFilePath = @“C:\Users\uacar\Desktop\Klasörler\Proje ve Excel’ler\Karabağlar Belediyesi\Özgür Bey DWG Projeler\3058 ADA 13 PARSEL_recover.dwg”;
string outPath = @“C:\Users\uacar\Desktop\Test\6.pdf”;
var cadImage = (CadImage)Aspose.CAD.Image.Load(sourceFilePath);

        int genislik = cadImage.Size.Width;
        int yukseklik = cadImage.Size.Height;

        //genislik = genislik / 50;
        //yukseklik = yukseklik / 50;

        CadBaseEntity[] entities = cadImage.Entities;
        List<CadBaseEntity> filteredEntities = new List<CadBaseEntity>();

        List<CadBaseEntity> orderedEntities = new List<CadBaseEntity>();

        foreach (CadBaseEntity entity in cadImage.Entities)
        {
            if (entity.TypeName == CadEntityTypeName.TEXT)
            {
                // Yazıları önce ekleyin
                orderedEntities.Add(entity);
            }
        }

        foreach (CadBaseEntity entity in cadImage.Entities)
        {
            if (entity.TypeName != CadEntityTypeName.TEXT)
            {
                // Diğer çizim öğelerini (örneğin, çizgiler) sonra ekleyin
                orderedEntities.Add(entity);
            }
        }

        cadImage.Entities = orderedEntities.ToArray();

        // Create an instance of CadRasterizationOptions and set its various properties
        Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions =
        new Aspose.CAD.ImageOptions.CadRasterizationOptions();
        rasterizationOptions.PageWidth = genislik;
        rasterizationOptions.PageHeight = yukseklik;

        rasterizationOptions.DrawColor = Color.Black;
        // Set Auto Layout Scaling
        rasterizationOptions.AutomaticLayoutsScaling = false;
        rasterizationOptions.Quality.TextThicknessNormalization = true;

        Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
        pdfOptions.VectorRasterizationOptions = rasterizationOptions;

        string outFile = outPath;

        // Export the CAD to PDF
        cadImage.Save(outFile, pdfOptions);

@ugur.acarr1453
And please attach the document with which this happens.

Hi,
It’s like sharing links.

The dwg I want to translate and the pdf I converted are available in the link.

If you don’t receive the file I can send it by email.

Thanks.

@ugur.acarr1453
I apologize for not seeing it right away - you wrote in the wrong section. The Aspose.Pdf library does not implement the dwg → pdf conversion. I will transfer your question to the appropriate section, everything that was written will be saved in the topic

@ugur.acarr1453,
Hello.
There is a limitation for PDF 1.5 and some viewers to have page size not more than 200x200 inches, that’s why the drawing is scaled up to this size at max. Scaling to raster has no such limitation.

Hello,
Thank you for the replies. Is there any sample code?

@ugur.acarr1453,
Hi.
Could you please clarify your requirements? What do you want to achieve for this drawing?

Hello,
I want to convert large A0 projects in DWG format to pdf or tif format with a scale of 1:50. Projects are generally 10 meters and above.

We will put an electronic signature on the pdf or tif we produce.

When courts or government institutions request physical projects or when they will be in the buildings belonging to the project, we will print them from the same scale physical printer and process them.

@ugur.acarr1453,
OK, could you please help me out a bit and provide what is the exact size of this DWG project in meters or mm?

The file is attached.
(Cad Image cad Image = (CadImage)Image.Load(source FilePath)
cadImage.Width:154555
cadImage.Height:38136.

I have sent you the height and size of the entire drawing.

I can only convey the area belonging to the Project.

@ugur.acarr1453,
yes, I can see the file and these values. You said the projects can be 5 meters, 10 meters, so in order to scale them down with 1:50 ratio we need to understand the initial size. Width and Height value are not meters, that’s why I am asking.

Hello,
You are right.

If I can convert to large pdf or tif, the next step will be to take the start and end values ​​of the project in the dwg and reflect the layers there only to pdf.

@ugur.acarr1453,
So, the initial size of the drawing is

int genislik = cadImage.Size.Width; // 154555
int yukseklik = cadImage.Size.Height;// 38136

and the unit type is millimeters, so we condiser this drawing to be approx. 155k x 38k millimeters.

The maximum allowed PDF now is 200 x 200 inches, that is 5080 x 5080 mm.

So, if you set up these values into the export options size:

CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.PageWidth = genislik;
rasterizationOptions.PageHeight = yukseklik;

the height and width go beyond the allowed size. So the drawing is scaled down automatically to fit 200 inches and you can see its final size 5076 x 1252 mm.

In case we decrease the width and height:

genislik = genislik / 50; // 3091
yukseklik = yukseklik / 50; // 762

corresponsing size is 3091 x 762 mm and it fits the 200 inches limitation. So the final size of PDF now is 3091 x 762 mm.

Some few additional notes:

  • there is a separate tiny entity to the right of the drawing, it significantly increases the size;
  • I found useful to add this code to make lines thin:
  foreach (CadLayerTable layer in cadImage.Layers)
  {
      layer.LineWeight = 0;
  }

  foreach (CadEntityBase entity in cadImage.Entities)
  {
      entity.LineWeight = 0;
  }