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.

Tue Sep 26, 2017 7:49 am

Hi,

I am trying to save the PDF file as Tiff file. I am using the code from
e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Conversion/Save-PDF-Document-as-tiff-image.html
in my C# console application.

Code: Select all
using System;
using System.Drawing;
using System.Drawing.Imaging;
using Spire.Pdf;
namespace SavePdfAsTiff
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"01.pdf");
    JoinTiffImages(SaveAsImage(document),"result.tiff",EncoderValue.CompressionLZW);
            System.Diagnostics.Process.Start("result.tiff");
        }
        private static Image[] SaveAsImage(PdfDocument document)
        {
            Image[] images = new Image[document.Pages.Count];
            for (int i = 0; i < document.Pages.Count; i++)
            {
                images[i] = document.SaveAsImage(i);
            }
            return images;
        }

        private static ImageCodecInfo GetEncoderInfo(string mimeType)
        {
            ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
            for (int j = 0; j < encoders.Length; j++)
            {
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            }
            throw new Exception(mimeType + " mime type not found in ImageCodecInfo");
        }

        public static void JoinTiffImages(Image[] images, string outFile, EncoderValue compressEncoder)
        {
            //use the save encoder
            Encoder enc = Encoder.SaveFlag;
            EncoderParameters ep = new EncoderParameters(2);
            ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
            ep.Param[1] = new EncoderParameter(Encoder.Compression, (long)compressEncoder);
            Image pages = images[0];
            int frame = 0;
            ImageCodecInfo info = GetEncoderInfo("image/tiff");
            foreach (Image img in images)
            {
                if (frame == 0)
                {
                    pages = img;
                    //save the first frame
                    pages.Save(outFile, info, ep);
                }

                else
                {
                    //save the intermediate frames
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);

                    pages.SaveAdd(img, ep);
                }
                if (frame == images.Length - 1)
                {
                    //flush and close.
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
                    pages.SaveAdd(ep);
                }
                frame++;
            }
        }
    }
}


I am getting error saying "Parameter is not valid".

Let me know how to fix this issue.

Thanks
Sri
User avatar

css
 
Posts: 3
Joined: Mon Sep 25, 2017 7:48 am

Tue Sep 26, 2017 8:30 am

Hi,

Thanks for your inquiry.
I suggest you first trying our latest hotfix Spire.PDF Pack(Hot Fix) Version:3.9.360 which is more robust. If the issue still troubles you, please share your sample pdf file so that we can have a better investigation.

Sincerley,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Sep 26, 2017 10:27 am

Hi Team,

I'm running into a similar issue when trying to save pdf to bpm. I've already updated to the newest 3.9.360 patch, but issue is still there.

My custom processDownloadedFile() method contains:

Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(str1pageFileName)
System.Drawing.Image bmp = doc.SaveAsImage(0, Spire.Pdf.Graphics.PdfImageType.Bitmap, 7, 7);


The SaveAsImage() line throws an error:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Spire.Pdf.General.Render.Font.Type1Font.GetOutline(String name, Single width)
at Spire.Pdf.General.Render.Font.Type1Font.GetOutline(Char src, Single width)
at Spire.Pdf.General.Render.Font.OutlineFont.GetGlyph(Char src, String name, TypeEncodingCmap type)
at Spire.Pdf.General.Render.Font.PDFFontViewer.GetCachedGlyph(Char src, String name, TypeEncodingCmap type)
at Spire.Pdf.General.Render.Font.PDFFontEncoding.ᜁ(PDFFontViewer A_0, Char A_1)
at Spire.Pdf.General.Render.Font.PDFFontEncoding.GetGlyphs(PDFFontViewer font, String text)
at Spire.Pdf.General.Render.Font.PDFFontViewer.GetGlyphs(String text)
at sprᶑ.ᜀ(sprᱯ A_0, spr⁚ A_1, Graphics A_2, PointF A_3)
at spr⁚.ᜁ(Graphics A_0, sprᱯ A_1, Boolean A_2)
at sprᱯ.ᜀ(String A_0, sprᶑ A_1, String A_2, Boolean A_3)
at sprᱯ.ᜀ(String[] A_0, String A_1)
at sprᱯ.ᜀ(sprṱ A_0)
at sprᱯ.ᜅ(Boolean A_0)
at sprᱯ.ᜤ()
at Spire.Pdf.PdfDocumentBase.ᜀ(Int32 A_0, Int32 A_1, Int32 A_2)
at Spire.Pdf.PdfDocumentBase.ᜀ(Int32 A_0, PdfImageType A_1, Int32 A_2, Int32 A_3)
at Spire.Pdf.PdfDocument.SaveAsImage(Int32 pageIndex, PdfImageType type, Int32 dpiX, Int32 dpiY)
at barcode2srvc.InboxDirWatcher.processDownloadedFile(String filePath)



//Łukasz

akquinet
 
Posts: 1
Joined: Mon Aug 21, 2017 8:45 am

Wed Sep 27, 2017 1:16 am

Hello Łukasz,

Thanks for your post.
To help us with a better investigation, please send your sample pdf file to us via email(support@e-iceblue.com).

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Sep 27, 2017 7:58 am

Hi Sri,

Have you tried the latest version? Did the issue get resolved by the hotfix?
Your feedback will be greatly appreciated.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Oct 02, 2017 9:25 am

Hi Łukasz,

I have received your pdf file, and reproduced the issue you reported on my side. The issue has been logged into our bug system. Sorry for the inconvenience caused. Once it is fixed, we will let your know.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed Oct 04, 2017 6:45 am

Sorry for the delay. I tried using the Hot fix version you have provided.

I am getting the below error in my existing project:

Code: Select all
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in ConsoleApplication1.exe

Additional information: Could not load file or assembly 'Spire.Pdf, Version=3.9.361.9040, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. The system cannot find the file specified.


I tried using the new project and it worked fine.
Sri
User avatar

css
 
Posts: 3
Joined: Mon Sep 25, 2017 7:48 am

Wed Oct 04, 2017 7:26 am

Hello Sri,

Thanks for your response.
Please make sure that you have replaced all the dlls in the folder, which includes the following four, and then rebuild your project.
Spire.Pdf.dll 3.9.360.2040
Spire.License.dll 1.3.6.40
Spire.License.xml
Spire.Pdf.xml

One more thing, kindly note that our single product is used respectively, if you want to use two products or more together, you need to choose Spire.Office. If the issue still troubles you, just come back to us for more help and share your sample pdf file.

Thanks,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Nov 02, 2017 10:15 am

Hi Łukasz,

Thanks for waiting.
Glad to inform that your issue has been resolved in Spire.PDF Pack(Hot Fix) Version:3.9.431.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF