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

Free Support Forum - aspose.com

Converting plain text to pdf adds blank page in the end

Hi,

When i'm converting a plain text file to pdf, changing font, fontzise and color is working fine, but in the end always a blank page is added. I've added 2 attachements with source and result.

Off course it is possible to remove the last page from the pdf, but I prefer to have the correct page count directly after conversion. Please help me to fix this.

Code snippet

private const string textFont = "Arial";
private const int textSize = 10;
private Color textColor = System.Drawing.Color.Black;

...

// read bytearray into Aspose Doc
Document doc;
using (MemoryStream stream = new MemoryStream(file))
{
doc = new Document(stream);
}

// create new empty Doc and a DocBuilder
Document newDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(newDoc);

// Specify font formatting before adding text.
Aspose.Words.Font font = builder.Font;
font.Size = textSize;
font.Color = textColor;
font.Name = textFont;

// write text from doc into newDoc
builder.Write(doc.GetText());

// and save into stream and pdf
MemoryStream newstream = new MemoryStream();
newDoc.Save(newstream, SaveFormat.Pdf);

Hi,


Thanks for your inquiry. Please use Document.ToString() method instead of GetText(). Here is how you should use it:

builder.Write(doc.ToString(SaveFormat.Text));

Best regards,

Thanks, problem solved!