Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Aug 13, 2018 7:19 pm

I need to save a page range using the .SaveToFile(). All of the options work for this function EXCEPT the page range version. Doing anything with the function results in an "The file format is incorrect." error.

Example:

Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument(Filename);
document.SaveToFile("C:\\Temp\\foo.pdf",0,0, Spire.Pdf.FileFormat.PDF);


Please let me know if I'm doing anything wrong but it's a pretty straightforward call 8)

I tried V 4.7 and am currently on 4.8.5.2040

shoppas
 
Posts: 3
Joined: Mon Aug 13, 2018 5:08 pm

Tue Aug 14, 2018 6:02 am

Hello Shoppas,

Thanks for your letter.
Please kindly note that the function SaveToFile(string filename, int startIndex, int endIndex, FileFormat fileFormat) currently only supports saving PDF to SVG. If you want to save a page range to PDF, Please refer to the following tutorial on website for the details. If there is any doubt, just feel free to contact us.
Split PDF into Multiple PDFs using a Range of Pages in C#, VB.NET

Thanks and Regards
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Tue Aug 14, 2018 3:59 pm

I tried using that and now it generates a PDF file that is unreadable. The original file has 2 invoices in it and I need to separate them out individually.

Original PDF size 26K. Each resulting single page is 6K and un-readable.

I can email you the original PDF's so you can see if you can get them to separate correctly, but the cod I'm using is pretty straight forward.

Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument(Filename);
Spire.Pdf.PdfDocument documentToSave = new Spire.Pdf.PdfDocument();
Spire.Pdf.PdfPageBase newPage = null;

Spire.Pdf.Widget.PdfPageCollection PDFPages = document.Pages;

foreach (Spire.Pdf.PdfPageBase page in PDFPages)
{
//Get Invoice Number from Rectange Area (i.e. ie. page 1 of N)
.......

newPage = documentToSave.Pages.Add(page.Size, new Spire.Pdf.Graphics.PdfMargins(0));
page.CreateTemplate().Draw(newPage, new PointF(0, 0));

//If not the same invoice.... save it
......
documentToSave.SaveToFile($"{InvoiceNumber}.pdf");

}

I have attached the resulting PDF's, but don't want to publically post the original multi-page PDF.

shoppas
 
Posts: 3
Joined: Mon Aug 13, 2018 5:08 pm

Wed Aug 15, 2018 2:31 am

Hello Shoppas,

To help us locate your issue quickly, please send your original Pdf, resultant Pdf as well as your full code(including "......" part) to us via email(support@e-iceblue.com). Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Aug 15, 2018 5:20 pm

I emailed the file(s). Let me know if you receive them. I built you a project that is functional and reproduces the error noted.

shoppas
 
Posts: 3
Joined: Mon Aug 13, 2018 5:08 pm

Thu Aug 16, 2018 1:34 am

Dear Shoppas,

Sorry we didn’t receive your email, could you zip it and upload again? Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF