We are investigating replacing Office Automation with Aspose.Total. Our current solution uses printing to print office docs to an imaging printer driver, because we really need images. Aspose has image conversion functionality with their renderers that could/should suit our needs. We would like to convert to PDF as our output format.
Word printing has an option called “Scale to Paper Size”, that resizes each page to fit the selected paper size, and we extend this functionality to our users. Does Aspose implement anything similar? Aspose provides RenderToScale, but that requires you to render each page to a graphic device (bitmap), not a PDF.
How can I render an entire document to a PDF, with each page’s contents scaling to match the desired paper size?
image.png (7.8 KB)
@PaulWendt,
Thanks for your inquiry. You can convert Word document to PDF and also save its pages to images. Please read following article.
Rendering and Printing
You can change the paper size of document and convert the final document to PDF. Please check the following code example. Hope this helps you.
Document doc = new Document(MyDir + "in.docx");
foreach (Section section in doc.Sections)
{
section.PageSetup.PaperSize = Aspose.Words.PaperSize.A4;
}
doc.UpdatePageLayout();
doc.Save(MyDir + "out.pdf");
Oh, thank you very much for your response. The point of the “Scale to Paper Size” option is to ensure that rendered content is scaled to match the page, as it is printed. If I have elements that go outside of the paper size, I need some code to readjust them, to fit the paper size. The option “Scale to Paper Size” from Word does that; how can we do something similar with Aspose?
I included an attached document with a table that goes off of the page. If I use Word to print this with “Scale to Paper Size”, the table’s size is automatically altered so that it is rendered on the printed page.
I’d like to do the same thing with the PDFs we output via Aspose. Is such a thing possible?
CutoffTable.zip (9.1 KB)
@PaulWendt,
Thanks for your inquiry. In your case, we suggest you please use Document.Print Method (PrinterSettings) to print the document according to the specified printer settings, using the standard (no User Interface) print controller. You can set the PrinterSettings according to your requirement.
Thank you. However, the “Scale to Paper Size” is an option available via Word Automation, not the printer driver. How can I perform similar functionality using Print via Aspose?
@PaulWendt,
Thanks for your inquiry. You can create the printer setting as shown below and pass it to Document.Print method.
PrinterSettings printsetting = new PrinterSettings();
System.Drawing.Printing.PaperSize size = new System.Drawing.Printing.PaperSize("First custom size", 800, 200);
printsetting.DefaultPageSettings.PaperSize = size;
@PaulWendt,
Further to my previous reply, there are different ways to achieve your requirement. You can change the paper size of document as shared in my post and print the document.
https://forum.aspose.com/t/scale-to-paper-size/180073/2?u=tahir.manzoor
You can also fit the content of table according to page’s size as shown below.
Document doc = new Document(MyDir + "CutoffTable.docx");
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
table.AutoFit(AutoFitBehavior.AutoFitToWindow);
}
doc.Print();
Moreover, you can change the page’s width and height and print it. Please check the following code example.
Document doc = new Document(MyDir + "CutoffTable.docx");
foreach (Section section in doc.Sections)
{
section.PageSetup.PageHeight = 500;
section.PageSetup.PageWidth = 950;
}
doc.Print();
Hi,
I wanted to press further with this. Here is thh difference in your solution and what Paul was asking for:
Find attached test document. It is set for paper size tabloid (11x17) and landscape orientation.
In Word if I choose print as is, it will print 3 pages.
In Word if I choose to print and scale to Letter (8.5x11) I will get the same information on each page and it will still print out 3 pages (scaled).
If I just choose to change paper size to Letter, it will not have the same information on each page and it will print out 5 pages. (same as your soution)
Do you have a way to scale to page now?
If no, do you plan on having this feature in the future?
Thank You,
CharlesMyTestDoc.zip (351.0 KB)
@ccuster68
Please note that Aspose.Words uses .NET printing API to print the document. Please try Document.Print method (PrinterSettings) to print the document according to the specified printer settings, using the standard (no User Interface) print controller.
You want to scale the content according to specific paper size. You can achieve it by using the solutions shared in my previous posts. Could you please share what issue you are facing? Have you tried Document.Print method (PrinterSettings)?
Hi Tahir,
I am not looking to print the document using another driver (although I know you can with an output of pdf). I am looking at using your document.save method to save the document as a pdf (or png) file. In Word, there is an option to scale to paper, that is not the same printer settings(driver), but only in Word settings.
The results are different. To be specific, in Word you can go to print the document, and under Settings (Word Settings) you can choose to “Scale to Paper size”.
Referencing the attached pictures:
ScaleToPaper1.jpg shows a normal print and shows it on 11x17 paper size and that it will print 3 pages.
ScaleToPaper2.jpg shows 11x17 paper size and the Word Settings of Scaled to 8.5x11, and it will still print the exact same content on 3 pages, but on 8.5x11.
ScaleToPaper3.jpg shows if you change the paper size to 8.5x11, it prints different content on 5 pages.
There is no other way to make ScaleToPaper2.jpg scenerio without the word settings (that I know of). Additionally we are looking for the speed and consistency of document.save method over printing.
It sounds like you do not support this yet, I was seeing if you would support this in the future or not.
Thank you for your replies,
CharlesScaleToPaper.zip (489.3 KB)
@ccuster68
Please note that “Scale To Paper Size” is MS Word (Application) level setting and does not store in the document. Therefore it cannot be controlled by Aspose.Words. This is completely controlled by the MS Word.
However, you can change the page size of document using Aspose.Words and save it to DOCX, PDF, PNG etc.
A post was split to a new topic: Scale to Paper Size