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

Free Support Forum - aspose.com

TextStamp FormattedText font style issue

Hi,

I’m trying to add watermarks to pages in a PDF using TextStamps. I want the watermarks to have a certain color and font, for that I use FormattedText options. It works well for the color but not the FontStyle. I’ve tried Helvetica, HelveticaBold and Courier, which the PDF format allegedly supports out of the box but the aspect on the final document doesn’t change, staying in what seems to be some Times-ish font.

Also worth mentioning is that our PDFs also include imported HTML with css-defined fonts (mainly Arial) and these fonts are preserved in the rendered document contrary to TextStamp fonts.

The problem has been showing up since I upgraded to Aspose.Pdf 8.2.0 but wasn’t occuring with my previous version (7.6.0).

Thanks for your help.

Guillaume


Simplified version of the code we use is in attachment

Well I got to the point where HTML rendering in a PDF seems totally undeterministic to me.

Turns out the solution I had posted there (adding   to avoid text overlapping) doesn’t work as expected any more.

Basically,


header



country name




Other fieldset


will have “country name” overlapping “Other fieldset”, way lower than it should be,


header



country name



 


Other fieldset


once worked properly, but now there’s a huge blank space below “header”, and “country name” is clinging to “Other fieldset” 2 pixels above it, not overlapping but much too close,



header





country name



aDiv



  


Other fieldset


has the same problem, plus “aDiv” is rendered above “country name” instead of being under !


Hi Guillaume,


Thanks for using our products.

We are working over this query and will get back to you soon. We apologize for this delay and inconvenience.

Any news ?

It’s been a while since I’ve posted the original message, we can’t release our application with misformatted PDFs. Especially considering the HTML we use displays perfectly well in a browser.

Thanks

Hi Guillaume,


Sorry for the delayed response.

In recent times, I have got busy with some other priority queries and I am afraid I could not spend much to replicate these issues. However I am currently working over these queries and will get back to you soon.
GuillaumeL:
Well I got to the point where HTML rendering in a PDF seems totally undeterministic to me.

Turns out the solution I had posted 481352, I am unable to notice any text overlapping issue. Can you please share the HTML which can help us in replicating this issue at our end. We apologize for this inconvenience.

[C#]

// will generate pdf fom html file<o:p></o:p>

string theHTMLFilename = @"C:\pdftest\sample.html.txt";

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

pdf.HtmlInfo.PageWidth = 5000;

pdf.ParseToPdf(theHTMLFilename);

//Save the pdf document

pdf.Save(@“C:\pdftest\HTMLConversion_v8.2.0.pdf”);

GuillaumeL:
I’m trying to add watermarks to pages in a PDF using TextStamps. I want the watermarks to have a certain color and font, for that I use FormattedText options. It works well for the color but not the FontStyle. I’ve tried Helvetica, HelveticaBold and Courier, which the PDF format allegedly supports out of the box but the aspect on the final document doesn’t change, staying in what seems to be some Times-ish font.
Hi Guillaume,

I have tried replicating the issue based on code snippet which you have shared but there were some unspecified/undeclared variables/methods, so I could not replicate the issue using that code. However, I tried replicating the issue using following simple code and as per my observations, the text is appearing font which is used in FormattedText(…) constructor. For your reference, I have also attached the resultant PDF file generated over my end, using Aspose.Pdf for .NET 8.2.0.

[C#]

//Create pdf document

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Set the conformance property of Pdf class to predefined value

pdf1.Conformance = Aspose.Pdf.Generator.PdfConformance.PdfA1B;

//Add a section into the pdf document

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

sec1.PageInfo.Margin = new Aspose.Pdf.Generator.MarginInfo { Top = 72, Bottom = 72, Left = 40, Right = 40 };

var htmlContent = " ";

var text2 = new Text(sec1, htmlContent);

// enable the property to display HTML contents within their own formatting

text2.IsHtmlTagSupported = true;

// Add the text object containing HTML contents to PD Sections

sec1.Paragraphs.Add(text2);

var streamForPdf = new MemoryStream();

pdf1.Save(streamForPdf);

//open document

Document pdfDocument = new Document(streamForPdf);

var formattedText = new FormattedText("Sample String", System.Drawing.Color.Blue, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 16);/* embedded */ //, textSize: options.FontSize);

//create text stamp

TextStamp textStamp = new TextStamp(formattedText);

//set whether stamp is background

textStamp.Background = true;

//set origin

textStamp.XIndent = 100;

textStamp.YIndent = 100;

//add stamp to particular page

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

//save output document

pdfDocument.Save("c:/pdftest/TextStamp_output.pdf");

streamForPdf.Close();