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 May 04, 2021 11:32 pm

Does Spire.PDF support .tiff files and, if so, does it also support .tiff files that contain a transparent background?

My goal is to be able to load into the application a .tiff with a transparent background. We can't use PNGs because we need it to be CMYK for our printer.

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Wed May 05, 2021 2:30 am

Hello,

Thanks for your inquiry.
Do you want to insert the TIFF which has transparent background into PDF file? If so, could you please provide your TIFF sample to help us do a better investigation? If there is any misunderstanding, please provide more information to clarify your requirement.

Sincerely,
Nina
E-iceblue support team
User avatar

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

Wed May 05, 2021 7:35 pm

Sure: attached is a sample file.

The goal is to have a CMYK transparent TIF generated and layered over top a non-transparent image.

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Thu May 06, 2021 9:17 am

Hi,

Thanks for your feedback.
The tiff file you attached is damaged in this post. What you want is to convert a PDF file to TIff file with CMYK transparent background, right? If so, please try the following code. If there is any misunderstanding, please feel free to write back.
Code: Select all
static void Main(string[] args)
{
    PdfDocument document = new PdfDocument();
    document.LoadFromFile(@"test.pdf");
    JoinTiffImages(SaveAsImage(document), "result.tiff", EncoderValue.CompressionLZW);
    System.Diagnostics.Process.Start("result.tiff");
}
private static Bitmap[] SaveAsImage(PdfDocument document)
{
    Bitmap[] bitmaps = new Bitmap[document.Pages.Count];
    for (int i = 0; i < document.Pages.Count; i++)
    {
        bitmaps[i] = new Bitmap(document.SaveAsImage(i));
        //make the background transparent
        bitmaps[i].MakeTransparent(Color.White);
    }
    return bitmaps;
}

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(Bitmap[] images, string outFile, EncoderValue compressEncoder)
{
    //use the save encoder
    System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag;
    EncoderParameters ep = new EncoderParameters(2);
    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
    ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.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++;
    }
}

Sincerely,
Nina
E-iceblue support team
User avatar

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

Wed May 12, 2021 1:29 pm

Nina.Tang wrote:Hi,

Thanks for your feedback.
The tiff file you attached is damaged in this post. What you want is to convert a PDF file to TIff file with CMYK transparent background, right?


No, what we're trying to do is generate a PDF that contains a TIFF file that had been exported from Adobe InDesign as a transparent TIFF file.

The example .TIFF file I supplied to you won't render on your web forum because modern browsers no longer support rendering .TIFFs. If you are using the Chrome browser, you will have to right-click on the broken image link, select "copy image address," and then paste that image URL in your browser to download the file. I've supplied another example.

The TIFF file contains black text, but no background color. Our goal is to import this transparent CMYK file and layer it over top another image. From there, we would generate a PDF containing the CMYK image and retaining the CMYK properties for our printer to use to produce a quality high-resolution print-out. They cannot use RGB files embedded in a PDF, only CMYK images.

We haven't been able to get that to work. It seems that it loads the file and we can render a PDF, but doesn't render it correctly.

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Thu May 13, 2021 7:04 am

Hello,

Thanks for your feedback.
I downloaded your tiff file and did a test, but found the background became black after inserting in PDF. Below is my testing code. You mentioned that "It seems that it loads the file and we can render a PDF, but doesn't render it correctly", did you encounter the same issue as mine? I have logged this issue into our bug tracking system with the ticket number SPIREPDF-4291. In addition, usually the image inserted in PDF document will be converted as RGB mode in our Spire.PDF. As for your requirement to keep CMYK mode, I have also posted it to our dev team to do further investigation, if there is any good news, I will inform you. Apologize for the inconvenience caused.
Code: Select all
PdfDocument pdfDocument = new PdfDocument();
PdfImage pdfImg = PdfImage.FromFile(@"transparent-tiff-test-051221.tiff");
PdfPageBase page = pdfDocument.Pages.Add();
float width = pdfImg.Width * 0.5f;
float height = pdfImg.Height * 0.5f;
float x = (page.Canvas.ClientSize.Width - width) / 2;
page.Canvas.DrawImage(pdfImg, x, 0, width, height);
pdfDocument.SaveToFile(@"result.pdf");

Sincerely,
Nina
E-iceblue support team
User avatar

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

Tue Jun 29, 2021 9:01 am

Hi,

Thanks for your patience.
I'm writing to inform you that we just released Spire.PDF Pack Version: 7.6.15 which contains the fix of your issue. Please download the hotfix from the following links.
Website link: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/7.6.15

Sincerely,
Nina
E-iceblue support team
User avatar

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

Mon Aug 23, 2021 4:28 pm

Thanks so much for investigating and releasing the patch. I tried to load the example TIFF file and, although it's an improvement from the previous version, it unfortunately renders a solid white background when it should be transparent. The source TIFF image is a CMYK TIFF exported from PhotoShop with transparencies.

Example:

Code: Select all

SizeF pageSize = new SizeF();
pageSize.Width = (360);
pageSize.Height = (432);

PdfPageBase page = pdfdoc.Pages.Add(pageSize, new PdfMargins(0));

PdfImage myTiff = PdfImage.FromFile("transparent-tiff-test-051221.tiff");

page.Canvas.DrawImage(myTiff, 9, 322, 125, 74);



What I see is the text from the tiff image and a solid white background. I can confirm it's solid by preceding it with another image underneath.

Thanks again for any assistance.

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Tue Aug 24, 2021 8:54 am

Hello,

Thank you for your feedback.
I tested your case and found the behavior you mentioned. I have logged the issue into our Bug tracking system with the ticket number SPIREPDF-4578. Our development team will investigate and fix it. Once it is resolved, I will inform you. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Tue Nov 16, 2021 5:36 pm

Hello:

Where can I find the current status of ticket # SPIREPDF-4578?

Has there been any movement on this ticket?

Thanks.

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Wed Nov 17, 2021 1:48 am

Hello,

Thank you for your follow-up.
We have not yet published the status of the issue. Now the issue of ticket SPIREPDF-4578 has not been completely resolved due to its complexity. Our developers are working hard to solve it, and I also urge them to speed up the progress. Once it is solved, I will inform you in time. We apologize for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Wed Dec 15, 2021 9:22 am

Hello,

Thank you for your patience.
Glad to inform that we just released Spire.Office Platinum(Hotfix) Version:6.12.1 which fixed the issue SPIREPDF-4578, please download it from the following links to test.
Website link: https://www.e-iceblue.com/Download/download-office-for-net-now.html
Nuget link:
https://www.nuget.org/packages/Spire.Office/6.12.1
https://www.nuget.org/packages/Spire.Office.NETCore/6.12.1

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 21, 2021 9:01 am

Hello,

Hope you are doing well!
Have you tried the new version of Spire.Office? Is the issue resolved now? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1650
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF