We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add rotated text to existing PDF - Rotate Text to 90 Degrees in PDF using Aspose.PDF for .NET

I can add text to an existing pdf, using the following pattern

  
  ...
  // doc in an instance of Aspose.Pdf.Document
  // pageIndex in as int
  var textFrag = new TextFragment("sample text") {
    Position = new Position(100, 100)
  };
  var builder = new TextBuilder(doc.Pages[pageIndex]);
  builder.AppendText(textFrag);
  ...

Now I was asked to add some text rotated at 90 degrees counterclockwise, but I’ve found no options to set text orientation added this way.



Is it possible?
If not, how can I get the same result using a different approach?

Hi Riccardo,

Thanks for using our products.

You can use the Table or Floating Box, if you are creating PDF documents from scratch. Kindly visit the following documentation links for more details and code snippets.

Or, if you are using the existing documents then you can add text using text stamp. For more details, please visit: Adding Text Stamp in the PDF File

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

Thanks for your suggestion; it worked!

I’ve noticed that adding vertical text using timestamps results in much
larger files, while the same text added normally (ie non-rotated) does
not.

Is there a way to overcome this problem?

Is it
possible to combine the two approaches, ie using Aspose.Pdf.Generator.*
to add vertical text to an instance to Aspose.Pdf.Document?

As a
side note, I’ve seen lots of Operator.* classes which are almost
undocumented, except for obvious and trivial explanation or samples to handle images. Is there any
source code illustrating other usage?

Hi Riccardo,


We are testing this scenario at our end and will get back to you soon with our findings. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

rioka68:
I’ve noticed that adding vertical text using timestamps results in much
larger files, while the same text added normally (ie non-rotated) does
not.
Hi Riccardo,

Thanks for your patience.

I have tested the scenario using Aspose.Pdf for .NET 7.2.0 where I have used the following code snippet to add the Watermark text over existing PDF file and as per my observations, the resultant PDF containing rotated watermark has similar size as compare to the output file containing normal(non-rotated) watermark text. Can you please share the code snippet which you are using, so that we can again test the scenario at our end.

[C#]

//open document<o:p></o:p>

Document pdfDocument = new Document("d:/pdftest/SVGConversion-test.pdf");

//create text stamp

TextStamp textStamp = new TextStamp("Sample Stamp");

//set whether stamp is background

textStamp.Background = true;

//set origin

textStamp.XIndent = 100;

textStamp.YIndent = 100;

//rotate stamp

textStamp.Rotate = Rotation.on90;

//set text properties

textStamp.TextState.Font = FontRepository.FindFont("Arial");

textStamp.TextState.FontSize = 14.0F;

textStamp.TextState.FontStyle = FontStyles.Bold;

textStamp.TextState.FontStyle = FontStyles.Italic;

textStamp.TextState.ForegroundColor = System.Drawing.Color.Aqua;

//add stamp to particular page

pdfDocument.Pages[1].AddStamp(textStamp);

//save output document

pdfDocument.Save("d:/pdftest/Stampled_output_90Degree-Rotation.pdf");



rioka68:
Is it possible to combine the two approaches, ie using Aspose.Pdf.Generator.* to add vertical text to an instance to Aspose.Pdf.Document?

Aspose.Pdf.Generator specifically provides the support for creating PDF documents from scratch. Whereas Aspose.Pdf.Document supports the feature to create as well as manipulate existing PDF documents. I am afraid Aspose.Pdf.Generator can not accept an object of Aspose.Pdf.Document and perform some operations on input document. Nevertheless, you may consider creating a PDF file using Aspose.Pdf.Generator, save the output in Stream object and then initialize Document object with the Stream object. In case of any related query, please feel free to contact.

rioka68:
I As a side note, I've seen lots of Operator.* classes which are almost undocumented, except for obvious and trivial explanation or samples to handle images. Is there any source code illustrating other usage?
We are working on creating sample against all Operator classes and as soon as we have some updates, we would be more than happy to update you with the status of correction. However at the moment, you can find a usage example of some of these classes over Add Image in an Existing PDF File

We are sorry for your inconvenience.