Free Support Forum - aspose.com

Font and page layout problem while convert doc to pdf

Hi,
I am using word template with mail merge fields on it. I am using font "Franklin Gothic Medium" of size 8 in word template. Output to ASPOSE.word looks fine but when converts to ASPOSE.pdf font changed to "TimeNewRomanPSMT" and on second page top margin almost double to original and one extra blank page at end of document.
My question is how can i use embedded font in word that integrate to pdf?
code sample;

doc.MailMerge.Execute(ds.BarcodeTable);

doc.MailMerge.DeleteFields();

SendToBrowserAsPdf(doc);

Many thanks

Syed

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please also attach your template for testing?

Best regards.

Thanks for your quick reply.
I have attached zip file one is doc template and other files generated by ASPOSE.word and ASPOSE.pdf. You can clearly see difference.

Hello Syed!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional materials. Let’s consider your questions in the original order:

1. You are writing that font changes from "Franklin Gothic Medium" to "TimeNewRomanPSMT". I see that font is different in the document before conversion and in PDF. But I cannot reproduce this issue on the latest versions of Aspose components. When I convert to Aspose.Pdf XML intermediate format everything comes out in "Franklin Gothic Medium". You can check this by converting the document to Aspose.Pdf XML and opening as text. Contents should look like this:

<Segment FontName="Franklin Gothic Medium" FontSize="8">FUN WITH STENCILS

If you are getting different result then you are using an older version of Aspose.Words. If result is the same then it should be fixed in Aspose.Pdf.

Please check versions of both Aspose.Words and Aspose.Pdf. We always recommend upgrade to the latest versions of components especially if this solves particular problems.

2. Regarding more vertical space on the top of the second page I see the problem. The reason is not top margin because the both sections have the same page setup. I’m pasting section start tags just to compare and ensure they are the same:

First:

Second:

As you can see there are different numbers of barcodes fit on one page in DOC and PDF. The best way is to experiment with this. At last we can ask Aspose.Pdf Team for advice.

3. Currently it is impossible to embed font during PDF conversion. You can suggest installing that font.

Regards,

Thanks Klepus,

I upgraded aspose.word to latest version and font problem solved. It looks fine on my development machine but when i uploaded to web server it still showing wrong font. I installed ‘Franklin Gothic Medium’ on web server but no luck. I have checked bin folder and ‘Aspose.Words.dll’ has latest version 5.2.0.0.

Do i need to install ‘Aspose.Words.dll’ on web server?

Blank page is still there at bottom.

Please give suggestion.

Regards

Syed



Hello!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for upgrading Aspose.Words.

Issue with font should be considered to fix in Aspose.Pdf since Aspose.Words outputs correct fonts. I’ll write to Aspose.Pdf developers and ask for their advice.

Regarding extra page you can try removing section break between the two pages (why is it needed?) and either make cells smaller or slightly extend page margins. The table doesn’t fit on page. If this doesn’t help we’ll also ask Aspose.Pdf developers how to deal with this.

Regards,

Thanks Klepus,

I am not properly getting your mean by section break between two pages. I am word template that contains one page. I have to follow template for print labels.

Also I noticed after installing ‘Franklin Gothic Medium’ pdf font changed to ‘Arial MT’ very strange. Everything fine for Aspose.words. Please can you look or need this raise on Aspose.pdf?

Regards

Syed

Hi again!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I’ve already written an e-mail to Aspose.Pdf Team addressing this thread. They will inspect this and answer you shortly. If they don’t we’ll remind them or post to their forum.

Since we are discussing the conversion to PDF I investigated the document immediately before conversion (Aspose.Words.Demos.doc). If you set larger scale, say 500%, and choose displaying non-printable characters by pressing button with ¶ you will see both section break between pages and paragraph break at the very end of the document. They both are very small, font size = 1 point. You cannot remove paragraph break at the end since it is a constraint but you can decide whether you need or don’t need extra section break.

In the template there is only one section. I wonder how you get a document with two sections from this template after mail merge. Let’s start getting right with this question. I expect you perform any other manipulations on the template. Please provide me the full code fragment from the point you open the template to the point you save the resulting document.

You can try removing one row from the table in the template. This extra page can be also avoided by removing blank table rows at the end of resulting document. That’s not so difficult to determine whether some row is blank. For this purpose you can traverse and check all cells in a row. Empty cell can contain only one child and it should be an empty paragraph.

Regards,

Hi Klepus,
I checked section and paragraph break as you mentioned. I wonder word template doesn’t have section break but when doc generated by aspose.word add section break for next page. You are right document has one section actually mail merge persists in table columns instead of sections.

Please guide me how can I remove empty rows because if data not exists it still write empty rows at end of page that mainly cause for blank page in pdf. I am stuck at this point. Please check attached file for code etc.

Many thanks

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can try using the following code to remove empty cells from the table.

Document doc = new Document(@"Test194\in.doc");

//Get tables from your document

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);

//Loop through all tables

foreach (Table tab in tables)

{

bool isEmpty = true;

//Check if last cell contains data

while (isEmpty)

{

//Loop through all paragraphs in the last cell

foreach (Paragraph par in tab.LastRow.LastCell.Paragraphs)

{

//Chech if paragraph has child

isEmpty = !par.HasChildNodes;

if (!isEmpty)

break;

}

if (isEmpty)

{

//Remove the last cell if it is empty

tab.LastRow.LastCell.Remove();

//Remove last row if it doesnot contain cells

if (!tab.LastRow.HasChildNodes)

tab.LastRow.Remove();

//Break while if table does not contains rows

if (!tab.HasChildNodes)

break;

}

}

}

//Save output document

doc.Save(@"Test194\out.doc");

Hope this helps.

Best regards.

Great stuff Alexey,

Empty table cells deleted and no more blank page.

I have only font problem now. When doc convert from Apose.Word to Aspose.Pdf font changed from ‘Franklin Gothic Medium’ to ‘Arial’.
Any suggestion please…
Regards
Syed

I added pdf.SetUnicode() before pdf.save(…) and that fixed font problem.
Thanks guys for your help.