Sautfinsoft PDF Focus .Net Converter text issue - c#

So I've been trying to use SautinSoft software to convert a pdf document to a docx document. However, whenever I run this code my word document ends up having squished text. I've attached the images below, any idea what is going on?
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus()
f.OpenPdf(#source);
if (f.PageCount > 0){
string path = Path.ChangeExtension(source, ".docx");
f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
f.ToWord(#path);
}
This is a docx file after conversion. The image rendered fine, but the text is all squished for some reason. I'm also running on macOS (if that makes a difference). Thank you for anyone that can help!

I found the answer. You have to make sure to set
f.WordOptions.KeepCharScaleAndSpacing = false;
Because by default, the converter will scale the font widths based on the PDF fonts rather than your default word doc fonts.

Just load your fonts which you are using in the PDF in "C:/Windows/Fonts" and reboot your PC.
Then to convert your PDF to WORD again.
If it doesn't work for you. Try to use an another way. Specify the path to your folder's font for PDF Focus like :
f.WordOptions.Fonts = D:/Fonts;

Related

PDFSharp blank pages

Tried to open a pdf result in blank pages. Retry with same pdf displayed all pages with content.
It happen only once & couldn't reproduce it.
My application work with 3 steps.
Open PDF
Add Barcode Image
Save PDF
Source pdf had 2 pages with text content, output pdf had only stamped pdf without content.
I believe something went wrong in following line because number of pages are correct but blank.
PdfDocument document = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify);
I need find reason of failure but don't have any idea what went wrong at first time. I have already gone through following questions but they have different case.
https://stackoverflow.com/a/52453789/9102192
PDFSharp returning blank pages when adding password
Can anyone help me finding root cause for this incident or any guesses ?
I would try to do something like this:
using (PdfDocument pdfDoc = PdfReader.Open("source", PdfDocumentOpenMode.Modify)){
// Logic to insert image into pdf //
pdfDoc.Save("targetPath")
}

Preventing a C# System.Windows.Forms.Clipboard object from opening on double-clicking

I use PdfSharp to create a PdfDocument object:
private readonly PdfDocument _pdf = new PdfDocument();
Along with the other methods for actually adding the text, setting font styles etc. I then write the pdf file to a temporary location on disk:
var tempPdf = string.Concat(Path.GetTempPath(), Guid.NewGuid().ToString(), ".pdf");
_pdf.Save(tempPdf);
Which I then use in System.Windows.Clipboard class to copy the content to the clipboard:
Clipboard.SetFileDropList(new StringCollection {tempPdf});
When the user pastes the Clipboard content into a Word document for example, the pdf content appears in the document as desired.
The problem I have is that when the user double-clicks on the embedded PDF it launches the PDF in a viewer such as Adobe Reader, also as expected. The (unanticipated) problem I have is that I need to prevent this pop-up from happening given that this content will be inserted into a legal document.
Can any suggest any approaches or strategies for helping me to achieve something like this? To summarise - allowing them to paste [pdf] content stored in the clipboard to a Word document, but without it opening on double-clicking.
The answer was in my question ;)
And credit to Nyerguds for helping me out of my cocoon - I was fixated on using PDF files to copy to the clipboard.
The solution is to replace the usages of PdfSharp for pdf generation with System.Drawing.Graphics / System.Drawing.Bitmap to create jpg images of that which we want to copy.
And once the clipboard contents have been pasted to the Word document, we no longer have that problem of the image being openable on double-clicking.

PDF Clown does not render text

I use PDF Clown to create PDF files containing text and different shapes. Saving the files brings the desired result. But when I print the pages or render them to bitmaps, only the shapes are visible and the text elements are missing.
I tried already different versions of the library with multiple files, always getting the same result.
Maybe someone can give me a hint on this issue.
EDIT:
This is a simplified form of the source code I use (with same result as described above; see the image at the end):
File file = new File();
Document document = file.Document;
document.PageSize = PageFormat.GetSize(PageFormat.SizeEnum.A4, PageFormat.OrientationEnum.Portrait);
Page page = new Page(document);
document.Pages.Add(page);
PrimitiveComposer composer = new PrimitiveComposer(page);
//draw a rectangle
composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.LightSalmon));
composer.DrawRectangle(new RectangleF(30, 42, 300, 32));
composer.Fill();
//draw some text
composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Black));
composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 32);
composer.ShowText("Hello World!", new PointF(32, 48));
composer.Flush();
//save the file
file.Save(#"..\document.pdf", SerializationModeEnum.Standard);
//and print it
Renderer renderer = new Renderer();
renderer.Print(file.Document, false);
Result of the above code (the printed version was created with virtual printer Adobe PDF; also tested with XPS Document Writer):
(I don't have enough points to add a comment so I put this comment as an answer.) If you look in the source for the RenderingSample class, you will see this comment:
This sample demonstrates how to render a PDF page as a raster image.
Note: rendering is currently in pre-alpha stage; therefore this sample is
nothing but an initial stub (no assumption to work!).
I don't think Stephano Chizzolini got around to finishing it.
There is another NuGet download, PDFClown.Net version 2.0.0, by Matthieu. It has tags for PDF-To-Image, Rasterizer and PDF, but I have not been able to get it to work either. I cannot find documentation for it. Inspection of the properties for the downloaded NuGET assembly shows version 0.1.2.0 instead of 2.0.0.

c#/WPF print formatting

I am very new to c#/WPF and I need help with what should be a very simple app. In the app I am designing a user simply browses for a .txt or .jpg file which is then loaded. I would like the user to then be able to print what's displayed. The code I have found to work appears to only print part of the contents on one page. In addition, when the .txt files are printed there are no margins and the text seems to go right off the page. Here is the code I am using as it seems to be very basic.
System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
if (pd.ShowDialog() != true) return;
pd.PrintVisual(textbox2, "textbox2.");
I guess my question would be, how do I set margin spacing and allow for multiple page document printing? Any help would be greatly appreciated. Thank you.
To print text files you will probably want to use a FlowDocument, this allows you to set margins, pagination etc, e.g.
Printing a WPF FlowDocument
To print a JPEG, you can use PrintVisual, e.g.
Load image from file and print it using WPF... how?

How to display a PdfPage as image in WPF form using Docotic.pdf.dll

I need to display PdfPage of a PDF Document in a WPF form. I am using Docotic.pdf.dll and want to stick to it. The PdfPage.Thumbnail is also giving me null with all PDFs.
Just confirmed from Bit Miracle, this feature has been added in Docotic.Pdf 3.4 (available on their site) and currently it is in beta phase .
Below is the code that will save the image from the Pdf.
using (PdfDocument pdf = new PdfDocument("your_file.pdf"))
{
PdfDrawOptions options = PdfDrawOptions.CreateZoom(150);
options.BackgroundColor = new PdfRgbColor(255, 255, 255); // white background, transparent by default
options.Format = PdfDrawFormat.Jpeg;
pdf.Pages[0].Save("result.jpg", options);
}
There is also Draw and print PDF group of samples that might worth to look into.
As far as I know Docotic.Pdf cannot display PDF files (at least the current version), it can only create them. The PdfPage.Thumbnail refers to the page thumbnail embedded in the PDF file, which usually is missing, this is why the property returns null.

Categories

Resources