PDFNet.Initialize(yourLicenseOrDemoKey);
// At the beginning of your process
PDFNet.SetDefaultDiskCachingEnabled(false); // disables writing temporary streams to disk
string imageExt = "png";
byte[] imageData = System.IO.File.ReadAllBytes(input_path + "butterfly.png"); // for demo purpose read from disk
using (pdftron.Filters.MemoryFilter memoryFilter = new pdftron.Filters.MemoryFilter((int)imageData.Length, false)) // false = sink
{
pdftron.Filters.FilterWriter writer = new pdftron.Filters.FilterWriter(memoryFilter); // helper filter to allow us to write to buffer
writer.WriteBuffer(imageData);
writer.Flush();
memoryFilter.SetAsInputFilter(); // switch from sink to source
using (var newDoc = new PDFDoc())
{
var options = new ConversionOptions();
options.SetFileExtension(imageExt);
DocumentConversion documentConversion = pdftron.PDF.Convert.StreamingPDFConversion(newDoc, memoryFilter, options);
documentConversion.Convert();
byte[] pdfData = newDoc.Save(SDFDoc.SaveOptions.e_linearized);
// System.IO.File.WriteAllBytes(outPath, pdfData); // if you want to test/verify the output
}
}
I used this code myself for multi page tiffs and found that it only copied over the first page of the tiffâŚ
I then tried to adapt the code with documentConversion.ConvertNextPage(); and documentConversion.GetConversionStatus(), but documentConversion.GetConversionStatus() fires complete after a single page, which does not workâŚ
Do you have any advice for getting multi page tiffs to work?
I actually got this to work for multi-page tiff with a different approach. I wrote the file temporarily to file then used: pdftron.PDF.Convert.ToPdf(newDoc, tempFileName); to write to the pdfDoc to then get a memory stream.
Going forward it might be nice to not have to write a file to disk to use pdftron.PDF.Convert.ToPdf⌠And use a memory stream/byte[] instead.
Hello. Iâve tried this code on a sample jpg (attached) and the resulting PDF is not what I expected. Upon inspecting the PDF, the page size defaulted to the dimensions of a letter size bond paper (8.5 x 11in) and resulted into having top and bottom white margins:
Iâm exploring the stream conversion approach because I am not allowed to use the serverâs disk therefore cannot use other methods like Convert.ToPdf(...) that only accepts file paths.
If you do not like the output of our APIs (other than ToPDF) then you can follow the AddImageTest sample where you will have full control over page size and image size.
Though you might need an image processing library to extract any EXIF data that is important to you, especially Orientation (as you might need to rotate the image) and DPI if you care about that.