PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 26, 2024 6:36 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jul 27, 2016 11:07 am 
Offline

Joined: Wed Jan 13, 2016 9:33 am
Posts: 15
How to insert a picture in the PDF file only once and show it on all pages

I saved a invoice of 10 pages without logo.
After that i add to the invoice a jpg of 10Kb as logo.

The result file size grows of 100Kb.

But when I print my document (without use PDFSharp)
on a pdf printer virtual driver such as BullZip, PrimoPDF, PdfFactory,
the file size growns only by 10Kb regardless of the number of pages.

Thanks


Last edited by riccardo on Wed Jul 27, 2016 12:50 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 27, 2016 11:16 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

You do not show any code and no PDF file.
viewtopic.php?f=2&t=832

When using PDFsharp as intended, the image will be included only once, even if it is referenced on many pages.

If you create a single XImage and use that on all pages then there will be no problems.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 27, 2016 12:42 pm 
Offline

Joined: Wed Jan 13, 2016 9:33 am
Posts: 15
Thomas Hoevel wrote:
If you create a single XImage and use that on all pages then there will be no problems.


This is probably my problem: I create view objects for each page

I will try to reuse XImage objects

Thank you very much again


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 27, 2016 12:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
There shouldn't be duplicates either when the same filename is used for all XImage objects.

BTW: do you get an increase of 50 kB for a document with 5 invoices?
If not then maybe there is a different issue.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 27, 2016 2:44 pm 
Offline

Joined: Wed Jan 13, 2016 9:33 am
Posts: 15
Thomas Hoevel wrote:
There shouldn't be duplicates either when the same filename is used for all XImage objects.


Unfortunately I create the image from a BITMAPINFO* (C++/CLI)

//PDFSharp does not support 16bit
Bitmap^ AdjustBitDepth(Bitmap^ image)
{
Bitmap^ newImage = nullptr;
switch (image->PixelFormat)
{
case PixelFormat::Format16bppRgb555:
newImage = image->Clone(System::Drawing::Rectangle(0, 0, image->Width, image->Height), PixelFormat::Format32bppRgb);
break;
case PixelFormat::Format16bppRgb565:
newImage = image->Clone(System::Drawing::Rectangle(0, 0, image->Width, image->Height), PixelFormat::Format32bppRgb);
break;
case PixelFormat::Format16bppArgb1555:
newImage = image->Clone(System::Drawing::Rectangle(0, 0, image->Width, image->Height), PixelFormat::Format32bppArgb);
break;
}

if (newImage == nullptr)
return image;

delete image;
return newImage;
}

////////////////////////////////////////////////////////////////////////////

XImage^ FromMetaRecord(BITMAPINFO* pInfo, BYTE* bitmapBytes)
{
Gdiplus::GpBitmap *bitmap = NULL;

Gdiplus::DllExports::GdipCreateBitmapFromGdiDib(pInfo, bitmapBytes, &bitmap);

System::Reflection::MethodInfo^ mi = Bitmap::typeid->GetMethod("FromGDIplus", System::Reflection::BindingFlags::Static | System::Reflection::BindingFlags::NonPublic);

Bitmap ^image = (Bitmap^)mi->Invoke(nullptr, gcnew cli::array<Object^> { IntPtr(bitmap) });

image = AdjustBitDepth(image);

XImage^ xImage = XImage::FromGdiPlusImage(image);

return xImage;
}

I am studying a methods to compare BITMAP objects to reuse the same XImage

Thomas Hoevel wrote:
BTW: do you get an increase of 50 kB for a document with 5 invoices?

Yes, its size grows proportional with page number and image size


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 312 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group