We are trying to create an auto-download for our client to combines database information with an uploaded Word document. We are currently using the following code to create the first page of the PDF:
// Create a pdf docuemnt object
Pdf pdf = new Pdf();
// Base directory of local images,
pdf.FoImagePath = MapPath(".");
// Bind XML & XSL file into the Pdf instance using BindFo
pdf.BindFO(xmlResult, xslPath);
pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = Path.GetTempPath();
I can also create a Word Document and check it’s pageCount. If doc.pagecount > 4 our client ONLY wants us to append the first four pages to the pdf document for their review.
How do I truncate an Aspose.Words document and then append it to the pdf file we’ve created thus far?
Hi
Thanks for your request. You can use code like the following:
Document doc = new Document(@"test001\in.doc");
// Save 10 pages of the document to PDF.
PdfSaveOptions opt = new PdfSaveOptions();
opt.PageIndex = 0;
opt.PageCount = 10;
doc.Save(@"Test001\out.pdf", opt);
I’m obviously NOT asking my question correctly …
I have an Aspose.Words Document object - I need to be able to add up to 4 pages of this word document to another PDF document. How do I get the Aspose.Words Document Object, into an Aspose.Pdf object? All this did was put a blank pdf file on my desktop. I don’t want a pdf file on my desktop, I need an Aspose.Pdf object so that I can then use Aspose.Pdf.Kit to concatenate it with another Aspose.Pdf object … does that make sense???
Hi there,
Thanks for this additional information.
Yes this is what we have been suggesting. Please see the code below which demonstrates how to combine an output PDF from Aspose.Words with another PDF using Aspose.Pdf.Kit.
Document attachedDoc = new Document(file.Stream);
if (attachedDoc.PageCount> 4)
{
attachPageCount = 4;
}
else
{
attachPageCount = attachedDoc.PageCount;
}
using(Stream stream = File.Create(MyDir + "trial.pdf"))
{
PdfSaveOptions attachedToPDF = new PdfSaveOptions();
attachedToPDF.PageIndex = 0;
attachedToPDF.PageCount = attachPageCount;
attachedDoc.Save(stream, attachedtoPdf);
stream.Seek(0, SeekOrigin.Begin);
}
// Instantiating PdfFileEditor object using Aspose.Pdf.Kit
PdfFileEditor editor = new PdfFileEditor();
// Create an output stream object that will store the combined PDF to disk.
FileStream outputStream = new FileStream("Document out.pdf", FileMode.Create);
// Store all input streams in an Array
Stream[] inStreams = new Stream[]
{
stream,
otherPdfStream
};
// Call the Concatenate method
editor.Concatenate(inputStreams, outputStream);
// Close streams
stream.Close();
otherPdfStream.Close();
outputStream.Close();
If you have any further queries, please feel free to ask.
Thanks,