How to push drawing down the page to add custom heading

Hello,
I am converting a dwg file to a pdf. Then I need to insert a heading (“CAD Drawing”) at the very top of the page. As you can see in this image: image.png (46.5 KB)
the text is over the image. My question is how to push the drawing down and so to have space for the heading. Here is the code I am using:

using (Aspose.CAD.Image cadImage = Aspose.CAD.Image.Load(cadFile))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions
{
PageWidth = cadImage.Width * 3 + 20,
PageHeight = cadImage.Height * 3,
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor,
GraphicsOptions = new GraphicsOptions
{
TextRenderingHint = TextRenderingHint.SingleBitPerPixel,
},
Zoom = 1f,
};

  var opt = new PdfOptions { VectorRasterizationOptions = rasterizationOptions};
  cadImage.Save(tempPath, opt);

}

Aspose.Pdf.Document doc6 = new Aspose.Pdf.Document(tempPath);
var pg = doc6.Pages[1];
Heading title = new Heading(1);
title.Text = “CAD Drawing”;
title.HorizontalAlignment = HorizontalAlignment.Center;
title.TextState.FontSize = 30;
pg.Paragraphs.Insert(0, title);
doc6.Save(outputPath);

@mpogorelov,

Can you please confirm if you i understood correct that you want to first convert file to PDF than add heading in that PDF.

Yes, that is correct.

@mpogorelov

Please note that existing contents can be moved in DOCX files but not in PDF files because the content is present as plain text on the page. Neither the API knows boundaries of existing paragraphs, images etc so you may not be able to push contents.in PDF documents.

Can I do something in Aspose.CAD.Image object prior to conversion to pdf ?
Or let me rephrase the whole question, how can I create a pdf page that has a heading text and cad drawing based on a source dwg file?
Than you

@mpogorelov,

Can you please share source dwg file and desire output so that we may further investigate to help you out.

Sure, here is the dwg: Test Project.zip (24.9 KB)
It should look something like this:image.png (72.2 KB)

@mpogorelov,

Thank you for sharing requested files. I have shared sample code with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.addText.zip (835 Bytes)

This line:
string nextHandle = ((CadStringParameter)cadImage.Header.HeaderProperties[CadHeaderAttribute.HANDSEED][0]).Value;
throws exception “The given key was not present in the dictionary”:
image.png (312.8 KB)

@mpogorelov,

Can you please share the working sample code reproducing the issue on your end that we may test on our end to help you further.

I just inserted the code sample you sent me into my code. Here is the function where I am using it:function.zip (1.1 KB)

@mpogorelov,

Thank your for the attachment file. Unfortunately, I am unable to open the shared file. Can you please provide the working sample project along with source file that is actually reproducing in your environment so that we may proceed further with investigation on our end.

@mudassir.fayyaz
I’ve created a sample project. Please see the attached zip file:CADtoPDFconversion.zip (28.3 KB)

@mpogorelov,

I have worked with sample project shared by you using Aspose.CAD 19.9 and unable to observe any exception. I have also shared my generated result with you for your kind reference. Please check attachment.tmp.pdf (396.3 KB)

@Adnan.Ahmad, tried 19.9 version and works!
Thank you

@mpogorelov,

Thank you for sharing the feedback.

@Adnan.Ahmad, how could I move the text a bit down so its not right on top of the page?

@mpogorelov,

Yes, you may change text height using code that i have shared with you. Please share feedback with us if there is still an issue.

@Adnan.Ahmad
Text height controls the size of the text, I need something like Margin.Top to move the text a bit down.

@mpogorelov,

I like to inform that you need to position text. Please modify following in the sample which i have shared with you so that you may get your desire position of text.

text.SecondAlignmentPoint