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

Free Support Forum - aspose.com

Text to PDF Alignment Not working

Hi,


Here i have tried to convert .txt file to .jpg, .pdf and .tiff.

a.).txt to .jpg(working)
b.).txt to .tiff(working)
c.).txt to .pdf(Alignment was not working properly)

jpeg and tiff files are looks identical but for PDF half of the paragraph is printing in the previous pages itself.

Also attached the Input/Output files

CODE:
var pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.PageIndex = 2;
pdfSaveOptions.PageCount = 1;
var height = PageSize.A4Height;
var width = PageSize.A4Width;
var doc = new Document(inputFilePath);
var builder = new DocumentBuilder(doc);
builder.Font.Size = 4;
builder.PageSetup.PageWidth = width;
builder.PageSetup.PageHeight = height;
doc.UpdatePageLayout();
doc.Save(outputFilePath, pdfSaveOptions);
Hi Aravind,

Thank you for your inquiry and sharing details.

This is to update you that your inquiry is related to Aspose.Pdf API. I am moving your thread to Aspose.Pdf support forum where my colleague from Aspose.Pdf support team will answer your query and guide you accordingly.

Hi Aravind,


Thanks for your inquriy. I am afraid the attachment is corrupted due to some reason. I will appreciate it if you please send your input/output documents again, so we will look into it and will guide you accordingly.

We are sorry for the inconvenience.

Best Regards,

Attached the input/output files for your reference



Thank you.

Hi Aravind,


Thanks for sharing the source documents again. We will appreciate it if you please share your sample code for TEXT to TIFF and JPEG, it will help us to replicate your issue and address it accordingly.

However, I have tested the TEXT to PDF and TIFF conversion using your above code and unable to notice the reported formatting issue on page 3.

//Text to TIFF<o:p></o:p>

var pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();

var doc = new Aspose.Words.Document("TEXT.txt");

var builder = new DocumentBuilder(doc);

builder.Font.Size = 4;

builder.PageSetup.PaperSize = Aspose.Words.PaperSize.A4;

doc.UpdatePageLayout();

doc.Save("test.tiff", Aspose.Words.SaveFormat.Tiff);

//Text to PDF

var pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();

pdfSaveOptions.SaveFormat = Aspose.Words.SaveFormat.Pdf;

var doc = new Aspose.Words.Document("TEXT.txt");

var builder = new DocumentBuilder(doc);

builder.Font.Size = 4;

builder.PageSetup.PaperSize = Aspose.Words.PaperSize.A4;

doc.UpdatePageLayout();

doc.Save("test.pdf", pdfSaveOptions);.

Best Regards,

Hi Tilal


var pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();<o:p></o:p>

var doc = new Aspose.Words.Document(“TEXT.txt”);<o:p></o:p>

var builder = new DocumentBuilder(doc);<o:p></o:p>

builder.Font.Size = 4;<o:p></o:p>

builder.PageSetup.PaperSize = Aspose.Words.PaperSize.A4;<o:p></o:p>

doc.UpdatePageLayout();<o:p></o:p>

doc.Save(“test.tiff”, Aspose.Words.SaveFormat.Tiff);


var text = new Document(inputFilePath);
var options = new ImageSaveOptions(SaveFormat.Tiff);
options = new ImageSaveOptions(SaveFormat.Tiff) { PageCount = 1 };
options.PageIndex = 3;
options.Resolution = 300;
text.Save(outputFilePath, options);


when using your code its working fine but when put options instead of Aspose.Words.SaveFormat.Tiff ,thats the problem in alignment

Hi Aravind,

Thanks for sharing the detail. Please use the ImageSaveOptions and PdfSaveOptions as shown below to get the same output in PDF and TIFF.

You are getting different output in PDF file because you are setting the PaperSize as PaperSize.A4 for PDF document. Please note that Aspose.Words mimics the same behavior as MS Word does. If you open the TEXT file in MS Word and change the paper size, you will get the same output.

Document text = new Document(MyDir + "TEXT.txt");

text.FirstSection.PageSetup.PaperSize = PaperSize.A4;

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);

options.PageIndex = 2;

options.PageCount = 1;

options.Resolution = 300;

text.Save(MyDir + "17.3.0.tiff", options);

PdfSaveOptions Pdfoptions = new PdfSaveOptions();

Pdfoptions.PageIndex = 2;

Pdfoptions.PageCount = 1;

text.UpdatePageLayout();

text.Save(MyDir + "17.3.0.pdf", Pdfoptions);